data

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package data persists workspace records to disk via WorkspaceStore, using atomic JSON reads/writes keyed by workspace ID plus per-repo lookup.

Index

Constants

View Source
const (
	RuntimeLocalWorktree = "local-worktree"
	RuntimeLocalCheckout = "local-checkout"
	RuntimeLocalDocker   = "local-docker"
	RuntimeCloudSandbox  = "cloud-sandbox"
	DefaultAssistant     = "claude"
)

Runtime constants for workspace execution backends

Variables

This section is empty.

Functions

func NormalizePath added in v0.0.8

func NormalizePath(path string) string

NormalizePath returns a cleaned path with symlinks resolved when possible.

func NormalizeRuntime added in v0.0.5

func NormalizeRuntime(runtime string) string

NormalizeRuntime returns a normalized runtime string

Types

type Project

type Project struct {
	Name       string      `json:"name"`
	Path       string      `json:"path"` // Absolute path to repository
	Workspaces []Workspace `json:"-"`    // Discovered dynamically via git
}

Project represents a registered git repository with its workspaces

func NewProject

func NewProject(path string) *Project

NewProject creates a new Project from a repository path

type Registry

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

Registry manages the projects.json file for persistent project tracking

func NewRegistry

func NewRegistry(path string) *Registry

NewRegistry creates a new registry at the specified path

func (*Registry) AddProject

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

AddProject adds a project path to the registry

func (*Registry) Load

func (r *Registry) Load() ([]string, error)

Load reads the project paths from the registry file

func (*Registry) Projects

func (r *Registry) Projects() ([]string, error)

Projects returns a copy of all registered project paths

func (*Registry) RemoveProject

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

RemoveProject removes a project path from the registry

func (*Registry) Save

func (r *Registry) Save(paths []string) error

Save writes the project paths to the registry file

type ScriptsConfig

type ScriptsConfig struct {
	Setup   string `json:"setup"`
	Run     string `json:"run"`
	Archive string `json:"archive"`
}

ScriptsConfig holds the setup/run/archive script commands

type TabInfo

type TabInfo struct {
	Assistant   string `json:"assistant"`
	Name        string `json:"name"`
	SessionName string `json:"session_name,omitempty"`
	Status      string `json:"status,omitempty"`
	CreatedAt   int64  `json:"created_at,omitempty"`
}

TabInfo stores information about an open tab

type Workspace added in v0.0.5

type Workspace struct {
	// Identity
	Name    string    `json:"name"`
	Created time.Time `json:"created"`

	// Git info
	Branch string `json:"branch"`
	Base   string `json:"base"` // Base ref (e.g., origin/main)
	Repo   string `json:"repo"` // Primary checkout path
	Root   string `json:"root"` // Workspace path

	// Execution
	Runtime string `json:"runtime"` // local-worktree, local-checkout, cloud-sandbox

	// Agent config
	Assistant string `json:"assistant"` // Assistant profile ID (e.g. claude, codex, gemini)

	// Scripts
	Scripts    ScriptsConfig `json:"scripts"`
	ScriptMode string        `json:"script_mode"`

	// Environment
	Env map[string]string `json:"env"`

	// UI state
	OpenTabs       []TabInfo `json:"open_tabs,omitempty"`
	ActiveTabIndex int       `json:"active_tab_index"`

	// Lifecycle
	Archived   bool      `json:"archived"`
	ArchivedAt time.Time `json:"archived_at,omitempty"`
	// contains filtered or unexported fields
}

Workspace represents a workspace with its associated metadata

func NewWorkspace added in v0.0.5

func NewWorkspace(name, branch, base, repo, root string) *Workspace

NewWorkspace creates a new Workspace with the current timestamp and defaults

func (Workspace) ID added in v0.0.5

func (w Workspace) ID() WorkspaceID

ID returns a unique identifier for the workspace based on its repo and root paths

func (Workspace) IsMainBranch added in v0.0.5

func (w Workspace) IsMainBranch() bool

IsMainBranch returns true if this workspace is on main or master branch

func (Workspace) IsPrimaryCheckout added in v0.0.5

func (w Workspace) IsPrimaryCheckout() bool

IsPrimaryCheckout returns true if this is the primary checkout

type WorkspaceID added in v0.0.5

type WorkspaceID string

WorkspaceID is a unique identifier based on repo+root hash

type WorkspaceStore added in v0.0.8

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

WorkspaceStore manages workspace persistence

func NewWorkspaceStore added in v0.0.8

func NewWorkspaceStore(root string) *WorkspaceStore

NewWorkspaceStore creates a new workspace store

func (*WorkspaceStore) ClearDeleting added in v0.0.20

func (s *WorkspaceStore) ClearDeleting(id WorkspaceID) error

ClearDeleting removes the delete tombstone for id. A missing marker is not an error (already cleared, or the delete already removed the whole directory).

