Skip to content

[FEATURE] devc_remote_uri.py — Cursor URI construction for remote devcontainers #153

@gerchowl

Description

@gerchowl

Description

Create scripts/devc_remote_uri.py — a standalone Python module/CLI that builds the Cursor/VS Code nested authority URI for remote devcontainers. Called by devc-remote.sh (sibling sub-issue).

Problem Statement

Part of #70. Opening Cursor/VS Code into a remote devcontainer requires constructing a vscode-remote:// URI with hex-encoded JSON specs. Bash is brittle for JSON serialization and hex encoding — Python handles this cleanly with stdlib only.

Proposed Solution

A Python script with:

  • hex_encode(s: str) -> strs.encode().hex()
  • build_uri(workspace_path, devcontainer_path, ssh_host, container_workspace) -> str — assembles vscode-remote://dev-container+{dc_hex}@ssh-remote+{ssh_host}{container_workspace}
  • CLI interface: devc_remote_uri.py <workspace_path> <ssh_host> <container_workspace> — reads devcontainerPath from args, prints URI to stdout
  • No external dependencies (stdlib only: json, sys, argparse)

URI format

vscode-remote://dev-container+{DC_HEX}@ssh-remote+{SSH_SPEC}/{container_workspace}

Where DC_HEX is the hex-encoded JSON:

{"settingType":"config","workspacePath":"/home/user/repo","devcontainerPath":"/home/user/repo/.devcontainer/devcontainer.json"}

SSH spec — two variants:

  • Simple (host from ~/.ssh/config): @ssh-remote+loginnode
  • Full (hex-encoded JSON): @ssh-remote+{SSH_HEX} where {"hostName":"user@1.2.3.4 -p 22"}

Files

  • Create: scripts/devc_remote_uri.py
  • Create: tests/test_devc_remote_uri.py

Testing Strategy

Pytest unit tests:

  • hex_encode(): known input → exact hex output
  • build_uri(): known inputs → exact URI matching Cursor docs examples
  • CLI: subprocess call with args, verify stdout
  • Edge cases: special chars in paths, spaces in host names
  • Error cases: missing args, empty strings

Verify: uv run pytest tests/test_devc_remote_uri.py -v

Alternatives Considered

  • Pure bash hex encoding (od -A n -t x1 | tr -d '[\n\t ]'): works but fragile across platforms
  • Node.js helper: rejected — Python already available in devcontainer

Impact

  • New file, no changes to existing behavior
  • Backward compatible
  • Standalone module — can be worked in parallel with the sibling bash script sub-issue

Changelog Category

Added

Metadata

Metadata

Assignees

Labels

area:workspaceWorkspace tooling, justfile, templateseffort:smallLess than 1 hourfeatureNew feature or requestsemver:minorNew feature, backward-compatible

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions