shellstate

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 11 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 shellstate owns validation and persistence of Sidecar shell display names. It is deliberately independent of both the TUI and CLI transports.

Index

Constants

View Source
const (
	NameEnv    = "SIDECAR_SHELL_NAME"
	SessionEnv = "SIDECAR_SHELL"
)

NameEnv carries the current display name into the shell's environment, and SessionEnv the tmux session that owns it. An agent that can read its own shell name can tell a default ("Shell 9") from a real one, which is what makes the rename instruction actionable rather than a rule to remember.

View Source
const MaxNameBytes = 50
View Source
const NamingInstruction = "This terminal is a Sidecar project shell. Learn its display name from $" + NameEnv +
	" as a cue (it may be empty on older shells, or lag after a rename in this process), or run " +
	"`sidecar shell name` for the authoritative name from Sidecar's manifest. \"Shell 3\" is the unset default; " +
	"a previous task's name is equally stale. Keep the name aligned with your current task: at the start of work " +
	"and whenever context changes materially, if the name does not describe what you are doing now, run " +
	"`sidecar shell rename \"short context\"`. Update at meaningful boundaries, not every sub-step. Prefer the " +
	"outcome (\"shell rename implementation\") over the model or a transient action (\"Codex running tests\"). " +
	"These commands act only on the current Sidecar shell; never edit shells.json or rename tmux sessions directly."

NamingInstruction is the canonical guidance for keeping a shell's display name useful. It lives here, next to the rules it describes, so every delivery channel — AGENTS.md, a harness system-prompt append, help text — quotes one source instead of drifting copies.

The trigger is "name does not describe current work," not only the generated "Shell N" default — a leftover previous-task name is equally stale.

Variables

View Source
var ErrShellChanged = errors.New("shell entry was replaced since it was observed")

ErrShellChanged reports that the entry on disk is not the one the caller looked at, so the removal was refused.

Functions

func AddAtPath added in v1.0.0

func AddAtPath(path string, def Definition) error

AddAtPath records one shell definition with the same locked, atomic read-before-write semantics used by rename. It is the state-free persistence boundary used by project and cross-project shell hosts.

func IsValidation

func IsValidation(err error) bool

func NormalizeName

func NormalizeName(name string) (string, error)

func RemoveAtPath added in v1.0.0

func RemoveAtPath(path string, id Identity) error

RemoveAtPath forgets one exact shell identity. A missing entry is already the requested state and therefore succeeds.

func RemoveIfUnchangedAtPath added in v1.0.0

func RemoveIfUnchangedAtPath(path string, id Identity, observedAt time.Time) error

RemoveIfUnchangedAtPath forgets one shell only when the entry on disk is still the incarnation the caller observed.

An auto-close decides a shell is dead, and then takes a moment to confirm it. A shell can be created under the same tmux name inside that moment — the global browser's create writes a fresh definition — and deleting the entry then would delete a live shell's identity (td-6a4100). The comparison runs inside the same exclusive lock the creating write takes, so the two orderings are the only two possible and both are correct: create-then-remove is refused, remove-then-create leaves the new entry alone.

A zero observedAt means the caller has no incarnation to check and accepts an unconditional removal.

Types

type Definition

type Definition struct {
	TmuxName    string `json:"tmuxName"`
	DisplayName string `json:"displayName"`
	// Namespace is the resolved tmux socket path. Empty identifies a legacy
	// entry that a headless rename must never claim as a side effect.
	Namespace string    `json:"namespace,omitempty"`
	CreatedAt time.Time `json:"createdAt"`
	AgentType string    `json:"agentType,omitempty"`
	SkipPerms bool      `json:"skipPerms,omitempty"`
	// WorkDir is the parent worktree path this shell was created in. Empty on
	// pre-td-4819be manifests; callers infer or treat empty as current workDir.
	WorkDir string `json:"workDir,omitempty"`
}

Definition contains all information needed to recreate a shell session.

func ListAtPath added in v1.0.0

func ListAtPath(path string) ([]Definition, error)

ListAtPath returns every shell definition recorded in the manifest at path.

It exists so callers that need to decide *which* shells to act on — the worktree delete, which must forget the shells rooted in the directory it is about to remove — can read the manifest through this package instead of unmarshalling shells.json themselves. A missing manifest is an empty project, not an error.

The result is a copy; mutating it does not affect the file. Removal is still one exact Identity at a time, so a caller that lists and then removes must tolerate the manifest changing in between (RemoveAtPath treats an entry that is already gone as success).

type Error

type Error struct {
	Kind ErrorKind
	Msg  string
	Err  error
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ErrorKind

type ErrorKind string
const (
	KindValidation ErrorKind = "validation"
	KindNotFound   ErrorKind = "not_found"
	KindAmbiguous  ErrorKind = "ambiguous"
	KindState      ErrorKind = "state"
)

type Identity added in v0.97.0

type Identity struct {
	TmuxName  string
	Namespace string
}

type LookupResult added in v0.97.0

type LookupResult struct {
	Shell string `json:"shell"`
	Name  string `json:"name"`
}

func LookupCurrent added in v0.97.0

func LookupCurrent(stateDir string, id Identity) (LookupResult, error)

LookupCurrent returns the display name of the current Sidecar project shell from the registered manifest. It does not create state or depend on process environment cues, so it works for shells created before SIDECAR_SHELL_NAME injection existed.

type OriginInfo added in v1.0.0

type OriginInfo struct {
	TmuxName    string `json:"tmuxName"`
	Namespace   string `json:"namespace"`
	ProjectKey  string `json:"projectKey"`
	WorkDir     string `json:"workDir"`
	DisplayName string `json:"displayName"`
}

func LookupOrigin added in v1.0.0

func LookupOrigin(stateDir string, id Identity) (OriginInfo, error)

LookupOrigin returns origin identity and workspace root for the current shell.

type RenameRequest

type RenameRequest struct {
	TmuxName  string
	Namespace string
	Name      string
}

type RenameResult

type RenameResult struct {
	Shell   string `json:"shell"`
	OldName string `json:"oldName"`
	Name    string `json:"name"`
	Changed bool   `json:"changed"`
}

func RenameAtPath

func RenameAtPath(path string, req RenameRequest) (RenameResult, error)

RenameAtPath performs a locked read-before-write mutation of one manifest.

func RenameCurrent

func RenameCurrent(stateDir string, req RenameRequest) (RenameResult, error)

RenameCurrent searches registered project manifests without creating state.

Jump to

Keyboard shortcuts

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