workspacecreate

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: 20 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 workspacecreate owns the shared Create Workspace form: presentation and in-memory state. It does not talk to git or tmux. Hosts bind it and submit through workspaceops.

Index

Constants

View Source
const (
	FieldKind    = "create-kind"
	FieldProject = "create-project"
	FieldName    = "create-name"
	FieldBase    = "create-base"
	FieldAgent   = "create-agent"
	FieldSkip    = "create-skip-permissions"
	ActionCreate = "create-submit"
	ActionCancel = "create-cancel"
)

Stable field IDs shared by both hosts.

View Source
const (
	ActionPlaceAuto  = "create-place-auto"
	ActionPlaceRight = "create-place-right"
	ActionPlaceBelow = "create-place-below"
)

Placement button IDs. Each is a create action: clicking one creates immediately with that placement, with no second confirmation.

View Source
const (
	FieldPickerInput = "create-picker-input"
)

Stable field IDs of the target picker step.

Variables

This section is empty.

Functions

func IsPlacementAction added in v1.3.0

func IsPlacementAction(action string) bool

IsPlacementAction reports that an action came from the placement row, which means "create now with this placement".

func PlacementSplit added in v1.3.0

func PlacementSplit(placement Placement) string

PlacementSplit is the `--split` value for a placement.

func ResolvePickerTarget added in v1.7.0

func ResolvePickerTarget(workDir string, kind Kind, providerID, raw string) (uirequest.Target, error)

ResolvePickerTarget resolves one picker answer onto the CLI's target shape, per kind. This is the whole reason the picker stays an entry point: it ends exactly where `sidecar open` begins.

func ResolvePickerTargetRemote added in v1.12.0

func ResolvePickerTargetRemote(kind Kind, providerID, raw string) (uirequest.Target, error)

ResolvePickerTargetRemote is the host-catalog equivalent of ResolvePickerTarget: identity only, no local path or git resolution.

Types

type FilesScannedMsg added in v1.7.0

type FilesScannedMsg struct {
	Root  string
	Paths []string
}

FilesScannedMsg carries a background file scan for the File picker. Hosts produce it from filefind.ScanPaths so both surfaces feed the picker the same way without this package learning to walk a filesystem.

type Form

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

Form is the Create Workspace chooser: inputs, indexes, skip, error, and modal cache.

func Open

func Open(opts OpenOpts) *Form

Open builds form state and loads last-used agent and that agent's auto-approve. It does not persist last agent.

func (*Form) AdvanceToTarget added in v1.7.0

func (f *Form) AdvanceToTarget()

AdvanceToTarget moves to the picker step for kinds that need one. The caller owns why: Enter chose the kind, or a placement button chose the placement and the target is all that is left to ask.

func (*Form) Agent

func (f *Form) Agent() string

func (*Form) AgentItems

func (f *Form) AgentItems() []modal.DropdownItem

AgentItems is this kind's picker (None first for shells, last for worktrees).

func (*Form) ApplyPlacementAction added in v1.3.0

func (f *Form) ApplyPlacementAction(action string) bool

ApplyPlacementAction records a placement button click and reports that the form should now be submitted. One click is the whole gesture.

func (*Form) ApplyPlacementActionStep added in v1.7.0

func (f *Form) ApplyPlacementActionStep(action string) PlacementAction

ApplyPlacementActionStep records a placement button click and answers what it means for the form's current step and kind.

func (*Form) BackToKind added in v1.7.0

func (f *Form) BackToKind()

BackToKind returns from the picker step to the kind list. Esc on the picker step means this, never close.

func (*Form) BaseBranch

func (f *Form) BaseBranch() string

func (*Form) Build

func (f *Form) Build(width int) *modal.Modal

Build returns the cached modal, rebuilding when width or the step/kind/ branch-list shape changes.

func (*Form) Error

func (f *Form) Error() string

func (*Form) HandleKey added in v1.7.0

func (f *Form) HandleKey(msg tea.KeyPressMsg) (string, tea.Cmd)

HandleKey routes a key through the modal and keeps the two-step flow local: Esc on the picker step goes back to the kind list instead of closing, and Enter on a target-needing kind advances instead of submitting. Up/down on the kind step steer the kind list from whichever field holds focus. What comes back is the action the host should treat, with those consumed.

func (*Form) InitialFocusID

func (f *Form) InitialFocusID() string

InitialFocusID is Name, or the kind toggle when Open was given FocusKind.

func (*Form) Kind

func (f *Form) Kind() Kind

func (*Form) KindDisabledReason added in v1.3.0

func (f *Form) KindDisabledReason() string

KindDisabledReason is why the selected row cannot be created right now, or empty when it can. It is the one gate every create path asks — keyboard, click, and placement button alike — so a disabled row cannot be created through a path that forgot to check.

func (*Form) Modal

func (f *Form) Modal() *modal.Modal

func (*Form) Name

func (f *Form) Name() string

func (*Form) NeedsTarget added in v1.12.0

func (f *Form) NeedsTarget() bool

needsTarget reports whether the currently selected kind continues onto the picker step. NeedsTarget reports that the selected kind has a picker step.

