workspace

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package workspace owns the directories a coding session runs in: the project roots a user registers, and the scratch directories the server generates for standalone chats. Path cleaning lives here alongside the scratch guard that depends on it, because that guard is the only thing standing between forged session metadata and a recursive delete of a real project.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalid = errors.New("workspace: invalid workspace")

ErrInvalid reports a path that cannot be used as a workspace root.

Functions

func Clean

func Clean(path string) (string, error)

Clean resolves a path to an absolute, symlink-free, lexically clean form. Resolution failures are tolerated so a path that does not exist yet still normalizes; callers that require an existing directory use Validate.

func EnsureDirectories

func EnsureDirectories(path string) error

EnsureDirectories creates the fixed layout every scratch workspace has. It is idempotent so a restored session can repair a partially deleted tree.

func Validate

func Validate(path string) (string, error)

Validate cleans path and proves it is an existing directory.

Types

type Registry

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

Registry is the durable list of project roots shown in the sidebar. It is persisted separately from sessions so an empty project can stay registered.

Lock ordering: a caller that owns both a session lock and this registry must always take the session lock first. Registry never calls back into session code, which keeps that ordering trivially satisfiable.

func NewRegistry

func NewRegistry(indexPath string) (*Registry, error)

NewRegistry restores the registry from indexPath. Entries whose paths no longer normalize are dropped rather than failing startup, matching how the sidebar has always tolerated a project that moved.

func (*Registry) Discard

func (r *Registry) Discard(path string)

Discard undoes an Ensure that was never persisted. It is only correct for a path Ensure reported as newly added.

func (*Registry) Ensure

func (r *Registry) Ensure(path string, addedAt time.Time) (Summary, bool)

Ensure adds a project root in memory without persisting it, reporting whether this call was the one that added it. Creating a session registers its workspace and writes both indexes as one unit, so the caller flushes with Save and undoes a failure with Discard.

func (*Registry) List

func (r *Registry) List() []Summary

List returns registered projects newest-added first, including projects that currently have no conversations.

func (*Registry) Register

func (r *Registry) Register(path string) (Summary, error)

Register validates a project root and persists it. Registering a path that is already present is a no-op that returns the existing entry.

func (*Registry) Remove

func (r *Registry) Remove(path string) error

Remove drops a project from the sidebar. Transcripts and workspace files are intentionally retained; registering the directory again restores the view.

func (*Registry) Save

func (r *Registry) Save() error

Save flushes the registry to disk.

type Scratch

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

Scratch generates and reclaims the server-owned directories that standalone chat sessions run in. These are not registered projects: they are never listed in the sidebar and are created and destroyed with their session.

func NewScratch

func NewScratch(dataDir string) *Scratch

NewScratch returns the scratch manager rooted under the product data directory. Every generated path lives exactly two levels below root.

func (*Scratch) Create

func (s *Scratch) Create(sessionID string, startedAt time.Time) (string, error)

Create makes the directory tree for one session and returns its cleaned path. A partially created tree is removed rather than left behind.

func (*Scratch) Remove

func (s *Scratch) Remove(path string) error

Remove deletes one scratch directory after proving it is managed storage.

func (*Scratch) Validate

func (s *Scratch) Validate(path string) (string, error)

Validate proves that path is one generated session directory exactly two levels below the managed root. This guard is required before any recursive cleanup, so an external project can never be removed through forged session metadata.

type Summary

type Summary struct {
	Path    string    `json:"path"`
	Name    string    `json:"name"`
	AddedAt time.Time `json:"addedAt"`
}

Summary is a registered project root as the browser sees it.

Jump to

Keyboard shortcuts

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