v0: colab_drive_auth - automated Drive mount handoff (URL -> consent -> Enter) #3

Closed
opened 2026-11-11 20:18:39 +00:00 by dsh · 1 comment
Owner

Automate the one manual step in the workflow: the Drive OAuth + Enter handoff.

Current manual flow

colab drivemount -s <name> triggers drive_auth_needed; a browser consent page opens (or a URL is logged); the operator clicks the account, grants Drive, closes the tab, and presses Enter in the terminal. Only then does the CLI finish mounting.

Proposed tool: colab_drive_auth(session, project, timeout_s=180)

  1. If /content/drive/MyDrive/<project> already lists → return mounted (idempotent).
  2. Spawn colab drivemount -s <session> under a PTY so prompts are observable and writable.
  3. Parse output for the auth URL (colab log shows drive_auth_needed; the CLI prints the verification URL in the automation output).
  4. Surface the URL twice: xdg-open on t14 and return it to the DSH caller so the Web GUI can show a clickable link (operator may be on another machine).
  5. Wait for consent: poll colab ls -s <session> /content/drive (mount appears once authorized); also watch PTY for an "Enter" prompt.
  6. When mounted (or prompt detected), send \n to the PTY, wait for exit/automation_result, verify the project dir, return mounted + path.
  7. Timeout / abort → kill child, return structured auth_pending with the URL so the caller can retry or hand off.

Security

  • URL is short-lived and user-visible; never log full consent tokens.
  • Tool must not auto-approve: operator clicks in the browser; the tool only automates the terminal side.
  • Never accept credentials in tool args.

Open questions

  • Does the CLI print the URL reliably, or only open the browser? (test both drivemount and exec-driven google.colab.drive.mount)
  • Can we detect "browser tab closed" as the signal instead of polling? (no; mount poll is the reliable signal)
  • Web GUI rendering of links inside tool results — check DSH tool result markdown support.

Acceptance

  • from a fresh T4 session, one tool call reaches a mounted Drive with only the browser consent as human action;
  • second call is a no-op mounted;
  • timeout leaves no wedged drivemount process and no half-mounted state.
Automate the one manual step in the workflow: the Drive OAuth + Enter handoff. ## Current manual flow `colab drivemount -s <name>` triggers `drive_auth_needed`; a browser consent page opens (or a URL is logged); the operator clicks the account, grants Drive, closes the tab, and **presses Enter in the terminal**. Only then does the CLI finish mounting. ## Proposed tool: `colab_drive_auth(session, project, timeout_s=180)` 1. If `/content/drive/MyDrive/<project>` already lists → return `mounted` (idempotent). 2. Spawn `colab drivemount -s <session>` under a **PTY** so prompts are observable and writable. 3. Parse output for the auth URL (`colab log` shows `drive_auth_needed`; the CLI prints the verification URL in the automation output). 4. Surface the URL twice: `xdg-open` on t14 **and** return it to the DSH caller so the Web GUI can show a clickable link (operator may be on another machine). 5. Wait for consent: poll `colab ls -s <session> /content/drive` (mount appears once authorized); also watch PTY for an "Enter" prompt. 6. When mounted (or prompt detected), send `\n` to the PTY, wait for exit/`automation_result`, verify the project dir, return `mounted` + path. 7. Timeout / abort → kill child, return structured `auth_pending` with the URL so the caller can retry or hand off. ## Security - URL is short-lived and user-visible; never log full consent tokens. - Tool must not auto-approve: operator clicks in the browser; the tool only automates the *terminal* side. - Never accept credentials in tool args. ## Open questions - Does the CLI print the URL reliably, or only open the browser? (test both `drivemount` and `exec`-driven `google.colab.drive.mount`) - Can we detect "browser tab closed" as the signal instead of polling? (no; mount poll is the reliable signal) - Web GUI rendering of links inside tool results — check DSH tool result markdown support. ## Acceptance - from a fresh T4 session, one tool call reaches a mounted Drive with only the browser consent as human action; - second call is a no-op `mounted`; - timeout leaves no wedged `drivemount` process and no half-mounted state.
dsh added this to the v0 - CLI wrapper milestone 2026-11-11 20:18:39 +00:00
Author
Owner

Implemented in f414adc (lib/drive.js, test/drive.test.mjs); design corrected in docs/drive-auth.md.

Key finding from the 0.8.0 source: the mount cannot appear before Enter — the CLI waits for the confirmation, then propagates credentials and mounts. The original scenario 4 ("detect the mount, then send Enter") is therefore impossible. The tool now runs a retry loop: surface the URL, wait a short operator grace, write \n, close stdin, poll colab ls, and retry while the operator clicks; the first attempt after consent succeeds.

No PTY: the child is spawned detached so /dev/tty is unavailable and the CLI uses its documented stdin fallback. Timeout returns auth_pending + URL and kills the child. Tests cover instant mount, fail-then-consent-then-mount, timeout, and no wedged child. drive_path = mount dir, project_path = <mount>/MyDrive/<project>.

Not yet verified against a real account (requires the operator's browser click); the fake CLI models the real ordering.

Implemented in `f414adc` (`lib/drive.js`, `test/drive.test.mjs`); design corrected in `docs/drive-auth.md`. Key finding from the 0.8.0 source: **the mount cannot appear before Enter** — the CLI waits for the confirmation, then propagates credentials and mounts. The original scenario 4 ("detect the mount, then send Enter") is therefore impossible. The tool now runs a retry loop: surface the URL, wait a short operator grace, write `\n`, close stdin, poll `colab ls`, and retry while the operator clicks; the first attempt after consent succeeds. No PTY: the child is spawned detached so `/dev/tty` is unavailable and the CLI uses its documented stdin fallback. Timeout returns `auth_pending` + URL and kills the child. Tests cover instant mount, fail-then-consent-then-mount, timeout, and no wedged child. `drive_path` = mount dir, `project_path` = `<mount>/MyDrive/<project>`. Not yet verified against a real account (requires the operator's browser click); the fake CLI models the real ordering.
dsh closed this issue 2026-11-11 20:53:49 +00:00
Sign in to join this conversation.
No description provided.