func (*Form) PersistLastAgent

func (f *Form) PersistLastAgent()

PersistLastAgent writes the current agent after a successful modal create.

func (*Form) PickerInput added in v1.7.0

func (f *Form) PickerInput() *textinput.Model

PickerInput exposes the filter input so tests can drive typing exactly as a keyboard would and hosts can paste into the step.

func (*Form) PickerSuggestions added in v1.12.0

func (f *Form) PickerSuggestions() []Suggestion

items are the picker's filtered rows for the current step and kind. PickerSuggestions is the current picker's suggestion pool, for tests.

func (*Form) Placement added in v1.3.0

func (f *Form) Placement() Placement

Placement is the segmented row's current value; Auto until a placement button is clicked.

func (*Form) PlacementSplit added in v1.3.0

func (f *Form) PlacementSplit() string

PlacementSplit is the `--split` value for the current placement.

func (*Form) ProjectIndex

func (f *Form) ProjectIndex() int

func (*Form) ProjectKey

func (f *Form) ProjectKey() string

func (*Form) RestoreFocus

func (f *Form) RestoreFocus()

RestoreFocus applies the pending focus after the modal has been rendered. No-op if focus is already managed by the modal.

func (*Form) SetBranches

func (f *Form) SetBranches(branches []string, current string)

SetBranches replaces the worktree base-branch list. Prefills current as the value unless the typed value is still a branch in the new list.

func (*Form) SetDiffRefs added in v1.7.0

func (f *Form) SetDiffRefs(refs []Suggestion)

SetDiffRefs replaces the diff picker's refs (recent commits and branches).

func (*Form) SetError

func (f *Form) SetError(msg string)

func (*Form) SetFileCandidates added in v1.7.0

func (f *Form) SetFileCandidates(paths []string)

SetFileCandidates replaces the File picker's candidates, most recently relevant first.

func (*Form) SetIssues added in v1.7.0

func (f *Form) SetIssues(items []Suggestion)

SetIssues replaces the issue picker's in-progress + recent issues.

func (*Form) SetKind

func (f *Form) SetKind(k Kind)

func (*Form) SetNotes added in v1.7.0

func (f *Form) SetNotes(items []Suggestion)

SetNotes replaces the note picker's recent notes.

func (*Form) SetPlacement added in v1.3.0

func (f *Form) SetPlacement(placement Placement)

SetPlacement records the placement a button click asked for.

func (*Form) ShowPlacement added in v1.3.0

func (f *Form) ShowPlacement() bool

ShowPlacement reports that the placement row belongs on screen: only a pane this modal places has somewhere to put it. Every pane kind qualifies — File, Git diff, td issue, resource, Note, and the Terminal split that had it first. Shell and Worktree create workspace rows, not panes.

func (*Form) ShowSkip

func (f *Form) ShowSkip() bool

func (*Form) SkipPerms

func (f *Form) SkipPerms() bool

func (*Form) Step added in v1.7.0

func (f *Form) Step() FormStep

Step reports which screen the form shows.

func (*Form) SyncAfterInput

func (f *Form) SyncAfterInput()

SyncAfterInput rematches combo indexes, reloads auto-approve when the agent changes, and persists skip immediately on toggle.

func (*Form) TargetFor added in v1.7.0

func (f *Form) TargetFor(workDir string) (uirequest.Target, error)

TargetFor resolves the picker's current answer onto the same uirequest.Target the CLI produces: the highlighted suggestion wins when there are matches, otherwise the raw typed value does (paste an id the recents do not know). workDir is the workspace root file paths resolve against.

func (*Form) TargetForRemote added in v1.12.0

func (f *Form) TargetForRemote() (uirequest.Target, error)

TargetForRemote resolves the picker answer without touching this machine's filesystem. File and diff values pass through as the host listed them; openPreviewTarget re-resolves through SourceContext.

func (*Form) TerminalName added in v1.3.0

func (f *Form) TerminalName() string

TerminalName is the name a created terminal split takes: what was typed, or the auto-name.

func (*Form) TranslateMouseAction added in v1.7.0

func (f *Form) TranslateMouseAction(action string) string

TranslateMouseAction maps picker-row clicks onto the submit action after pointing the cursor at the clicked row, so a host's existing ActionCreate branch performs the open. Everything else passes through untouched.

func (*Form) Validate

func (f *Form) Validate() string

Validate reports why Create cannot proceed. Worktree name is required; shell name is optional. Empty return means the form is submittable.

type FormStep added in v1.7.0

type FormStep int

FormStep is which screen of the two-step flow the form shows. Shell and Worktree never leave StepKind; pane kinds that need a target continue to StepTarget, and Esc there returns here.

const (
	StepKind FormStep = iota
	StepTarget
)

type Kind

type Kind int

Kind is the workspace type the form will create.

