workspace

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package workspace identifies the filesystem root owned by a coding session and persists explicit user trust outside that root.

Index

Constants

View Source
const (
	// StoreSchema identifies the durable workspace store format.
	StoreSchema = "pips.workspaces/v1alpha1"
)

Variables

View Source
var (
	// ErrInsecurePermissions means a workspace store path can be accessed by
	// users other than its owner.
	ErrInsecurePermissions = errors.New("coding workspace: insecure store permissions")
	// ErrUnsupportedStoreSchema means the store uses an unknown schema.
	ErrUnsupportedStoreSchema = errors.New("coding workspace: unsupported store schema")
	// ErrStoreTooLarge means the store exceeds its bounded input size.
	ErrStoreTooLarge = errors.New("coding workspace: store too large")
	// ErrWorkspaceUnknown means a permission was recorded before its Workspace
	// was explicitly trusted.
	ErrWorkspaceUnknown = errors.New("coding workspace: workspace is not trusted")
)
View Source
var (
	// ErrInvalid means a workspace path or identity is unusable.
	ErrInvalid = errors.New("coding workspace: invalid workspace")
	// ErrInvalidPath means a workspace-relative path is malformed.
	ErrInvalidPath = errors.New("coding workspace: invalid path")
	// ErrOutsideRoot means a path attempts to leave the workspace root.
	ErrOutsideRoot = errors.New("coding workspace: path outside root")
	// ErrSymlink means a mutation path traverses a symbolic link.
	ErrSymlink = errors.New("coding workspace: symbolic link not allowed")
	// ErrUnsupportedType means a path is not a regular file or directory.
	ErrUnsupportedType = errors.New("coding workspace: unsupported file type")
	// ErrChanged means a filesystem object changed during a guarded operation.
	ErrChanged = errors.New("coding workspace: path changed")
	// ErrClosed means an operation used a closed workspace tree.
	ErrClosed = errors.New("coding workspace: tree closed")
	// ErrUnsupportedPlatform means the current platform cannot supply the
	// filesystem identity required for a safe trust decision.
	ErrUnsupportedPlatform = errors.New("coding workspace: unsupported platform")
)

Functions

func NormalizePath

func NormalizePath(name string, allowRoot bool) (string, error)

NormalizePath validates and normalizes a slash-separated, relative path. The root path "." is accepted only when allowRoot is true.

Types

type Identity

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

Identity binds trust to both a canonical path and the filesystem object currently found there.

func (Identity) Device

func (i Identity) Device() uint64

Device returns the platform device number included in the identity.

func (Identity) Inode

func (i Identity) Inode() uint64

Inode returns the platform inode number included in the identity.

func (Identity) Key

func (i Identity) Key() string

Key returns a versioned, opaque key for persistence in a workspace store.

func (Identity) Path

func (i Identity) Path() string

Path returns the canonical absolute path included in the identity.

type Mutation

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

Mutation is active only for the duration of a Tree.Mutate callback.

func (*Mutation) OpenDir

func (m *Mutation) OpenDir(name string) (*MutationDir, error)

OpenDir opens a stable, non-symlink directory beneath the workspace.

type MutationDir

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

MutationDir is a stable directory handle used by a guarded mutation.

func (*MutationDir) Close

func (d *MutationDir) Close() error

Close releases the directory handle. Repeated calls are safe.

func (d *MutationDir) Link(oldName, newName string) error

Link creates a hard link between two direct children. It fails when the new name already exists, which makes it suitable for guarded backup creation.

func (*MutationDir) Lstat

func (d *MutationDir) Lstat(name string) (fs.FileInfo, error)

Lstat inspects a direct child without following a final symbolic link.

func (*MutationDir) Mkdir

func (d *MutationDir) Mkdir(name string, perm fs.FileMode) error

Mkdir creates one direct child directory without following symbolic links.

func (*MutationDir) Open

func (d *MutationDir) Open(name string) (*os.File, error)

Open opens a direct child for guarded inspection.

func (*MutationDir) OpenFile

func (d *MutationDir) OpenFile(name string, flag int, perm fs.FileMode) (*os.File, error)

OpenFile opens a direct child using the supplied flags and permission bits.

func (*MutationDir) Path

func (d *MutationDir) Path() string

Path returns the normalized workspace-relative directory path.

func (*MutationDir) Remove

func (d *MutationDir) Remove(name string) error

Remove removes one direct child.

func (*MutationDir) Rename

func (d *MutationDir) Rename(oldName, newName string) error

Rename atomically renames one direct child to another in the same directory.

func (*MutationDir) Sync

func (d *MutationDir) Sync() error

Sync asks the operating system to persist directory metadata.

type Permission