func (*WorkspaceStore) Delete added in v0.0.8

func (s *WorkspaceStore) Delete(id WorkspaceID) error

Delete removes a workspace from the store

func (*WorkspaceStore) IsDeleting added in v0.0.20

func (s *WorkspaceStore) IsDeleting(id WorkspaceID) bool

IsDeleting reports whether a delete tombstone exists for id.

func (*WorkspaceStore) List added in v0.0.8

func (s *WorkspaceStore) List() ([]WorkspaceID, error)

List returns all workspace IDs stored in the store

func (*WorkspaceStore) ListByRepo added in v0.0.8

func (s *WorkspaceStore) ListByRepo(repoPath string) ([]*Workspace, error)

ListByRepo returns all workspaces for a given repository path

func (*WorkspaceStore) ListByRepoIncludingArchived added in v0.0.8

func (s *WorkspaceStore) ListByRepoIncludingArchived(repoPath string) ([]*Workspace, error)

func (*WorkspaceStore) Load added in v0.0.8

func (s *WorkspaceStore) Load(id WorkspaceID) (*Workspace, error)

Load loads a workspace by its ID

func (*WorkspaceStore) LoadMetadataFor added in v0.0.8

func (s *WorkspaceStore) LoadMetadataFor(ws *Workspace) (bool, error)

LoadMetadataFor loads stored metadata for a workspace and merges it into the provided workspace. Uses the workspace's computed ID (based on Repo+Root) to find stored metadata. Returns (true, nil) if metadata was found and merged. Returns (false, nil) if no metadata file exists (safe to apply defaults). Returns (false, err) if metadata exists but couldn't be read (don't overwrite).

func (*WorkspaceStore) MarkDeleting added in v0.0.20

func (s *WorkspaceStore) MarkDeleting(id WorkspaceID) error

MarkDeleting writes a durable tombstone for id before destructive delete steps begin. The marker is written crash-safely (temp + fsync + atomic rename) via fsatomic, so an interrupted delete can never leave a torn marker that startup recovery would reject.

func (*WorkspaceStore) Rename added in v0.0.20

func (s *WorkspaceStore) Rename(id WorkspaceID, newName string) error

Rename updates a workspace's human-facing Name only. Repo/Root/Branch and therefore ID() are unchanged, so no tmux session, tag, worktree, or in-memory map keyed on the ID is affected (Tier-1 label rename). The newName is trimmed and validated with the same rule as workspace creation, then the record is saved in place atomically — because Repo/Root are untouched, ws.ID() == id and Save takes its in-place branch (no flock migration, no old-record deletion).

func (*WorkspaceStore) ResolvedDefaultAssistant added in v0.0.14

func (s *WorkspaceStore) ResolvedDefaultAssistant() string

ResolvedDefaultAssistant returns the configured default assistant, falling back to DefaultAssistant if none is set.

func (*WorkspaceStore) Save added in v0.0.8

func (s *WorkspaceStore) Save(ws *Workspace) error

Save saves a workspace to the store using atomic write

func (*WorkspaceStore) SetDefaultAssistant added in v0.0.14

func (s *WorkspaceStore) SetDefaultAssistant(name string)

SetDefaultAssistant updates the assistant used when applying defaults while loading metadata.

func (*WorkspaceStore) SetEnv added in v0.0.20

func (s *WorkspaceStore) SetEnv(id WorkspaceID, env map[string]string) error

SetEnv updates a workspace's environment-variable map and persists it. Like Rename (the same Tier-1 single-field-update shape, in workspace_store.go), it loads the workspace fresh from disk before mutating and saving in place, so a caller holding a possibly-stale in-memory Workspace (e.g. one captured when a dialog opened) cannot clobber a field another in-flight operation changed concurrently in the meantime. Split into its own file to keep workspace_store.go under the repo's 500-line file cap.

Reserved-key exclusion is the caller's responsibility: internal/process already imports internal/data for data.Workspace, so this package importing internal/process back to reuse its reserved-key list would cycle. See process.IsReservedScriptEnvKey.

func (*WorkspaceStore) UpsertFromDiscovery added in v0.0.8

func (s *WorkspaceStore) UpsertFromDiscovery(discovered *Workspace) error

UpsertFromDiscovery merges a discovered workspace into the store. Store metadata wins; discovery updates Repo/Root/Branch (and Name if empty). Archived state is cleared on discovery.

The merge runs as an atomic read-modify-write: the discovered fields are reconciled against the stored metadata while the workspace flock is held across the reload+merge+save, mirroring Update(id, fn). Holding the lock over the whole sequence prevents lost updates when two amux processes rescan the same repo concurrently — without it, each would load->merge->save in turn and silently clobber the other's fields (e.g. OpenTabs, Archived).

Jump to

Keyboard shortcuts

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