const (
	KindShell Kind = iota
	KindWorktree
	// KindTerminalSplit creates a live terminal beside the workspace's own
	// terminal. It owns no branch and no agent, so it needs at most a name.
	KindTerminalSplit
	// The pane kinds below open one leaf of the pane tree. Each needs a
	// target, so the modal grows a second step for them; each has somewhere
	// to be placed, so the placement row shows for every one of them.
	KindFile
	KindDiff
	KindIssue
	// KindResource opens a configured terminal-resource provider's locator as
	// a resource pane. One row exists per configured instance; ProviderID on
	// the row says which, and the label is that instance ID.
	KindResource
	KindNote
)

type OpenOpts

type OpenOpts struct {
	Kind      Kind
	FocusKind bool
	// UseLastKind starts the list on the row it was last left on, when that
	// row is one this host offers.
	UseLastKind bool
	// AllowTerminalSplit offers the Terminal split row, and nothing else: the
	// flag means "this host can run a SECOND live terminal beside its own".
	// Every other row places a passive pane in a tree, which both hosts have,
	// so no other row is gated on it — bundling them here is what once cost the
	// global browser its resource-provider rows.
	AllowTerminalSplit bool
	// ShowNotes offers the Note row. It follows whether the notes plugin is
	// registered, so a build without Notes never promises a note pane.
	ShowNotes bool
	// PaneKindsOnly drops the Shell and Worktree rows: they create workspace
	// rows, and a host that is not a workspace surface — an ordinary plugin's
	// pane deck — has nowhere to put one. The catalog is otherwise the same
	// table, so a pane kind added there arrives here with no further work.
	PaneKindsOnly bool
	// Providers are the configured terminal-resource provider instances; each
	// becomes its own kind row labelled with its instance ID.
	Providers []ProviderItem
	// TerminalSplitDisabled is why a terminal split cannot be created right
	// now — the on-screen live-terminal cap being the one reason today. When
	// it is set the row and its form render disabled with this one line, and
	// the create paths refuse: the modal states the rule instead of offering a
	// creation that would be refused after the fact.
	TerminalSplitDisabled string
	// TerminalName is the auto-name a terminal split takes when the name field
	// is left empty.
	TerminalName   string
	ShowProject    bool
	ProjectKey     string
	Name           string
	Projects       []ProjectItem
	Agents         []string
	Branches       []string
	NextShell      string
	PreferredAgent string
	DefaultAgent   string
}

OpenOpts configures a new form. PreferredAgent and DefaultAgent are the already-resolved fallbacks from the host (.sidecar-agent / defaultAgentType); this package does not load them from disk.

type Placement added in v1.3.0

type Placement int

Placement is where a created pane lands. It is the modal's face of the same vocabulary `sidecar open --split` uses, so the CLI and the modal share one placement model rather than two that agree by hand.

const (
	PlacementAuto Placement = iota
	PlacementRight
	PlacementBelow
)

func PlacementFromAction added in v1.3.0

func PlacementFromAction(action string) (Placement, bool)

PlacementFromAction maps a placement button's action to its placement.

type PlacementAction added in v1.7.0

type PlacementAction int

PlacementAction is what a placement button click means on the current step: nothing, a continue-with-this-placement onto the picker step, or a create right now. The split exists because pane kinds that need a target cannot create from the kind list — but they must not lose the clicked placement, which Enter on the picker step then honors.

const (
	PlacementIgnored PlacementAction = iota
	PlacementAdvanced
	PlacementSubmitted
)

type ProjectItem

type ProjectItem struct {
	Key   string
	Label string
}

ProjectItem is one row in the global project combo.

type ProviderItem added in v1.7.0

type ProviderItem struct {
	ID string
}

ProviderItem is one configured terminal-resource provider a host offers.

type Suggestion added in v1.7.0

type Suggestion struct {
	Value string
	Label string
	Badge string
	Meta  string
}

Suggestion is one row of a target picker's list. Value is the identifier the target resolves from (a workspace-relative path, a git spec, an issue or note id); Label is what the row displays; Badge is optional provenance; Meta is an optional right-aligned column — an age, today — that answers "which of these is the one I want" without competing with the label for the left edge.

func FoldDiffRefs added in v1.7.0

func FoldDiffRefs(refs []workspaceops.DiffRef) []Suggestion

FoldDiffRefs folds recent commits and branches. Identity resolves host-side through uirequest.DiffTarget exactly as `sidecar open --diff` does; Label may repeat it for readability but never leaks into Value.

func FoldIssues added in v1.7.0

func FoldIssues(issues []workspaceops.IssueRef) []Suggestion

FoldIssues folds td issues, in-progress ones badged so "what am I doing" reads before "what exists". The row is the issue's title with its age in the right-hand column, on the same reasoning as the notes below: an id is what you copy to hand an issue to an agent, not what you scan a list by. Value keeps the id, so pasting one still matches the row it names.

func FoldNotes added in v1.7.0

func FoldNotes(notes []workspaceops.NoteRef) []Suggestion

FoldNotes folds td notes. The row is the note's title with its age in the right-hand column, and the id is nowhere on it: a note id is a thing to copy for an agent, not a thing anyone recognises a note by, and it crowded out the one column that says which note this is. The id stays in Value, so pasting or typing one still matches the row it names.

Jump to

Keyboard shortcuts

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