projectdir

package
v1.17.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package projectdir resolves project-specific state directories under $XDG_STATE_HOME/sidecar/projects/<slug>/ (defaults to ~/.local/state/sidecar/projects/<slug>/). Each project root gets a unique slug-named directory containing a meta.json that maps back to the original project path.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lookup added in v0.93.0

func Lookup(projectRoot string) (string, bool)

Lookup returns the already-registered data directory for a project root without creating anything. Diagnostics use it: a function whose job is to report what this process will write to must not itself write.

func LookupAll added in v1.0.3

func LookupAll(projectRoots []string) map[string]string

LookupAll resolves many project roots in one pass over projects/.

Lookup rescans and re-reads every registered project's meta.json on each call, so resolving N roots with it costs N full scans — and a long-lived install accumulates hundreds of registered projects. Callers that need the whole configured set at once use this instead: one ReadDir, one meta.json read per candidate, regardless of how many roots are asked for.

Roots with no registered directory are absent from the result rather than mapped to an empty string, so a caller can tell "never registered" from "registered at the empty path".

func LookupAllWithBase added in v1.0.3

func LookupAllWithBase(base string, projectRoots []string) map[string]string

LookupAllWithBase is the testable form of LookupAll. base is the Sidecar state directory containing projects/.

func LookupWorktree added in v0.94.0

func LookupWorktree(projectRoot, worktreePath string) (string, bool)

LookupWorktree returns the already-registered data directory for worktreePath without creating or migrating state. It is intended for read-only inventory consumers such as diagnostics and the cross-project overview.

func LookupWorktreeWithBase added in v1.0.0

func LookupWorktreeWithBase(base, projectRoot, worktreePath string) (string, bool)

LookupWorktreeWithBase is the read-only, testable form of LookupWorktree. base is the Sidecar state directory containing projects/.

func Resolve

func Resolve(projectRoot string) (string, error)

Resolve returns the data directory for the given project root path. It creates the directory (with meta.json) if it does not already exist. On subsequent calls with the same projectRoot, the existing directory is returned.

func ResolveWithBase

func ResolveWithBase(base, projectRoot string) (string, error)

ResolveWithBase is the exported, testable form of Resolve. base overrides the state directory (e.g. a temp dir in tests).

func WorktreeDir

func WorktreeDir(projectRoot, worktreePath string) (string, error)

WorktreeDir returns the worktree-specific data directory for a project. The directory is created if it does not exist.

func WorktreeDirContext added in v0.94.0

func WorktreeDirContext(ctx context.Context, projectRoot, worktreePath string) (string, error)

WorktreeDirContext resolves worktree state while allowing legacy Git inventory to be cancelled with its owning lifecycle operation.

func WorktreeDirWithBase

func WorktreeDirWithBase(base, projectRoot, worktreePath string) (string, error)

WorktreeDirWithBase is the exported, testable form of WorktreeDir. base overrides the state directory (e.g. a temp dir in tests).

func WorktreeKey added in v0.94.0

func WorktreeKey(worktreePath string) (string, error)

WorktreeKey is stable across restarts and independent of presentation names.

Types

type EquivalentProject added in v1.15.0

type EquivalentProject struct {
	// Dir is the project's state directory.
	Dir string
	// Registered is the registered spelling while it still names the root,
	// otherwise the pinned root. Callers that go
	// on to Resolve must pass it, not their own spelling, or Resolve creates a
	// second project.
	Registered string
}

EquivalentProject is one registry entry for a directory.

func ListRegistered added in v1.16.0

func ListRegistered() ([]EquivalentProject, error)

ListRegistered inventories every project manifest without creating state. Unlike best-effort lookups, destructive callers need to know when inventory is incomplete: corrupt or unreadable registrations must not disappear silently.

func ListRegisteredWithBase added in v1.16.0

func ListRegisteredWithBase(base string) ([]EquivalentProject, error)

ListRegisteredWithBase is the read-only form for an explicit state directory.

func LookupEquivalent added in v1.15.0

func LookupEquivalent(projectRoot string) []EquivalentProject

LookupEquivalent finds every registry entry for projectRoot, including ones registered under another spelling of the same directory: a symlinked checkout, or macOS's /var for /private/var. It never creates anything.

All of them, not the first: one checkout registered under two spellings has two manifests, and a caller that picked one by directory order could miss the records it was looking for.

type WorktreeIndex added in v1.16.0

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

WorktreeIndex answers LookupWorktreeWithBase for many worktrees from one read of the state tree. A single lookup rescans every project's meta.json and then every worktree record of the matching project, so a caller that looks up each of a few hundred worktrees re-read the same files tens of thousands of times. The index memoizes both scans per call site and returns exactly the directory the uncached lookup returns: project resolution keeps findByMeta's root identity and exact-spelling priority, and the first record in directory order that matches a path wins, as it does in the linear scan.

An index is a snapshot. Build one per catalog or command, never hold one across invocations; records written after first use are not seen. It is safe for concurrent use.

func NewStateWorktreeIndex added in v1.16.0

func NewStateWorktreeIndex() *WorktreeIndex

NewStateWorktreeIndex indexes the configured state directory, the base LookupWorktree reads.

func NewWorktreeIndex added in v1.16.0

func NewWorktreeIndex(base string) *WorktreeIndex

NewWorktreeIndex returns an empty index over the state directory base.

func (*WorktreeIndex) Lookup added in v1.16.0

func (x *WorktreeIndex) Lookup(projectRoot, worktreePath string) (string, bool)

Lookup is LookupWorktreeWithBase(index base, projectRoot, worktreePath).

Jump to

Keyboard shortcuts

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