Skip to content

Conversation

@rgarcia
Copy link
Contributor

@rgarcia rgarcia commented Dec 22, 2025

Summary

Add manually-maintained cp functionality to the Go SDK for copying files to/from running VM instances.

Usage

import "github.com/onkernel/hypeman-go/lib"

// Copy file to instance
err := lib.CpToInstance(ctx, client, instanceID, localPath, guestPath, lib.CpOptions{
    Recursive: true,
    Archive:   true,  // preserve UID/GID
})

// Copy from instance
err := lib.CpFromInstance(ctx, client, instanceID, guestPath, localPath, lib.CpOptions{
    FollowLinks: true,
})

Features

  • CpToInstance: Copy local file/directory to instance
  • CpFromInstance: Copy file/directory from instance to local
  • WebSocket-based streaming with JSON control messages
  • Supports files and recursive directory operations
  • Handles symlinks, permissions, and modification times
  • Chunked binary data transfer for efficient streaming

Implementation

Located in lib/cp.go following the SDK's convention for custom extensions that won't conflict with auto-generated code.

Dependencies

Requires corresponding API server changes: onkernel/hypeman#45


Note

Adds high-level file transfer and a new filesystem stat API.

  • New lib package: CpToInstance/CpFromInstance stream files/dirs over WebSocket with progress callbacks, archive UID/GID preservation, link following, cycle detection, and path/symlink sanitization; mockable via WsConn/WsDialer (lib/ws_connector.go)
  • New API: GET /instances/{id}/stat via client.Instances.Stat(...) with InstanceStatParams and PathInfo response
  • Model updates: InstanceNewParams gains devices field
  • Tests added for cp flows and Instances.Stat
  • Deps: add github.com/gorilla/websocket and github.com/stretchr/testify; docs (api.md) and stats updated

Written by Cursor Bugbot for commit 00c6817. This will update automatically on new commits. Configure here.

@rgarcia rgarcia requested a review from sjmiller609 December 23, 2025 00:34
Cherry-picked from stainless-sdks/hypeman-go preview/feature/hypeman-cp.

- Add InstanceService.Stat() method
- Add PathInfo response type with Error field for stat failures
- Add InstanceStatParams query parameters
Add file copy functionality to the SDK for copying files to/from
running instances via WebSocket streaming.

Features:
- CpToInstance: Copy local file/directory to instance
- CpFromInstance: Copy file/directory from instance to local
- WebSocket-based streaming with JSON control messages
- Recursive directory operations with cycle detection
- Archive mode preserving UID/GID/permissions
- FollowLinks option for symlink handling
- Progress callbacks via CpCallbacks
- Path traversal protection

Includes comprehensive unit tests with mock WebSocket.
@rgarcia rgarcia merged commit dcbfaa1 into main Dec 23, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants