Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,11 @@ Run `colab <command> --help` to view specific options, defaults, and detailed he
### File Operations
| Command | Description |
| --- | --- |
| `colab ls [-s NAME] [PATH]` | List remote files on the VM |
| `colab upload [-s NAME] [-r] LOCAL REMOTE` | Upload a local file or directory (`-r`) to the VM filesystem |
| `colab download [-s NAME] [-r] REMOTE LOCAL` | Download a remote file or directory (`-r`) from the VM filesystem |
| `colab rm [-s NAME] PATH` | Delete a remote file on the VM filesystem |
| `colab ls [-s NAME] [--json] [PATH]` | List remote files on the VM (`--json`: name, type, size, modified) |
| `colab upload [-s NAME] [-r] [--via contents\|ssh] LOCAL REMOTE` | Upload a local file or directory (`-r`) to the VM filesystem; `--via ssh` copies with scp |
| `colab download [-s NAME] [-r] [--via contents\|ssh] REMOTE LOCAL` | Download a remote file or directory (`-r`) from the VM filesystem; `--via ssh` copies with scp |
| `colab mkdir [-s NAME] PATH` | Create a remote folder |
| `colab rm [-s NAME] [-r] PATH` | Delete a remote file, or a folder with everything in it (`-r`) |
| `colab edit [-s NAME] PATH` | Edit a remote file in-place using your local `$EDITOR` |

### Automation & Utilities
Expand Down Expand Up @@ -272,6 +273,33 @@ Make the script executable (`chmod +x script.py`) and run it: `./script.py`. The

---

### Tray File Manager

`colab tray` shows a **Files** button on each runtime's card. It opens a two-pane window, like Total Commander: this computer on the left, the runtime's `/content` on the right.

- **Copy:** drag and drop between the panes (or from Explorer), the **Upload / Download** buttons, or **F5**. **F7** new folder, **F8** delete (local files go to the recycle bin), **Enter** opens, **Backspace** goes up, the drive list switches drives.
- **Transfer:** *Contents API* (no key needed) or *SSH / scp* (faster for big files; needs an SSH key without a passphrase: set `"ssh_identity": "~/.ssh/your_key"` in `~/.config/colab-cli/settings.json` if it is not `~/.ssh/id_ed25519`).
- **Progress and Cancel:** a bar with files done / total and the time; Cancel stops the copy (files already copied stay; with scp the file being copied may be cut short).
- **Command line:** the field at the bottom runs a command in the runtime's current folder.
- If the runtime stops or the connection ends, a red banner says so and only the local pane stays usable.

Details: [docs/09_tray_and_profiles.md](docs/09_tray_and_profiles.md), section 5.

### Runtimes Opened in the Colab Web UI

A runtime you started in the browser shows as `[?]` in `colab sessions`. Attach it to use it from the CLI:

```bash
colab sessions # [?] m-s-usc1c3-29lht8cq7mkz8 | Hardware: CPU ...
colab attach --endpoint m-s-usc1c3-29lht8cq7mkz8 -s web
colab upload -s web data.csv /content/data.csv
colab upload -s web -r --via ssh ./project /content/project
colab ssh -s web -- ls -la /content
colab stop -s web # stops it in the browser too
```

The CLI runs code in its own kernel, not the notebook's, but `/content` is shared, so uploaded files show in the notebook's Files panel at once. In the tray, the card of such a runtime has a **Connect** button that runs `colab attach` for you. To stop one without attaching: `colab stop --endpoint ID`.

## Deep Dive Documentation

For comprehensive architectural overviews and deep-dives into specific CLI sub-systems, refer to the detailed documentation:
Expand Down
2 changes: 2 additions & 0 deletions docs/03_file_management.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
log:
2026-11-20: `upload`/`download --progress` prints `[colab] progress DONE/TOTAL PATH` after each file (TOTAL is `?` for a recursive download, which does not count first); the tray's file manager reads it for its progress bar. `upload/download --via ssh` kill their scp when they get SIGTERM, so a cancel does not leave scp copying.
2026-11-20: For the tray's file manager: `colab ls --json` (one object: path, items with name/type/size/last_modified, folders first; an error is JSON too), `colab mkdir`, `colab rm -r` (`ContentsClient.rm_tree`, children first, since the contents API refuses a folder that is not empty), and `--via ssh [-i KEY]` on `upload`/`download`, which copies with OpenSSH scp through `colab ssh --proxy-mode` (`ssh.scp_transfer`) using the default key setting. Tested live on an attached web UI runtime.
2026-11-20: Took upstream PR #267 (`colab upload -r` / `colab download -r`, by Koji Shukawa) before Google merged it, with its review comments applied: no `ntpath` import (a drive-prefixed entry name is still refused on Windows, through `os.path.splitdrive`), simpler `posixpath.join` calls, `_is_local_symlink` so a destination given as `link/` is still seen as a symlink on POSIX, and HTTP errors without the URL (the fork's message, which hides the runtime proxy token). Tested live on a Colab web UI runtime: a tree with subfolders and an empty folder uploaded and downloaded back identical.
2026-11-19: Added `-r`/`--recursive` support to `colab upload` and `colab download` via `ContentsClient.mkdir`, `_ensure_dir`, `upload_dir`, and `download_dir` (preserving empty directories, skipping symlinks on upload, handling single-file `download -r` targets, normalizing remote paths, and enforcing entry-name, canonical local-symlink/containment, and recursion-depth checks). Reused a persistent `requests.Session` in `ContentsClient` with `close()`/context-manager cleanup (reopening a fresh client after `$EDITOR` in `colab edit`) for HTTP keep-alive, and redacted `colab-runtime-proxy-token` query params from `HTTPError` messages.
2026-11-12: Errors no longer show the runtime proxy token: `ContentsClient` reports an HTTP error as status and path (requests put the full URL, token included, in its message) and the file commands print errors through `common.redact_secrets`. Under Git Bash on Windows, remote paths that MSYS rewrote (`/content` -> `C:/Program Files/Git/content`) are turned back by `utils.undo_msys_path`. A failing editor in `colab edit` prints `[colab] ...: Editing failed` and exits 1 instead of a traceback (Typer vendors its own Click and does not handle `click.ClickException`).
Expand Down
99 changes: 99 additions & 0 deletions docs/09_tray_and_profiles.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
log:
2026-11-20: File manager: a progress bar with files done / total, the file and the time (`--progress` lines from `upload`/`download`), a Cancel button that stops the whole process tree (taskkill /T on Windows; SIGTERM elsewhere, on which scp is killed), a red banner and a read-only remote side when the runtime is gone (from the tray's refresh or a "Session not found"), and a note that a failed or cancelled scp may leave a cut-short file. Section 5 documents the window in full. Tested live: per-file progress on a 30-file upload, cancel over the contents API (7 of 60 files copied) and over scp (no scp left running), and the banner after `colab stop` with the window open.
2026-11-20: A two-pane file manager (`tray/files.py`, argv in `tray/file_ops.py`), opened with the Files button of a local card, in the style of Total Commander: this computer on the left (drive list, Up), the runtime on the right from `content`. Copy by drag and drop, the Upload/Download buttons or F5; F7 new folder, F8 delete (a local file goes to the recycle bin, a remote one after a confirmation, `rm -r` for a folder), Enter or double-click opens, Backspace goes up. The line at the bottom runs a command in the runtime's folder (`colab ssh -- sh -c` over ssh, otherwise `colab exec` with Python on stdin, so no key is needed). Transfers go over the contents API or scp (`--via`), chosen at the top and saved as `tray_transfer`. Every action is a CLI subcommand run with QProcess, one at a time. Tested live: the window's runner uploaded, downloaded, ran a command and deleted on an attached web UI runtime; the user tried it from the tray.
2026-11-20: The SSH and forward buttons use `ssh_identity` from `settings.json` (or `COLAB_CLI_SSH_IDENTITY`) when the key is not `~/.ssh/id_ed25519` / `id_ecdsa`; before, they ended with "no SSH public key found".
2026-11-20: A card without a wrapped line (an idle runtime, such as one just attached with Connect) has no height for width, and Qt then returns about 1 px: the card list collapsed and the panel looked empty. Each card now takes the larger of its size hint and its height for the panel width.
2026-11-20: The card of a runtime with no local session also has a Connect button, which runs `colab attach --endpoint <id>`; the runtime then becomes a normal card with Log and SSH.
Expand Down Expand Up @@ -255,6 +257,7 @@ run it on each binary.
running job only the runtime can be stopped. A runtime with no local
session is stopped by its endpoint (`colab stop --endpoint`), and the
dialog says it may be open in the Colab web UI or on another computer.
- **Files** opens a two-pane file manager for the runtime; see section 5.
- **Log** opens a window that runs `colab job tail -n 200` (Follow adds
`--follow` while the job runs) or, without a job, `colab log -n 200`, and
shows the output as it comes; a help line says what it shows and where the
Expand Down Expand Up @@ -304,6 +307,102 @@ run it on each binary.
from the Colab logo of homarr-labs/dashboard-icons (Apache-2.0): Colab's C
and a teal ring. The Colab logo is a trademark of Google.

## 5. The file manager (`tray/files.py`)

The Files button of a local card opens a two-pane window for that runtime,
in the style of Total Commander. `tray/file_ops.py` (no Qt) turns every
action into argv for one of the CLI's own subcommands; the window runs them
with QProcess, one at a time, and never talks to the runtime itself.

### Layout

| Part | What it is |
|------|------------|
| Banner (red, hidden normally) | Shown when the runtime is gone; see *When the runtime goes away*. |
| Transfer | Contents API or SSH / scp; remembered as `tray_transfer` in `settings.json`. Refresh re-lists the remote folder. |
| Left pane: *This computer* | Drive list (`QDir.drives()`), path field (type a path and press Enter), up button (parent). A `QFileSystemModel` view of the folder. |
| Right pane: *Colab runtime* | Path field (contents-API path such as `content/data`), up button, and the listing from `colab ls --json`: name (folders end in `/`), size, modified. Starts at `content` (`/content`); `..` goes up, up to the runtime's root. |
| Button bar | Upload, Download, F7 New folder, F8 Delete. |
| Command line | `/content/...$` prompt and a field: runs a command in the remote folder. |
| Output | What every command printed (transfers, errors, command output). |
| Progress | A bar and a Cancel button while something runs; the status line under it. |

### Keys and mouse

| Action | How |
|--------|-----|
| Copy | Drag files or folders from one pane to the other (also from Explorer / Finder onto the right pane), the Upload / Download buttons, or F5 (copies the selection of the focused pane to the other pane's folder). Dropping on a folder copies into that folder. |
| Open | Enter or double-click: a folder opens; a local file opens in its default program; a remote file does nothing. |
| Up | Backspace, or the up button. |
| New folder | F7 (in the focused pane). |
| Delete | F8 (in the focused pane), after a confirmation. Local files go to the recycle bin (`QFile.moveToTrash`); remote ones are deleted for good (`colab rm`, `rm -r` for a folder). |
| Command | Type in the line at the bottom and press Enter. |

### Transfers

| | Contents API (default) | SSH / scp |
|---|---|---|
| Runs | `colab upload/download [-r] --via contents --progress` | `colab upload/download [-r] --via ssh` (OpenSSH scp through `colab ssh --proxy-mode`) |
| Needs | nothing | an SSH key: `ssh_identity` in `settings.json`, `COLAB_CLI_SSH_IDENTITY`, or `~/.ssh/id_ed25519` / `id_ecdsa`; no passphrase |
| Speed | base64 inside JSON: fine for code and small data | faster for big files |
| Progress | per file: "3 / 10 files, path, 0:12" and a filling bar (a download counts files without a total) | a moving bar and the time; no per-file data |
| A failure or cancel | each file is written whole or not at all; files copied before stay | the file being copied may be cut short (the window says so) |
| Limits | | a free CPU runtime takes one SSH connection at a time, so an open `colab ssh` makes scp fail with 429 |

A folder is copied with its subfolders, empty ones included. Copying onto an
existing remote folder of the same name merges into it over the contents
API; scp then puts the folder inside it.

### Command line

The command runs in the remote folder shown in the prompt. Over SSH it is
`colab ssh -s NAME -- sh -c "cd FOLDER && COMMAND"`; otherwise `colab exec`
gets Python on stdin that runs the command with `subprocess.run(shell=True,
cwd=FOLDER)` and prints its output and `[exit N]`, so it works without a key
(in the CLI's kernel, not a notebook's). The listing is refreshed after it.
If the connection ends, an ssh command ends with it; one run through
`colab exec` may go on running on the runtime.

### Cancel

Cancel stops the running command and drops the waiting ones. The window stops
the whole process tree: `taskkill /T /F` on Windows (a child such as scp
outlives its parent there), SIGTERM elsewhere, on which `colab upload/download
--via ssh` kills its scp. The output says what is left: over the contents API
the files copied before the cancel stay and the file being copied was not
written; over scp that file may be cut short.

### When the runtime goes away

On each refresh the tray tells every open file manager whether its runtime
is still a local session (`set_available`); a command that prints
`Session 'NAME' not found` does the same. Without the runtime the banner
says so, waiting commands are dropped, and the remote side (listing, path,
command line, transfer choice, Refresh, Upload, Download) is disabled; the
left pane still works. If the runtime comes back (for example it was only
missing from one refresh), the window lists it again.

### What it leaves behind

- On this computer: only what you download, in the folder you chose. Local
deletes go to the recycle bin. `tray_transfer` is saved in `settings.json`,
and every command adds its usual lines to
`~/.config/colab-cli/history/NAME.jsonl` and `colab.log`. The window writes
no temporary files.
- On the runtime: only what you upload or create. A delete through the
contents API makes the Jupyter server create an empty `.ipynb_checkpoints`
folder in the parent folder (seen live); it is harmless and stays visible,
as hidden files are not hidden here.
- Everything on the runtime is lost when it stops.

### A runtime opened in the Colab web UI

Such a runtime has no local session, so its card has Connect and Stop only.
Connect runs `colab attach --endpoint ID`; the card then becomes a local one
with Log, SSH, Files and Stop, and the file manager works on the notebook's
`/content` (the CLI's commands run in their own kernel, not the notebook's).
Stop on that card stops it in the web UI too.

## Testing

- `tests/test_job_vm.py`: cell markers, the notebook driver with IPython and
Expand Down
Loading