type Permission struct {
	Kind        PermissionKind     `json:"kind"`
	ResourceID  string             `json:"resource_id"`
	Fingerprint string             `json:"fingerprint"`
	Decision    PermissionDecision `json:"decision"`
	DecidedAt   time.Time          `json:"decided_at"`
}

Permission binds one local decision to a normalized resource fingerprint.

type PermissionDecision

type PermissionDecision string

PermissionDecision is an explicit local allow or deny decision.

const (
	PermissionAllow PermissionDecision = "allow"
	PermissionDeny  PermissionDecision = "deny"
)

Supported permission decisions.

type PermissionKind

type PermissionKind string

PermissionKind identifies a typed workspace-scoped authority.

const (
	PermissionMCPServer PermissionKind = "mcp_server"
)

Supported permission kinds.

type Store

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

Store records workspace-scoped user decisions outside project directories. The file is read lazily and mutations are serialized per Store instance.

func NewStore

func NewStore(path string) *Store

NewStore returns a workspace store backed by path.

func (*Store) IsTrusted

func (s *Store) IsTrusted(identity Identity) (bool, error)

IsTrusted reports whether identity is present and still matches its stored canonical path and filesystem identity.

func (*Store) Path

func (s *Store) Path() string

Path returns the workspace store path.

func (*Store) Permission

func (s *Store) Permission(
	identity Identity,
	kind PermissionKind,
	resourceID string,
) (Permission, bool, error)

Permission returns one typed decision for identity and resourceID.

func (*Store) SetPermission

func (s *Store) SetPermission(identity Identity, permission Permission) error

SetPermission records a typed decision for an already trusted Workspace.

func (*Store) Trust

func (s *Store) Trust(identity Identity) error

Trust records an explicit trust decision for identity.

type Tree

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

Tree owns confined filesystem access for a Workspace. It is safe for concurrent reads; mutations submitted through Mutate are serialized.

func OpenTree

func OpenTree(workspace Workspace) (*Tree, error)

OpenTree opens confined filesystem access for workspace and verifies that its canonical directory identity has not changed since Workspace was opened.

func (*Tree) Close

func (t *Tree) Close() error

Close releases the root handle. Repeated calls are safe.

func (*Tree) FileSystem

func (t *Tree) FileSystem() fs.FS

FileSystem returns a confined read-only fs.FS view. Operations continue to honor Tree closure and path validation.

func (*Tree) InspectAddPath

func (t *Tree) InspectAddPath(name string) (string, fs.FileInfo, []string, error)

InspectAddPath validates an Add target without requiring its parent tree to exist. It returns the exact missing parent directories in shallow-to-deep order. Existing components may not be symbolic links and existing parents must be directories.

func (*Tree) InspectMutationPath

func (t *Tree) InspectMutationPath(name string) (string, fs.FileInfo, error)

InspectMutationPath validates a file mutation target. Existing path components may not be symbolic links; parents must be directories. A nil FileInfo means the final path does not exist.

func (*Tree) InspectRegularPath

func (t *Tree) InspectRegularPath(name string) (string, fs.FileInfo, error)

InspectRegularPath validates an existing regular file path without following symbolic links in any component.

func (*Tree) Lstat

func (t *Tree) Lstat(name string) (fs.FileInfo, error)

Lstat returns information about name without following its final symbolic link.

func (*Tree) Mutate

func (t *Tree) Mutate(ctx context.Context, fn func(*Mutation) error) error

Mutate serializes a guarded filesystem mutation. The callback may open stable directory handles and operate on base names through Mutation.

func (*Tree) Open

func (t *Tree) Open(name string) (*os.File, error)

Open opens name through the confined root. Internal symbolic links are allowed only when their targets remain inside the root.

func (*Tree) Path

func (t *Tree) Path() string

Path returns the canonical workspace path for display and process-level adapters. File operations must use Tree methods instead.

func (*Tree) ReadDir

func (t *Tree) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir reads one directory without recursively following its entries.

func (t *Tree) Readlink(name string) (string, error)

Readlink returns the unexpanded target of a workspace symbolic link.

func (*Tree) Stat

func (t *Tree) Stat(name string) (fs.FileInfo, error)

Stat returns information about name, following internal symbolic links.

type Workspace

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

Workspace is a canonical directory and its filesystem identity.

func Open

func Open(path string) (Workspace, error)

Open canonicalizes path and verifies that it names a directory with a platform filesystem identity.

func (Workspace) Identity

func (w Workspace) Identity() Identity

Identity returns the canonical filesystem identity used by the workspace store.

func (Workspace) Root

func (w Workspace) Root() string

Root returns the canonical absolute workspace path.

Jump to

Keyboard shortcuts

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