managedtarget

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 15 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 managedtarget resolves a caller-facing shell name into one host-shaped Sidecar-owned target. Resolve is state-free: callers supply the candidates they are authorized to expose. List/Candidates load that universe from a Sidecar state directory so the CLI and the TUI cannot disagree.

Index

Constants

View Source
const (
	KindShell    = "shell"
	KindWorktree = "worktree"
)

Variables

This section is empty.

Functions

func DiscoverWorktreeRoots added in v1.16.0

func DiscoverWorktreeRoots(ctx context.Context, proj Project) []string

DiscoverWorktreeRoots is every non-bare worktree Git lists for proj, or nil when Git cannot answer.

func IsManagedSession added in v1.16.0

func IsManagedSession(value string) bool

IsManagedSession reports the reserved session-name shapes. Missing values in these namespaces must never be reinterpreted as display names.

func ObserveWorktreeOrphans added in v1.15.0

func ObserveWorktreeOrphans(ctx context.Context, projects []Project, opts ObserveOptions) shellliveness.OrphanObservation

ObserveWorktreeOrphans gathers the evidence for projects. A tmux server with no sessions is an empty listing, not a failure: `no server running` means there is nothing live to be orphaned.

Git is asked only when there is something to judge. Every verdict needs a directory that is gone, so a pass with no live worktree session in a missing directory (and no caller asking for root verdicts) never spawns git at all. That keeps the common `agent list` free of a git process per project.

func SessionSelector added in v1.16.0

func SessionSelector(session string) string

SessionSelector protects a literal session name, including one that starts with the human display-name selector prefix.

func ValidateCaller added in v1.16.0

func ValidateCaller(e CallerEvidence) error

ValidateCaller refuses contradictions, never chooses a replacement target. A live pane directory verifies a deliberate cd, even outside the owning project. Without live directory evidence, only a known registered cwd can contradict the stored origin; arbitrary directories claim no other shell.

func WorktreeOrphans added in v1.15.0

func WorktreeOrphans(ctx context.Context, projects []Project, opts ObserveOptions) shellliveness.OrphanPlan

WorktreeOrphans is ObserveWorktreeOrphans followed by the decision.

Types

type CallerEvidence added in v1.16.0

type CallerEvidence struct {
	ClaimedSession, PaneSession, Cwd, PaneWorkDir, OriginWorkDir, RegisteredCwdRoot string
	OriginVerified                                                                  bool
}

CallerEvidence is independently collected context for an implicit selector. Paths are canonicalized by the host adapter. A shell's owning project does not change when its live pane changes directory.

type DiscoverFunc added in v1.16.0

type DiscoverFunc func(ctx context.Context, proj Project) []string

DiscoverFunc lists the Git worktree roots of one project, as DiscoverWorktreeRoots does. A caller that scans many times over one observation can supply a memoized one.

type Error

type Error struct {
	Kind    ErrorKind
	Message string
	// ByName distinguishes display-name ambiguity from a session identity
	// collision, so callers cannot hide it using implicit project context.
	ByName bool
}

func (*Error) Error

func (e *Error) Error() string

type ErrorKind

type ErrorKind string
const (
	NotFound  ErrorKind = "not_found"
	Ambiguous ErrorKind = "ambiguous"
)
const CallerConflict ErrorKind = "caller_conflict"

type ObserveOptions added in v1.15.0

type ObserveOptions struct {
	// WantRoots asks for root verdicts even when no session is suspect, for a
	// caller (`shell list`) that marks shells rather than sessions.
	WantRoots bool
}

ObserveOptions says how much evidence a caller needs.

type Project added in v1.15.0

type Project struct {
	Key, Path, Dir string
	Worktrees      []string
}

Project is the registered-project facts the candidate scan needs. Callers that already loaded the registry (the CLI) pass this; List loads it from stateDir.

func LoadProjects added in v1.15.0

func LoadProjects(stateDir string) ([]Project, error)

LoadProjects reads every registered project under stateDir/projects.

type Query

type Query struct{ Host, Project, Namespace, Value string }

type Target

type Target struct {
	Host, Project, ProjectRoot, Kind, Session, Name, Namespace, WorkDir, WorktreeRoot, ManifestPath string
	Priority                                                                                        int
}

func Candidates added in v1.15.0

func Candidates(ctx context.Context, stateDir string, projects []Project) ([]Target, error)

Candidates is every shell and worktree session the given projects own, each worktree root listed exactly once.

Shell records belong to the project whose manifest holds them. Worktree roots do not, because several registered projects can see the same directory. Each root therefore has one owner, chosen by how strongly a project claims it: created worktree, then the project's own checkout, then the first project that merely discovered it through Git.

func CandidatesWith added in v1.16.0

func CandidatesWith(ctx context.Context, stateDir string, projects []Project, discover DiscoverFunc) ([]Target, error)

CandidatesWith is Candidates with the Git worktree discovery supplied by the caller; nil means DiscoverWorktreeRoots. Manifests and registered worktrees are always read fresh.

func List added in v1.15.0

func List(ctx context.Context, stateDir, projectKey string) ([]Target, error)

List is every managed shell and worktree in stateDir, or only projectKey when that is set. Empty projectKey means every registered project. This is the universe agent list and agent broadcast share.

func Resolve

func Resolve(candidates []Target, q Query) (Target, error)

Resolve prefers exact session identities. Ordinary bare values may fall back to a unique display name; managed session-shaped values and session: selectors never do. name: selects a display name explicitly, including session-shaped names. Every filter is exact; an empty field leaves that axis unscoped.

Jump to

Keyboard shortcuts

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