workspace

package
v0.43.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrObjectNotFound = errors.New("s3: object not found")

ErrObjectNotFound is returned by DownloadFile when the requested key does not exist. Sentinel so callers can distinguish missing-but-OK from a real transport / auth failure.

View Source
var TempDirBase = ""

TempDirBase is the parent under which per-session work directories are created. Tests override it via t.TempDir(); production uses os.TempDir().

Functions

func Teardown

func Teardown(ctx context.Context, ws *Workspace, store *S3Store) error

Teardown uploads the per-session jsonl, then packages ClaudeDir as a tar.gz (excluding this session's subtree) and uploads it. Finally, the temp dir is removed. Upload failures are logged but do not propagate — a flaky upload must not block the caller's turn response. TempDir is always removed.

Types

type S3Config

type S3Config struct {
	Endpoint        string
	Region          string
	Bucket          string
	AccessKeyID     string
	SecretAccessKey string
	PathStyle       bool
}

S3Config carries the S3-compatible endpoint configuration.

Endpoint is a full URL with scheme — http://... or https://... — so operators can use the same form they paste into rclone / aws cli. Trailing path segments are not supported. PathStyle must be true for MinIO and most on-prem S3 implementations; false for AWS S3 (virtual-hosted-style is required) and most public clouds.

type S3Store

type S3Store struct {
	// contains filtered or unexported fields
}

S3Store is the workspace persistence backend. One instance is held by the server and shared across all turns.

func NewS3Store

func NewS3Store(cfg S3Config) (*S3Store, error)

func (*S3Store) DownloadFile added in v0.43.0

func (s *S3Store) DownloadFile(ctx context.Context, key, destPath string) error

DownloadFile fetches the object at key and writes it verbatim to destPath (creating parent directories). Returns ErrObjectNotFound if the object does not exist; the caller can ignore that to mean "no prior state".

func (*S3Store) DownloadTarGz

func (s *S3Store) DownloadTarGz(ctx context.Context, key, destDir string) error

DownloadTarGz streams the object at key, gunzip-untars it into destDir. Returns nil if the object does not exist (treated as empty workspace). Tar entries with paths escaping destDir are skipped.

func (*S3Store) UploadFile added in v0.43.0

func (s *S3Store) UploadFile(ctx context.Context, srcPath, key string) error

UploadFile reads srcPath in full and PUTs it verbatim at key. ContentLength is set so the SDK issues a single signed PUT.

func (*S3Store) UploadTarGz

func (s *S3Store) UploadTarGz(ctx context.Context, srcDir, key string, excludeRel func(rel string) bool) error

UploadTarGz walks srcDir, packages it as a tar.gz, and PUTs it to the given key. The tarball is buffered in memory so the SDK can issue a single PUT request (avoids multipart for the typical small workspace payload). Symlinks are skipped. File modes are normalized to 0644 (regular) / 0755 (dir). Failures during walk are logged and the offending file is skipped; the upload still completes with whatever was packed.

excludeRel, if non-nil, returns true for any rel-path under srcDir that should be omitted from the tarball. Used by callers that store some subdirectories as separate S3 objects (per-session jsonl).

type Workspace

type Workspace struct {
	WorkspaceID string
	SessionID   string

	TempDir    string // root: /tmp/cc-broker/sess_<sessionID>
	ClaudeDir  string // <TempDir>/claude-config — CLAUDE_CONFIG_DIR
	ProjectDir string // <TempDir>/project       — CLI cwd (kept empty; only used for proj_hash)
	MemoryDir  string // <ClaudeDir>/projects/ws_<wid>/memory — auto-memory override
}

Workspace is the ephemeral local filesystem view a single CC turn operates in.

func Setup

func Setup(ctx context.Context, workspaceID, sessionID string, store *S3Store) (*Workspace, error)

Setup creates the temp directory tree, downloads the workspace's claude-home tarball, and downloads the per-session jsonl. The returned Workspace must be passed to Teardown so the temp directory is removed and state is uploaded back.

On any error after the directory tree is created, Setup removes TempDir before returning, so callers do not leak per-session directories.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL