google-colab-cli 0.8.0__tar.gz → 0.8.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/AGENTS.md +5 -3
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/PKG-INFO +7 -2
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/README.md +6 -1
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/docs/01_session_management.md +22 -2
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/docs/02_execution_and_interactive.md +13 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/docs/03_file_management.md +1 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/docs/04_automation_and_utility.md +104 -48
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/docs/05_run_command.md +4 -2
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/docs/06_ssh_access.md +23 -7
- google_colab_cli-0.8.1/docs/07_update_notices.md +169 -0
- google_colab_cli-0.8.1/docs/public_api_migration_plan.md +145 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/examples/finetune_run.py +6 -5
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/integration/README.md +2 -1
- google_colab_cli-0.8.1/integration/repro_update_notices/test.sh +120 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/integration/repro_windows_ssh/test.py +16 -3
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/pyproject.toml +1 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/skills/colab-operator/SKILL.md +9 -11
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/src/colab_cli/auth.py +143 -28
- google_colab_cli-0.8.1/src/colab_cli/auto_update.py +393 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/src/colab_cli/cli.py +21 -1
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/src/colab_cli/client.py +174 -12
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/src/colab_cli/commands/automation.py +94 -16
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/src/colab_cli/commands/execution.py +76 -4
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/src/colab_cli/commands/run.py +28 -109
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/src/colab_cli/commands/session.py +119 -53
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/src/colab_cli/commands/ssh.py +77 -8
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/src/colab_cli/commands/utility.py +82 -8
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/src/colab_cli/common.py +12 -1
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/src/colab_cli/contents.py +8 -1
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/src/colab_cli/repl.py +0 -1
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/src/colab_cli/state.py +16 -2
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/conftest.py +16 -9
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_auth.py +385 -27
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_auth_adc.py +15 -6
- google_colab_cli-0.8.1/tests/test_automation.py +317 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_cli.py +363 -3
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_client.py +148 -7
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_common.py +23 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_contents.py +38 -1
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_exec.py +140 -2
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_ipynb_exec.py +46 -0
- google_colab_cli-0.8.1/tests/test_notices_tool.py +352 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_run.py +102 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_runtime_options.py +7 -4
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_ssh.py +53 -4
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_ssh_autocreate.py +4 -12
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_ssh_lifecycle.py +7 -21
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_ssh_wire_contract.py +7 -11
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_state.py +31 -2
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_update.py +609 -2
- google_colab_cli-0.8.1/tests/test_windows_ssh.py +314 -0
- google_colab_cli-0.8.1/tools/NOTICE.md +7 -0
- google_colab_cli-0.8.1/tools/notices.py +418 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/uv.lock +46 -46
- google_colab_cli-0.8.0/src/colab_cli/auto_update.py +0 -248
- google_colab_cli-0.8.0/tests/test_automation.py +0 -150
- google_colab_cli-0.8.0/tests/test_windows_ssh.py +0 -165
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/.githooks/pre-commit +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/.gitignore +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/.pre-commit-config.yaml +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/.python-version +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/CHANGELOG.md +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/CONTRIBUTING.md +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/LICENSE +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/cloudbuild.yaml +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/docs/3042ab12-2026-05-07.png +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/docs/demo.webm +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/docs/demos.md +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/integration/repro_bundled_oauth/test.sh +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/integration/repro_legacy_token_migration/test.sh +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/integration/repro_plot_redirection/test.sh +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/integration/repro_run_command/test.sh +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/integration/repro_ssh/test.sh +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/integration/repro_variable_persistence/test.sh +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/src/colab_cli/commands/__init__.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/src/colab_cli/commands/files.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/src/colab_cli/commands/usage.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/src/colab_cli/consumption.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/src/colab_cli/converter.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/src/colab_cli/history.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/src/colab_cli/oauth_config.json +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/src/colab_cli/runtime.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/src/colab_cli/utils.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/mock_kernel.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_cli_log.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_consumption.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_consumption_client.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_history.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_local_credentials.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_log_export.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_pay.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_readme.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_repl.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_resolution_logic.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_runtime.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_ssh_cmd.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_ssh_workdir.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_streaming.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_url.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_utils.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_version.py +0 -0
- {google_colab_cli-0.8.0 → google_colab_cli-0.8.1}/tests/test_whoami.py +0 -0
|
@@ -6,9 +6,9 @@
|
|
|
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
8
|
- `oauth2`: public `google-auth-oauthlib` `InstalledAppFlow`, token cached in the OS keyring via the Python `keyring` library (`service_name="google-colab-cli"`, `username="oauth_token"`), falling back to `_run_remote_flow` if the keyring is not accessible or locked (keyring failures are echoed to stderr; logs alone go to a file; on Linux, `_check_linux_keyring_locked` checks `secretstorage` beforehand and warns immediately when the `SecretService` collection is locked). A pre-keyring `~/.config/colab-cli/token.json` (`LEGACY_TOKEN_PATH`) is migrated into the keyring and deleted only after a successful keyring write, or immediately when the keyring already holds a token. Integration scripts assume no legacy file exists and detect OAuth2 availability via a keyring-only `has_oauth2_token` helper; the migration path is covered by `integration/repro_legacy_token_migration/test.sh` (isolated HOME + file-backed test keyring). Tests that must ignore the host keyring set `PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring`. 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`
|
|
10
|
-
- **Backend Hosts**:
|
|
11
|
-
- `colab.research.google.com` (session backend / `tun/m/...`):
|
|
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`. Both `colaboratory` and `userinfo.email` are required by the session backend at `colab.research.google.com` (assign/unassign/sessions return 401 without them); `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
|
+
- **Backend Hosts**:
|
|
11
|
+
- `colab.research.google.com` (session backend / `tun/m/...`): requires the `colaboratory` and `userinfo.email` scopes. Handles assign, unassign, CCU info, and the contents API.
|
|
12
12
|
- **Runtime**: `ColabRuntime` wraps `jupyter-kernel-client` for execution.
|
|
13
13
|
- **State**:
|
|
14
14
|
- `StateStore` persists session metadata in `~/.config/colab-cli/sessions.json`.
|
|
@@ -77,6 +77,8 @@ The package version is derived from the git tag via `hatch-vcs` (see `pyproject.
|
|
|
77
77
|
18. **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.
|
|
78
78
|
19. **Clean up orphaned assignments before finishing live tests**: After running a live integration test, `colab sessions` may show server-side assignments that the local `colab stop` couldn't see (e.g. assignments leaked from earlier in the session, or from crashed prior runs). Always run `colab sessions` as the final cleanup step, and for any `[?]`-marked orphan, run `python -c "from colab_cli.common import state; state.client.unassign('<endpoint>')"` (the CLI doesn't expose a direct unassign-by-endpoint command). Re-verify with `colab sessions` returning "No active sessions". Encoded 2026-05-05 after the first `colab url` live test left an orphan from a prior conversation turn that would have idled-out and billed compute units.
|
|
79
79
|
20. **Forward unknown args through Typer with `context_settings`**: Typer/Click consumes any token starting with `-`/`--` as a flag of the parent command unless told otherwise. For a subcommand like `colab run script.py --some-script-flag` (where `--some-script-flag` belongs to the user's script, not to `colab`), declare it with `app.command(name="run", context_settings={"allow_extra_args": True, "ignore_unknown_options": True})` and accept the positional with `Annotated[Optional[List[str]], typer.Argument(...)] = None`. Also use `repr()` (not f-string interpolation) when embedding those forwarded strings into kernel-side Python source — `repr()` produces a safe round-trippable literal regardless of the user's shell-passed quotes, backslashes, or non-ASCII bytes. Encoded 2026-05-12 while implementing `colab run`.
|
|
80
|
+
21. **Break Work into Small PRs/Commits**: Decompose multi-step changes into small, self-contained PRs or commits so each step is easy to review and verify independently.
|
|
81
|
+
22. **Concise Code & No One-Line Comments**: Write concise, self-explanatory code and do NOT write single-line comments. Use docstrings or multi-line explanations only when genuinely necessary to explain non-obvious invariants.
|
|
80
82
|
|
|
81
83
|
## Agent Execution Limitations (What I Can vs Cannot Run)
|
|
82
84
|
As an AI agent operating via non-interactive shell tools (`run_shell_command`), there are strict limits on what I can test autonomously without human intervention:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: google-colab-cli
|
|
3
|
-
Version: 0.8.
|
|
3
|
+
Version: 0.8.1
|
|
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
|
|
@@ -133,6 +133,7 @@ Run `colab <command> --help` to view specific options, defaults, and detailed he
|
|
|
133
133
|
| Command | Description |
|
|
134
134
|
| --- | --- |
|
|
135
135
|
| `colab auth [-s NAME]` | Authenticate the VM for GCP services (BigQuery, GCS, etc.) |
|
|
136
|
+
| `colab logout` | Clear local OAuth2 and cached runtime tokens to sign out or switch accounts |
|
|
136
137
|
| `colab drivemount [-s NAME] [PATH]` | Mount Google Drive on the VM (default: `/content/drive`) |
|
|
137
138
|
| `colab install [-s NAME] [-r FILE \| PKG...]` | Install packages on the VM using `uv` (falls back to `pip`) |
|
|
138
139
|
| `colab log [-s NAME] [-n N] [-o FILE]` | View or export session history (`.ipynb`, `.md`, `.txt`, `.jsonl`) |
|
|
@@ -142,7 +143,11 @@ Run `colab <command> --help` to view specific options, defaults, and detailed he
|
|
|
142
143
|
| `colab update [--install]` | Check for a newer release (and optionally upgrade the CLI in place) |
|
|
143
144
|
|
|
144
145
|
### Global Options
|
|
145
|
-
* `--auth {oauth2,adc}` — Authentication strategy for the Colab API (default: `adc`)
|
|
146
|
+
* `--auth {oauth2,adc}` — Authentication strategy for the Colab API (default: `oauth2`). To authenticate with Application Default Credentials (`--auth adc`), run:
|
|
147
|
+
```bash
|
|
148
|
+
gcloud auth application-default login \
|
|
149
|
+
--scopes=openid,https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/colaboratory
|
|
150
|
+
```
|
|
146
151
|
* `-c, --client-oauth-config PATH` — Path to public OAuth client credentials configuration (default: `~/.colab-cli-oauth-config.json`).
|
|
147
152
|
* `--config PATH` — Path to local session metadata storage (default: `~/.config/colab-cli/sessions.json`).
|
|
148
153
|
* `--logtostderr` — Direct debug logging output to stderr.
|
|
@@ -96,6 +96,7 @@ Run `colab <command> --help` to view specific options, defaults, and detailed he
|
|
|
96
96
|
| Command | Description |
|
|
97
97
|
| --- | --- |
|
|
98
98
|
| `colab auth [-s NAME]` | Authenticate the VM for GCP services (BigQuery, GCS, etc.) |
|
|
99
|
+
| `colab logout` | Clear local OAuth2 and cached runtime tokens to sign out or switch accounts |
|
|
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`) |
|
|
@@ -105,7 +106,11 @@ Run `colab <command> --help` to view specific options, defaults, and detailed he
|
|
|
105
106
|
| `colab update [--install]` | Check for a newer release (and optionally upgrade the CLI in place) |
|
|
106
107
|
|
|
107
108
|
### Global Options
|
|
108
|
-
* `--auth {oauth2,adc}` — Authentication strategy for the Colab API (default: `adc`)
|
|
109
|
+
* `--auth {oauth2,adc}` — Authentication strategy for the Colab API (default: `oauth2`). To authenticate with Application Default Credentials (`--auth adc`), run:
|
|
110
|
+
```bash
|
|
111
|
+
gcloud auth application-default login \
|
|
112
|
+
--scopes=openid,https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/colaboratory
|
|
113
|
+
```
|
|
109
114
|
* `-c, --client-oauth-config PATH` — Path to public OAuth client credentials configuration (default: `~/.colab-cli-oauth-config.json`).
|
|
110
115
|
* `--config PATH` — Path to local session metadata storage (default: `~/.config/colab-cli/sessions.json`).
|
|
111
116
|
* `--logtostderr` — Direct debug logging output to stderr.
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
---
|
|
2
2
|
log:
|
|
3
|
+
2026-12-04: Changed global `--public-api/--no-public-api` CLI option in `cli.py` to `Optional[bool] = None` so `settings.json`'s `use_public_api` takes effect whenever the flag and `COLAB_CLI_PUBLIC_API` are omitted (instead of being overridden to `False`).
|
|
4
|
+
2026-12-04: `colab stop` now rejects combining `-s/--session` with `--all` (printing an error to stderr and exiting with status 2 before syncing or unassigning sessions).
|
|
5
|
+
2026-12-02: `colab stop -s <target>` now falls back to `list_assignments()` and matches by server endpoint when `<target>` is not found in local state, allowing orphaned (`[?]`) assignments to be stopped directly (discussion #309).
|
|
6
|
+
2026-12-01: Extracted `assign_runtime` in `session.py` (shared by `colab new` and `colab run`) to translate exhausted `HTTP 502/503/504` and `ReadTimeout` allocation failures into actionable CLI messages (including the browser Colab Terms of Service acceptance hint for first-time/newly entitled accounts, `colab sessions`, and `COLAB_CLI_REQUEST_TIMEOUT`) with exit code 1 instead of raw tracebacks (#273).
|
|
7
|
+
2026-11-23: `colab stop -s <name>` now exits 1 when the named session does not exist (or has already vanished from the backend), delegating missing-session handling to `State.get_session` (#251).
|
|
8
|
+
2026-11-13: Documented `--auth {oauth2,adc}` (default `oauth2`) and required ADC `gcloud` scopes under Global Flags.
|
|
3
9
|
2026-11-04: `--gpu` and `--tpu` now reject unknown values instead of silently selecting `A100` (GPU) or `v6e1` (TPU). `resolve_runtime_options()` uses the new `GPU_ACCELERATORS` / `TPU_ACCELERATORS` maps and raises a `typer.BadParameter` that names the flag and the supported list; `--help` is generated from the same maps so it cannot drift. Validation runs before any assignment request, in both `colab new` and `colab run`.
|
|
4
10
|
2026-11-02: Added `_check_linux_keyring_locked` in `auth.py` to check if the active Linux `SecretService` keyring collection is locked via `secretstorage` before reading or writing OAuth tokens, logging and printing an immediate warning with the collection label, timeout, and `--auth=adc` hint while still attempting the keyring operation.
|
|
5
11
|
2026-10-29: Removed the `colab console` subcommand; the long-lived connections that skip mid-session token refresh are now `repl` and `ssh`.
|
|
6
12
|
2026-10-29: The debug log (`colab.log` and `--logtostderr`) masks access tokens, runtime proxy tokens, OAuth codes, client secrets, auth headers and cookies, including in percent-encoded URLs; `jupyter_kernel_client` logs at INFO so kernel stdin replies are not recorded.
|
|
7
13
|
2026-10-29: `sessions.json`, `settings.json`, `colab.log` and session history files are created with mode 0600, and existing copies are tightened to 0600 the next time the CLI uses them (history files whenever the history logger starts).
|
|
14
|
+
2026-10-22: Added global `--public-api/--no-public-api` toggle (`COLAB_CLI_PUBLIC_API`, `Settings.use_public_api`, default `False`), dual `Client.list_assignments()` dispatch (`/v1beta/runtimes` vs `/tun/m/assignments`), `Operation`/`Status` models, and cached auth capability hints on HTTP 401/403.
|
|
8
15
|
2026-10-21: Stored OAuth2 credentials in the OS native keyring via the `keyring` library instead of `~/.config/colab-cli/token.json`, falling back to `_run_remote_flow` if keyring is inaccessible. Keyring failures are reported on stderr, and an existing `token.json` is migrated into the keyring and then deleted (or deleted outright if the keyring already has a token).
|
|
9
16
|
2026-10-14: Added configurable HTTP request timeouts and bounded allocation retries. Uncertain allocation POSTs are reconciled by GET using the same notebook hash before resubmission.
|
|
10
17
|
2026-09-25: Runtime proxy tokens are now refreshed before expiry. `SessionState` persists `token_expires_at`, and `State.get_session` re-fetches the token via `GET /tun/m/assignments` when it's within 5 minutes of expiring.
|
|
@@ -80,7 +87,13 @@ the client waits `COLAB_CLI_RETRY_BACKOFF * 2**attempt` seconds (default 10, 20,
|
|
|
80
87
|
It then queries the same notebook hash: an existing allocation is returned directly;
|
|
81
88
|
otherwise the refreshed XSRF token is used for the next POST. HTTP 412 still raises
|
|
82
89
|
`TooManyAssignmentsError`; other errors are not retried. Failed initial/recovery
|
|
83
|
-
GETs and exhausted POST retries propagate to the caller.
|
|
90
|
+
GETs and exhausted POST retries propagate from `Client.assign()` to the caller.
|
|
91
|
+
At the CLI layer (`assign_runtime`, shared by `colab new` and `colab run`),
|
|
92
|
+
exhausted `502`/`503`/`504` responses and `ReadTimeout` errors are translated into
|
|
93
|
+
actionable stderr diagnostics (including accepting Colab Terms of Service at
|
|
94
|
+
`https://colab.research.google.com/`, checking `colab sessions`, and
|
|
95
|
+
`COLAB_CLI_REQUEST_TIMEOUT`) and exit code `1` instead of raw tracebacks. There
|
|
96
|
+
is no unlimited wait.
|
|
84
97
|
|
|
85
98
|
```bash
|
|
86
99
|
COLAB_CLI_REQUEST_TIMEOUT=300 COLAB_CLI_ASSIGN_RETRIES=3 COLAB_CLI_RETRY_BACKOFF=10 \
|
|
@@ -115,6 +128,8 @@ end to end; mocked timeouts alone do not establish backend compatibility.
|
|
|
115
128
|
- `authuser`: 0.
|
|
116
129
|
- `<endpoint>`: The unique session identifier returned during assignment (e.g., `tpu-v5e1-s-kkb-...`).
|
|
117
130
|
- **Cleanup**: Remove the session from the local state file upon successful 204 response.
|
|
131
|
+
- **Endpoint fallback**: If `-s <target>` does not match a local session name, `colab stop` queries `list_assignments()` and matches by server endpoint ID (as shown in `colab sessions`), unassigning the matching runtime and removing any local entry referencing that endpoint.
|
|
132
|
+
- **Missing sessions**: Stopping a specific session (`colab stop` or `colab stop -s <name>`) exits with code 1 if no matching local session or server endpoint exists. `colab stop --all` exits 0 when no sessions are active. Combining `-s/--session` with `--all` exits with code 2 (stderr) without modifying any sessions.
|
|
118
133
|
|
|
119
134
|
### 4. Session Listing (`colab sessions`)
|
|
120
135
|
- **API**: `GET https://colab.research.google.com/tun/m/assignments` (based on `colab-agent` implementation).
|
|
@@ -131,10 +146,12 @@ The runtime proxy token (`runtimeProxyInfo.token`) authenticates every request t
|
|
|
131
146
|
- **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`).
|
|
132
147
|
|
|
133
148
|
## Implementation Details
|
|
134
|
-
- **Authentication**: Uses `google-auth-oauthlib`
|
|
149
|
+
- **Authentication**: Uses `google-auth-oauthlib` (`InstalledAppFlow` remote copy-paste flow, default `--auth oauth2`) or Application Default Credentials (`--auth adc`).
|
|
135
150
|
- **Global Flags**:
|
|
151
|
+
- `--auth`: Authentication strategy (`oauth2` or `adc`, default: `oauth2`). User ADC credentials require `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`.
|
|
136
152
|
- `-c`, `--client-oauth-config`: Path to the client secrets JSON file (default: `~/.colab-cli-oauth-config.json`).
|
|
137
153
|
- `--config`: Path to the session state JSON file (default: `~/.config/colab-cli/sessions.json`).
|
|
154
|
+
- `--public-api/--no-public-api`: Select the Colab Public API (`colaboratory.googleapis.com`) vs. the legacy tunnel API (`COLAB_CLI_PUBLIC_API` env var; defaults to `None` so `~/.config/colab-cli/settings.json`'s `use_public_api` applies when unset, which itself defaults to `False`).
|
|
138
155
|
- **Token Storage**: Credentials are persisted to the OS native keyring via the `keyring` library (`service_name="google-colab-cli"`, `username="oauth_token"`) after the initial flow. If the keyring is inaccessible or locked, `_run_remote_flow` is invoked for the current run and a warning is printed to stderr. A legacy `~/.config/colab-cli/token.json` is migrated into the keyring on first use and deleted after a successful keyring write, or immediately if the keyring already holds a token.
|
|
139
156
|
- Use `requests` for robust HTTP interactions and `pydantic` for schema validation.
|
|
140
157
|
- Handle authentication headers (likely `Authorization: Bearer <token>` or cookies).
|
|
@@ -151,6 +168,9 @@ TDD is mandatory for all session management features.
|
|
|
151
168
|
### 1. Mock Assignment API
|
|
152
169
|
- **Test Case**: Verify `colab new` correctly parses a `PostAssignmentResponse` and stores it in the local `StateStore`.
|
|
153
170
|
- **Test Case**: Verify `colab stop` sends a `POST` request with the correct XSRF token to the unassign endpoint.
|
|
171
|
+
- **Test Case**: Verify `colab stop -s <endpoint>` unassigns an orphaned server-side assignment matched via `list_assignments()` (and removes any local record pointing to that endpoint).
|
|
172
|
+
- **Test Case**: Verify `colab stop -s <missing>` prints a not-found error and exits with status 1 without calling unassign.
|
|
173
|
+
- **Test Case**: Verify `colab stop -s <name> --all` prints an error to stderr and exits with status 2 without syncing or unassigning sessions.
|
|
154
174
|
- **Test Case**: Verify that the path provided via `-c` is correctly passed to the authentication flow.
|
|
155
175
|
- **Mocking**: Use `unittest.mock` to intercept `requests.Session.request` and return simulated XSSI-prefixed JSON payloads matching the HAR traces.
|
|
156
176
|
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
log:
|
|
3
|
+
2026-11-27: Fixed `colab exec` exiting 1 after `sys.exit()` / `sys.exit(None)` / `sys.exit(0)`. A leftover `any(output_type == "error")` check after `_exit_code_from_outputs` re-flagged the `SystemExit` error output as a failure, overriding the CPython mapping; `_exit_code_from_outputs` already returns 1 for every non-`SystemExit` error, so the check was removed. `test_cli_exec_systemexit_zero_exits_zero_silently` now passes.
|
|
4
|
+
|
|
5
|
+
2026-11-23: Shared `colab run`'s CPython `SystemExit` handling (`_exit_code_from_outputs`, `_make_script_output_hook`) with `colab exec` and muted IPython's `"To exit: use ..."` warning during `exec` setup. Because a persistent IPython kernel catches `SystemExit` and emits it as `output_type == "error"` to avoid killing the kernel process, treating every kernel error output as exit 1 wrongly failed scripts that call `sys.exit(0)` (e.g. `argparse --help`, `unittest.main()`) and collapsed `sys.exit(N)` codes into 1.
|
|
6
|
+
|
|
7
|
+
2026-11-23: `colab exec` now exits 1 when executed code produces a kernel `error` output (after recording history and saving `*_output.ipynb` for notebooks, stopping further notebook cells) (#250).
|
|
8
|
+
|
|
3
9
|
2026-05-07: Fixed `colab console` piped-stdin handling. Previously a piped invocation (e.g. `echo 'cmd' | colab console -s s`) sent the command and then hung indefinitely because the previous EOF handler emitted a bare `\x04` (Ctrl-D), which the remote `tmux`-wrapped bash treats as a literal character rather than a session terminator. The new handler sends `exit\n` (which bash actually exits on) and then closes the websocket from the client side after a short grace period (`PIPED_EOF_GRACE_SECONDS = 0.5s`) so any tail output (bash `logout`, tmux `[exited]`) makes it back to the user. TTY mode is unchanged: real-terminal EOF is left to the remote shell. Verified live: `echo 'echo HELLO' | colab console -s s` now exits in ~1.2s instead of hanging.
|
|
4
10
|
|
|
5
11
|
2026-05-07: Fixed `print_kitty` (used by `colab exec --output-image` and any image-producing exec) to no-op when `sys.stdout.isatty()` is false. The Kitty Graphics Protocol escape sequence is meaningless when stdout is a file or pipe and was visually corrupting captured output (a multi-KB base64 PNG blob would land in log files, grep targets, or showboat captures). Image bytes are still saved to disk via `handle_image`'s file-write path; only the inline-render attempt is suppressed.
|
|
@@ -33,6 +39,11 @@ Execution involves sending Python code (or shell commands) to the Jupyter kernel
|
|
|
33
39
|
- If file path is remote: Execute `!python <path>`.
|
|
34
40
|
- **Multi-Modal Output**: Handle `display_data` messages (e.g., `image/png`, `text/html`). For the CLI, we'll save images to temporary files and print their paths, or if the terminal supports it (e.g., iTerm2), inline them.
|
|
35
41
|
- **Timeout Configuration**: Exposes a `--timeout` flag (default 30s): the longest silence allowed before execution fails. Raise it so long-running silent tasks (like model compilation or data downloading) are not prematurely killed; `0` means no limit.
|
|
42
|
+
- **Error & `SystemExit` Semantics**:
|
|
43
|
+
- Any uncaught exception (`ValueError`, `SyntaxError`, etc.) causes `colab exec` to exit with status `1`
|
|
44
|
+
- Any executed code block that returns an `output_type == "error"` causes colab to exit with status `11
|
|
45
|
+
- Any exit code stops remaining cells in a `.ipynb` notebook while still writing `*_output.ipynb`.
|
|
46
|
+
- **Why `SystemExit` is handled specially**: Unlike CPython—where `sys.exit(...)` terminates the process directly—an IPython/Jupyter kernel must stay alive across executions, so it catches `SystemExit` and reports it as `output_type == "error"` (`ename == "SystemExit"`), accompanied by an interactive `"An exception has occurred, use %tb..."` banner and `"To exit: use 'exit', 'quit', or Ctrl-D."` `UserWarning`. Treating `SystemExit` like an uncaught exception breaks well-formed scripts passed to `colab exec -f script.py` (such as `argparse --help`, `unittest.main()`, or early-exit guards calling `sys.exit(0)`) and loses custom integer exit codes (`sys.exit(N)`). `colab exec` therefore shares `colab run`'s CPython mapping: `sys.exit()` / `sys.exit(None)` / `sys.exit(0)` exit `0` silently, `sys.exit(N)` exits `N` silently, and `sys.exit("msg")` prints `msg` to `stderr` and exits `1`.
|
|
36
47
|
|
|
37
48
|
## Implementation Details
|
|
38
49
|
- **Kernel Management**: `ColabRuntime` (from `colab-agent`) already handles message signing and message types.
|
|
@@ -46,6 +57,8 @@ TDD is mandatory for all execution features.
|
|
|
46
57
|
- **Test Case**: Verify `ColabRuntime` correctly sends an `execute_request` message over the websocket.
|
|
47
58
|
- **Test Case**: Verify `iopub.stream` messages are correctly handled and printed to `stdout` in real-time.
|
|
48
59
|
- **Test Case**: Verify `display_data` (specifically `image/png`) triggers the correct local handling (saving or display).
|
|
60
|
+
- **Test Case**: Verify `colab exec` exits with status 1 when the kernel emits an `error` output, and halts multi-cell `.ipynb` execution at the failing cell while still saving `*_output.ipynb`.
|
|
61
|
+
- **Test Case**: Verify `colab exec` applies CPython `SystemExit` semantics (`sys.exit(0)`/`None` → `0` silently, `sys.exit(N)` → `N`, `sys.exit("msg")` → prints `msg` to `stderr` and exits `1`) without IPython `%tb` or exit-warning noise.
|
|
49
62
|
|
|
50
63
|
### 2. TTY and Piping
|
|
51
64
|
- **Test Case**: Mock `sys.stdin.isatty()` to verify `colab repl` correctly switches between interactive mode and one-shot piped execution.
|
|
@@ -32,6 +32,7 @@ File management on the Colab VM will be implemented using the Jupyter Contents A
|
|
|
32
32
|
- **API**: `GET /api/contents/<remote_path>?content=1` (as seen in HAR).
|
|
33
33
|
- **Response**: JSON with `content` field.
|
|
34
34
|
- **Handling**: Decodes content based on `format` (`base64`, `json`, or plain `text`) and saves it locally.
|
|
35
|
+
- **Timeouts**: Every Contents API request uses a `(connect, read)` timeout of `(30, 300)` seconds. The read timeout bounds the wait between bytes, not the whole transfer, so large files still finish while a dropped connection fails with an error instead of hanging `ls`, `rm`, `upload`, `download`, or `edit` forever.
|
|
35
36
|
|
|
36
37
|
### 4. Deleting Files (`colab rm`)
|
|
37
38
|
- **API**: `DELETE /api/contents/<remote_path>`.
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
log:
|
|
3
|
+
2026-11-30: `_run_with_timeout` in `auth.py` now sets a `cancel_event` on timeout so keyring worker threads that unblock from `_check_linux_keyring_locked` after timing out skip stale lock warnings and abort before calling `get_password`/`set_password`/`delete_password`. Unit tests now enforce `keyring.backends.null.Keyring` (and `PYTHON_KEYRING_BACKEND`) for the entire pytest process via `pytest_configure` in `tests/conftest.py` instead of restoring the host OS keyring between tests, and timeout tests in `tests/test_auth.py` join spawned daemon threads before fixture teardown.
|
|
4
|
+
2026-11-23: Added standalone version-gated update notices fetched from a movable GitHub tag (`notices_url`, defaulting to `https://raw.githubusercontent.com/googlecolab/google-colab-cli/refs/tags/notices/notices.json`) and cached as `update_notices` in `Settings`. Matching PEP 440 `affects` rules display via `announce_notices` independently of whether PyPI reports a newer version, HTTP 404 silently clears retracted notices without warning, transient errors preserve cached notices, and ANSI/control sequences are stripped.
|
|
5
|
+
2026-11-19: Added `colab logout` to clear stored OAuth2 credentials across all chained OS keyring backends (disambiguating missing entries from real keychain/KWallet failures and warning on `NoKeyringError`) and legacy `~/.config/colab-cli/token.json` without revoking Google Cloud SDK's shared OAuth client grant. Under `--auth=adc`, prints `gcloud auth application-default revoke`. Also invalidates cached runtime proxy tokens in `sessions.json` (warning if local sessions remain), resets cached API capability flags in `settings.json`, and suppresses the daily auto-update banner.
|
|
6
|
+
2026-11-13: `_get_adc_credentials` in `auth.py` now catches `DefaultCredentialsError` from `google.auth.default()` so missing local ADC prints the 4-scope `gcloud auth application-default login` command and exits 1 instead of surfacing `google-auth`'s stock unscoped setup message. Updated scope documentation to clarify that both `colaboratory` and `userinfo.email` are required by `colab.research.google.com`.
|
|
3
7
|
2026-11-07: Optimized `_get_adc_credentials` in `auth.py` to stub `google.auth._cloud_sdk.get_project_id` around `google.auth.default()`. When ADC user credentials lack a `quota_project_id`, `google-auth` otherwise spawns `gcloud config get-value project` on every CLI invocation to resolve a `project_id` that `_get_adc_credentials` immediately discards (`_`).
|
|
4
8
|
2026-11-04: `colab drivemount` now opens the Drive consent URL in the system browser (`utils.open_url_in_browser`, also used by `colab pay`/`colab url --open`) instead of only printing it. The URL is still printed first, and a missing browser opener (SSH, containers, CI) is treated as normal: the flow keeps waiting for the user exactly as before. The prompt moved into `commands/automation.py::show_drive_auth_url` so it can be unit-tested.
|
|
9
|
+
2026-11-04: `colab drivemount` now handles credentials-propagation failures instead of dumping the HTTP body. Responses are parsed defensively (HTML/empty bodies no longer raise out of the websocket hook), an authentication prompt is only shown when the server actually returns an `unauthorized_redirect_uri`, and failures print the status plus the multi-account guidance (select the account from `colab whoami`) while logging the raw body to history. The intercepted kernel request is answered on failure too, so the command exits promptly instead of hanging until its 600s timeout.
|
|
5
10
|
2026-11-02: Added `_check_linux_keyring_locked` in `auth.py` to inspect the active Linux `SecretService` collection via `secretstorage` before `get_password`/`set_password`, warning immediately when the keyring is locked so users know why the CLI is waiting on an unlock prompt (and suggesting `--auth=adc`).
|
|
6
11
|
2026-10-29: Session history files are created readable only by the owner (0600), and existing ones are tightened to 0600 whenever the history logger starts.
|
|
12
|
+
2026-10-22: Added hidden `colab test-public-api` subcommand and `Client.check_api_access()` to probe both `colaboratory.googleapis.com/v1beta/runtimes` and `colab.research.google.com/tun/m/assignments`, caching `public_api_supported` and `tunnel_api_supported` in `Settings` for targeted HTTP 401/403 error hints.
|
|
7
13
|
2026-10-21: Migrated OAuth2 token persistence in `auth.py` from `~/.config/colab-cli/token.json` to the OS native password storage via the `keyring` library (`KEYRING_SERVICE_NAME = "google-colab-cli"`, `KEYRING_USERNAME = "oauth_token"`). When the keyring is empty, locked, or inaccessible, `_run_remote_flow` is invoked; keyring read/write failures print a warning to stderr without failing the command. An existing `~/.config/colab-cli/token.json` (`LEGACY_TOKEN_PATH`) is used when the keyring has no token, copied into the keyring, and deleted only after the keyring write succeeds; it is also deleted when the keyring already holds a token.
|
|
8
14
|
2026-09-25: Cleaned up references to keep-alive background daemon and pre-flight pings. VM liveness is automatically maintained by the Colab backend based on active kernel activity.
|
|
9
15
|
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`).
|
|
@@ -75,15 +81,15 @@ allowing the core `Client` to remain authentication-agnostic — it only sees a
|
|
|
75
81
|
### Required Scopes
|
|
76
82
|
|
|
77
83
|
The CLI talks to the Colab session backend at `colab.research.google.com`
|
|
78
|
-
for assignment, unassignment, CCU info, and the contents API.
|
|
79
|
-
|
|
84
|
+
for assignment, unassignment, CCU info, and the contents API. Both the
|
|
85
|
+
`colaboratory` and `userinfo.email` scopes are required for this host.
|
|
80
86
|
|
|
81
|
-
How each provider supplies the
|
|
87
|
+
How each provider supplies the scopes:
|
|
82
88
|
|
|
83
|
-
- **`oauth2`**: `PUBLIC_SCOPES`
|
|
84
|
-
InstalledAppFlow consent screen lists
|
|
85
|
-
keyring that were minted before a scope
|
|
86
|
-
fresh consent flow.
|
|
89
|
+
- **`oauth2`**: `PUBLIC_SCOPES` includes both `colaboratory` and
|
|
90
|
+
`userinfo.email`, so the InstalledAppFlow consent screen lists them.
|
|
91
|
+
Existing cached tokens in the keyring that were minted before a scope
|
|
92
|
+
change must be cleared to trigger a fresh consent flow.
|
|
87
93
|
- **`adc`**: `google.auth.default(scopes=PUBLIC_SCOPES)` is called, and for
|
|
88
94
|
credential subclasses that support `with_scopes` (service accounts,
|
|
89
95
|
GCE/GKE metadata, impersonated) we re-apply via `creds.with_scopes(...)`.
|
|
@@ -91,20 +97,16 @@ How each provider supplies the scope:
|
|
|
91
97
|
`scopes=` kwarg AND raise `NotImplementedError` on `with_scopes`; those
|
|
92
98
|
users must explicitly re-authenticate:
|
|
93
99
|
|
|
94
|
-
```
|
|
100
|
+
```bash
|
|
95
101
|
gcloud auth application-default login \
|
|
96
|
-
--scopes=openid
|
|
97
|
-
https://www.googleapis.com/auth/cloud-platform,\
|
|
98
|
-
https://www.googleapis.com/auth/userinfo.email,\
|
|
99
|
-
https://www.googleapis.com/auth/colaboratory
|
|
102
|
+
--scopes=openid,https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/colaboratory
|
|
100
103
|
```
|
|
101
104
|
|
|
102
|
-
`userinfo.email`
|
|
103
|
-
`colab.research.google.com` (otherwise assign/unassign/sessions
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
`
|
|
107
|
-
lists that omit `cloud-platform` with `Invalid value for [--scopes]`).
|
|
105
|
+
`colaboratory` and `userinfo.email` are required for the session backend at
|
|
106
|
+
`colab.research.google.com` (otherwise assign/unassign/sessions return HTTP
|
|
107
|
+
401); `openid` and `cloud-platform` are mandated by `gcloud` itself
|
|
108
|
+
(`gcloud auth application-default login` rejects scope lists that omit
|
|
109
|
+
`cloud-platform` with `Invalid value for [--scopes]`).
|
|
108
110
|
|
|
109
111
|
## Approach
|
|
110
112
|
|
|
@@ -148,6 +150,16 @@ How each provider supplies the scope:
|
|
|
148
150
|
`jupyter_kernel_client` default raising `TimeoutError` mid-flow, this
|
|
149
151
|
subcommand passes `timeout=INTERACTIVE_AUTOMATION_TIMEOUT_SEC` (600s) to
|
|
150
152
|
`ColabRuntime.execute_code`. Same applies to `colab auth`.
|
|
153
|
+
- **Multi-account browsers**: Drive propagation is attributed to the Google
|
|
154
|
+
account that approves the consent page, which may not be the account the
|
|
155
|
+
CLI authenticated as. If the browser shows an account chooser, select the
|
|
156
|
+
account reported by `colab whoami`; approving with another account fails
|
|
157
|
+
with HTTP 400 even though the consent itself succeeded. A private window
|
|
158
|
+
only helps if it is already signed in to that account.
|
|
159
|
+
- **Failure reporting**: errors from the propagation endpoint never echo the
|
|
160
|
+
raw response body (often HTML). The CLI prints the status, points at
|
|
161
|
+
`colab whoami`, logs the body to the history file, and answers the waiting
|
|
162
|
+
kernel request so `drivemount` exits instead of hanging until its timeout.
|
|
151
163
|
|
|
152
164
|
### 4. Logging and Notebook Capture (`colab log`)
|
|
153
165
|
|
|
@@ -185,48 +197,70 @@ How each provider supplies the scope:
|
|
|
185
197
|
Git commit hash using `git rev-parse --short HEAD`.
|
|
186
198
|
- Dynamic versioning is supported in the build system via `hatch-vcs`.
|
|
187
199
|
|
|
188
|
-
### 8. Auto-Update (`colab update`)
|
|
200
|
+
### 8. Auto-Update & Standalone Notices (`colab update`)
|
|
189
201
|
|
|
190
|
-
- **Action**: Check if a new version of the Colab CLI
|
|
191
|
-
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
202
|
+
- **Action**: Check if a new version of the Colab CLI or any standalone
|
|
203
|
+
version-gated advisory notice is available.
|
|
204
|
+
- **Auto-check**: The CLI automatically fetches PyPI and the standalone
|
|
205
|
+
notices feed once every 24 hours during the execution of any non-suppressed
|
|
206
|
+
command. Independently, the cached `latest_version` and `update_notices`
|
|
207
|
+
are consulted on **every** invocation so upgrade and standalone notice
|
|
208
|
+
banners remain visible between fetches without requiring a network
|
|
195
209
|
round-trip.
|
|
196
210
|
- **Suppressed subcommands**: To keep machine-parseable output clean, the
|
|
197
|
-
daily fetch and the cached
|
|
198
|
-
|
|
199
|
-
`
|
|
200
|
-
|
|
201
|
-
|
|
211
|
+
daily fetch and the cached banners are suppressed for subcommands listed in
|
|
212
|
+
`_AUTO_UPDATE_SUPPRESSED` (and non-TTY `ssh`) in the global Typer callback
|
|
213
|
+
in `cli.py`.
|
|
214
|
+
- **Manual-check**: `colab update` forces a check and prints the status plus
|
|
215
|
+
any matching standalone notices.
|
|
202
216
|
- **Implementation**:
|
|
203
217
|
- Fetches a PyPI-style JSON document from a configurable `update_url`
|
|
204
|
-
(default: `https://pypi.org/pypi/google-colab-cli/json`)
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
218
|
+
(default: `https://pypi.org/pypi/google-colab-cli/json`).
|
|
219
|
+
- Selects latest stable public releases (`_parse_stable_version`) from
|
|
220
|
+
`releases` with fallback to `info`.
|
|
221
|
+
- Compares the candidate with the current CLI version.
|
|
222
|
+
- Independently fetches standalone notices from `notices_url` (default:
|
|
223
|
+
`https://raw.githubusercontent.com/googlecolab/google-colab-cli/refs/tags/notices/notices.json`;
|
|
224
|
+
managed via `tools/notices.py`, see [07_update_notices.md](07_update_notices.md)).
|
|
225
|
+
- Notice payload schema: a JSON array `[{"affects": "<1.0.0", "message": "..."}]`
|
|
226
|
+
(or `{"notices": [...]}`). Each entry's `affects` is evaluated against
|
|
227
|
+
the installed version with `packaging.specifiers.SpecifierSet(..., prereleases=True)`.
|
|
228
|
+
ANSI escape codes and control characters are stripped, messages are
|
|
229
|
+
truncated to 500 characters, and at most 3 deduplicated notices are
|
|
230
|
+
printed.
|
|
209
231
|
- Persists the following fields in `~/.config/colab-cli/settings.json`:
|
|
210
|
-
- `update_url`: source configuration.
|
|
232
|
+
- `update_url`: PyPI JSON source configuration.
|
|
233
|
+
- `notices_url`: standalone notices JSON source configuration.
|
|
211
234
|
- `last_check`: timestamp of the last fetch (drives the daily
|
|
212
235
|
throttle).
|
|
213
236
|
- `enable_update_check`: master switch for both the daily fetch and
|
|
214
|
-
|
|
215
|
-
- `latest_version`: highest version observed during the most
|
|
216
|
-
recent successful check. Updated whenever a strictly-newer
|
|
217
|
-
version is observed (never downgraded),
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
237
|
+
cached upgrade/notice banners.
|
|
238
|
+
- `latest_version`: highest stable version observed during the most
|
|
239
|
+
recent successful check. Updated whenever a strictly-newer stable
|
|
240
|
+
version is observed (never downgraded), preserved across failed
|
|
241
|
+
checks when valid, and self-healed (cleared or replaced) if a stale
|
|
242
|
+
prerelease or invalid string is present.
|
|
243
|
+
- `update_notices`: list of `{affects, message}` entries from the
|
|
244
|
+
most recent successful notices fetch. Overwritten on HTTP 200 or
|
|
245
|
+
cleared to `[]` on HTTP 404 (absent/deleted `notices` tag, with no
|
|
246
|
+
warning printed), and preserved across transient network failures.
|
|
247
|
+
`affects` is re-evaluated on every invocation so cached notices
|
|
248
|
+
stop appearing immediately once the user upgrades past the range.
|
|
249
|
+
- **Notification**:
|
|
250
|
+
- If a new stable version is found, a non-intrusive banner is printed with a
|
|
251
|
+
`Run 'pip install --upgrade google-colab-cli' to update.` (or `uv tool
|
|
252
|
+
install -U`) hint, plus `You can run 'colab update --install' to upgrade
|
|
253
|
+
in place.` on Linux and macOS. Cached banners between fetches use the
|
|
254
|
+
generic `Run 'colab update' to update.` hint.
|
|
255
|
+
- Any matching standalone notices are printed via `announce_notices` as
|
|
256
|
+
`[colab] Notice: <message>`, **even when the CLI is already on the
|
|
257
|
+
latest PyPI version**. When both an upgrade banner and notices are
|
|
258
|
+
shown unsolicited, the `"enable_update_check": false` silence hint is
|
|
259
|
+
printed only once at the bottom.
|
|
226
260
|
- **Self-install (`--install`)**: An opt-in `--install` flag (default
|
|
227
261
|
`False`) makes `colab update` upgrade the CLI in place (**Linux and macOS**).
|
|
228
262
|
It detects how the CLI was installed:
|
|
229
|
-
- If `sys.executable` contains `/uv/tools
|
|
263
|
+
- If `sys.executable` contains `/uv/tools/` (indicating it was installed via
|
|
230
264
|
`uv tool install`), it runs `uv tool install -U google-colab-cli`.
|
|
231
265
|
- Otherwise, runs `pip install -U google-colab-cli` using `sys.executable`
|
|
232
266
|
to ensure the upgrade lands in the same interpreter.
|
|
@@ -291,6 +325,23 @@ How each provider supplies the scope:
|
|
|
291
325
|
installed), it falls back to reading the files from the project root.
|
|
292
326
|
- Prints the content to stdout.
|
|
293
327
|
|
|
328
|
+
### 11. Public & Tunnel API Probe (`colab test-public-api`)
|
|
329
|
+
|
|
330
|
+
- **Action**: Hidden diagnostic command (`hidden=True`, suppressed from auto-update banner) that runs `state.client.check_api_access()`.
|
|
331
|
+
- **Implementation**:
|
|
332
|
+
- Issues read-only GET probes to `https://colaboratory.googleapis.com/v1beta/runtimes` and `https://colab.research.google.com/tun/m/assignments`.
|
|
333
|
+
- Persists `public_api_supported` and `tunnel_api_supported` booleans in `~/.config/colab-cli/settings.json` and prints `OK` or `FAILED` for each backend.
|
|
334
|
+
- When `Client._issue_request` receives HTTP 401/403, it updates the failed backend's cached flag and appends a targeted remediation hint (`--no-public-api` or `--public-api`) if the alternate backend is cached as supported.
|
|
335
|
+
|
|
336
|
+
### 12. Sign Out (`colab logout`)
|
|
337
|
+
|
|
338
|
+
- **Action**: Clear locally cached OAuth2 credentials and cached runtime proxy tokens so the user can sign out or switch accounts on the next command.
|
|
339
|
+
- **Implementation**:
|
|
340
|
+
- Under `--auth=oauth2` (default), deletes `(google-colab-cli, oauth_token)` across all chained keyring backends (disambiguating missing entries from real keychain/KWallet errors and warning on stderr on `NoKeyringError`) and removes any leftover `~/.config/colab-cli/token.json`, attempting both stores even if one errors. Does not call Google's `/revoke` endpoint because the bundled OAuth client is shared with Google Cloud SDK.
|
|
341
|
+
- Under `--auth=adc`, leaves local ADC untouched and directs the user to `gcloud auth application-default revoke`.
|
|
342
|
+
- Blanks cached `token` and `token_expires_at` on local `sessions.json` entries (so `-s NAME` cannot bypass re-auth with stale proxy tokens), resets cached `public_api_supported`/`tunnel_api_supported` flags in `settings.json`, and warns on stderr if local sessions exist.
|
|
343
|
+
- Suppressed from the daily auto-update banner (`_AUTO_UPDATE_SUPPRESSED`).
|
|
344
|
+
|
|
294
345
|
## Implementation Details
|
|
295
346
|
|
|
296
347
|
- **Code Injection**: Use a standard `run_code(session, code)` helper via
|
|
@@ -343,3 +394,8 @@ TDD is mandatory for all automation features.
|
|
|
343
394
|
- **Test Case**: Verify `colab AGENT` prints the same content.
|
|
344
395
|
- **Test Case**: Verify fallback to local `README.md` file when metadata is not available.
|
|
345
396
|
- **Test Case**: Verify error exit when both metadata and local file are unavailable.
|
|
397
|
+
|
|
398
|
+
### 5. `logout` Account Sign-Out
|
|
399
|
+
|
|
400
|
+
- **Test Case**: Verify `clear_oauth_token()` removes both keyring entries (including across `ChainerBackend` backends) and `LEGACY_TOKEN_PATH`, handles concurrent `FileNotFoundError` and macOS `NotFound` cleanly, and re-raises locked/denied/cancelled `PasswordDeleteError` and `OSError` without skipping the remaining store.
|
|
401
|
+
- **Test Case**: Verify `colab logout` invalidates cached runtime tokens in `sessions.json`, resets cached capability flags in `settings.json`, suppresses auto-update checks, emits warnings/errors to stderr, and prints the `gcloud` hint under `--auth=adc`.
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
log:
|
|
3
|
+
2026-12-02: `_teardown` now keeps the local session record and logs/prints a retry hint (`colab stop -s <name>`) when `unassign` fails, instead of silently deleting local state and orphaning the VM (discussion #309).
|
|
4
|
+
2026-11-23: Moved CPython `SystemExit` helpers (`_exit_code_from_outputs`, `_make_script_output_hook`) to `commands/execution.py` so `colab exec` and `colab run` share identical exit-code and `stderr` message semantics (including printing non-integer `sys.exit("msg")` messages to `stderr`).
|
|
3
5
|
2026-09-25: Removed keep-alive daemon spawning from session allocation and teardown. `--keep` remains supported and skips unassignment on completion.
|
|
4
6
|
2026-08-09: Added `--high-mem` flag (passthrough to session creation; sends `shape=hm` on assign when supported).
|
|
5
7
|
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__"`.
|
|
@@ -63,8 +65,7 @@ print(torch.cuda.get_device_name(0))
|
|
|
63
65
|
4. **Tear down**: In a `finally` block, unless `--keep` was passed, the CLI:
|
|
64
66
|
- Sends `runtime.stop(shutdown_kernel=True)` (best-effort).
|
|
65
67
|
- Calls `state.client.unassign(endpoint)` to free the billable VM.
|
|
66
|
-
-
|
|
67
|
-
- Logs `session_terminated` with `reason="run_completed"` (or `"run_failed"`).
|
|
68
|
+
- Only after `unassign` succeeds: removes the session from `StateStore` and logs `session_terminated` with `reason="run_completed"` (or `"run_failed"`). If `unassign` fails, the failure is logged and printed to `stderr` with a `colab stop -s <name>` retry hint, and the local record is kept so the session remains addressable.
|
|
68
69
|
|
|
69
70
|
If `--keep` is set, the session remains visible in `colab sessions` and `colab status` and can be reused with `colab exec -s <name>`, `colab repl -s <name>`, etc., until the user runs `colab stop` (or the backend reclaims it due to inactivity).
|
|
70
71
|
|
|
@@ -84,6 +85,7 @@ If `--keep` is set, the session remains visible in `colab sessions` and `colab s
|
|
|
84
85
|
7. **`test_run_missing_script_errors`** — `colab run` with no script path errors out (Typer-level).
|
|
85
86
|
8. **`test_run_nonexistent_script_errors_before_assign`** — `colab run does-not-exist.py` MUST exit non-zero **without** calling `client.assign` so users don't burn a VM on a typo.
|
|
86
87
|
9. **`test_run_unassign_called_on_exception_during_execute`** — If `runtime.execute_code` raises, unassign is still called (try/finally guarantee).
|
|
88
|
+
10. **`test_run_teardown_keeps_local_session_when_unassign_fails`** / **`test_run_teardown_keeps_local_session_when_execute_and_unassign_fail`** — If `unassign` raises during teardown, the local session record is kept, `session_terminated` is not logged, and a warning with `colab stop -s <name>` is printed to `stderr` without masking the script's exit status.
|
|
87
89
|
|
|
88
90
|
### Integration test (`integration/repro_run_command/test.sh`)
|
|
89
91
|
- Write a tiny script that prints its argv and exits 0.
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
log:
|
|
3
|
+
2026-12-04: `colab ssh` no longer sends an `Origin` header on the `/colab/ssh` upgrade (`suppress_origin=True`); the runtime rejects an upgrade that carries one with HTTP 403.
|
|
4
|
+
2026-11-27: Fixed `colab ssh` under Git for Windows' MSYS `ssh` (`/usr/bin/ssh` in Git Bash): ProxyCommand path arguments now use forward slashes on Windows (bash stripped the backslashes, failing with `D:Projects...python.exe: not found`), and `UserKnownHostsFile` is `/dev/null` when `ssh.exe` is an MSYS/Cygwin build (it wrote the host key to a `./nul` file). Native Windows OpenSSH keeps `nul`. Verified live from Git Bash and PowerShell (OpenSSH_for_Windows 9.5), and `integration/repro_windows_ssh/test.py` passed.
|
|
5
|
+
2026-11-23: Updated `integration/repro_windows_ssh/test.py` to check cached OAuth2 credentials via the OS `keyring` (`KEYRING_SERVICE_NAME` / `KEYRING_USERNAME`) instead of the removed `TOKEN_CONFIG_PATH`, and added portable import and prerequisite-skip regression tests in `tests/test_windows_ssh.py`.
|
|
3
6
|
2026-11-09: `--identity/-i` now accepts either a `.pub` public key or a private key path: `_resolve_pubkey` reads the `.pub` file directly when present before falling back to `_pubkey_from_identity` (`ssh-keygen -y -f`), and `_ssh_base_args` strips `.pub` for `ssh -i` when the sibling private key exists on disk.
|
|
4
7
|
2026-10-29: Removed the `colab console` subcommand, so `colab ssh` is the interactive shell on the runtime. Dropped console behavior from the Windows validation caveat.
|
|
5
8
|
2026-10-29: Added `colab ssh [-s NAME] -- CMD`, which runs one command on an existing session and exits with its status (a PTY only when stdin and stdout are terminals; neither it nor its ProxyCommand child creates a runtime). Its handshake carries `ssh-mode-cmd`, and the update banner is skipped for `ssh` when stdout is not a terminal. Added `tests/test_ssh_cmd.py`.
|
|
@@ -103,7 +106,14 @@ session (never creating one); every word from CMD on goes to CMD, flags too.
|
|
|
103
106
|
falls back to the login home.
|
|
104
107
|
On native Windows, the ProxyCommand uses `subprocess.list2cmdline` for
|
|
105
108
|
CreateProcessW argument parsing; POSIX systems continue to use `shlex.join`.
|
|
106
|
-
|
|
109
|
+
Path arguments (the interpreter, `--config`, `--identity`) are emitted with
|
|
110
|
+
forward slashes on Windows: Git for Windows' MSYS `ssh` (`/usr/bin/ssh` in
|
|
111
|
+
Git Bash) runs ProxyCommand as `bash -c "exec <cmd>"`, which strips unquoted
|
|
112
|
+
backslashes, while CreateProcessW and Python accept `D:/...` unchanged.
|
|
113
|
+
The local `UserKnownHostsFile` uses `os.devnull` (`nul` on Windows), except
|
|
114
|
+
when the `ssh` on PATH is an MSYS/Cygwin build (`msys-2.0.dll` or
|
|
115
|
+
`cygwin1.dll` beside `ssh.exe`): those treat `nul` as a regular file and
|
|
116
|
+
write the host key to `./nul`, so they get `/dev/null`.
|
|
107
117
|
4. **`--proxy-mode` bridge**: Bridges the WebSocket ↔ stdin/stdout for use as an
|
|
108
118
|
OpenSSH `ProxyCommand`. Honors every flag: `-s NAME` creates the session if
|
|
109
119
|
missing (creation output routed to stderr so stdout stays the clean ssh byte
|
|
@@ -191,18 +201,24 @@ interpreter installed under a path with spaces. Assertions check exact argv
|
|
|
191
201
|
preservation for spaces, quotes, shell punctuation, backslashes, Unicode, and
|
|
192
202
|
identity paths. A separate test launches the real Windows OpenSSH client with
|
|
193
203
|
a local stub ProxyCommand and verifies its argv, without contacting Colab.
|
|
194
|
-
|
|
195
|
-
|
|
204
|
+
When Git for Windows is installed, the ProxyCommand is also run through its
|
|
205
|
+
`bash -c "exec ..."` (how MSYS `ssh` launches it) with interpreters under
|
|
206
|
+
paths with and without spaces. The null-device choice is checked for native
|
|
207
|
+
OpenSSH and for MSYS/Cygwin `ssh.exe` layouts.
|
|
208
|
+
Portable tests also check registration without SIGHUP, the local null
|
|
209
|
+
device, and `integration/repro_windows_ssh/test.py` import and prerequisite
|
|
210
|
+
skip paths across platforms. Existing POSIX shell quoting and teardown tests
|
|
211
|
+
remain in the suite.
|
|
196
212
|
|
|
197
213
|
These and the existing SSH tests passed on Windows, Linux, and macOS with
|
|
198
214
|
Python 3.12. This covers SSH compatibility only; local file editing and
|
|
199
215
|
self-update require separate platform validation.
|
|
200
216
|
|
|
201
217
|
`uv run python integration/repro_windows_ssh/test.py` provides a native Windows
|
|
202
|
-
live test using cached
|
|
203
|
-
remote command through the generated ProxyCommand with a key
|
|
204
|
-
spaces, exercises `--rm`, and cleans up the recorded endpoint on
|
|
205
|
-
77 is a prerequisite skip, not a successful live validation.
|
|
218
|
+
live test using OAuth2 credentials cached in the OS keyring. It creates a CPU
|
|
219
|
+
runtime, executes a remote command through the generated ProxyCommand with a key
|
|
220
|
+
path containing spaces, exercises `--rm`, and cleans up the recorded endpoint on
|
|
221
|
+
failure. Exit 77 is a prerequisite skip, not a successful live validation.
|
|
206
222
|
|
|
207
223
|
The native Windows live test passed on 2026-10-20 with Python 3.12.14 and the
|
|
208
224
|
Windows OpenSSH client. This validates remote command execution and cleanup
|