launchdefaults

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 27 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 launchdefaults stores launch defaults for orgs and repositories: the coding agent, each agent's profile, model, and extra flags, the default prompt for each kind of item and for each situation a pull request can be in, and the effort, plan mode, and worktree that launches on their items start from.

An owner's defaults (Name "") apply to every repository of that owner, and a repository's own defaults win over them. Every setting inherits when it is "", nil, or has no entry for the agent, so a row only holds what differs. The launcher resolves the full order: the app's settings, then the owner's defaults, the repository's, the chosen prompt's, and last the launch menu's.

Index

Constants

View Source
const (
	// KeptFormat names the format of the launch defaults' copy, so it can be told from
	// any other JSON file.
	KeptFormat = brand.Slug + ".launch-defaults"

	// KeptVersion is the version of the format this build writes, and the newest it reads.
	// Version 2 keeps a profile, a model, and extra arguments per agent; a version 1
	// copy's are Claude's.
	KeptVersion = 2
)
View Source
const (
	FieldOwner         = "owner"
	FieldName          = "name"
	FieldAgent         = "agent"
	FieldProfiles      = "profiles"
	FieldPRPromptID    = "prPromptId"
	FieldIssuePromptID = "issuePromptId"
	FieldModels        = agent.FieldModels
	FieldEffort        = agent.FieldEffort
	FieldExtraFlags    = agent.FieldExtraFlags
	FieldOutside       = "autopilotOutside"

	// The default prompt for each situation a pull request can be in.
	FieldChecksPromptID    = "checksPromptId"
	FieldConflictsPromptID = "conflictsPromptId"
	FieldChangesPromptID   = "changesPromptId"
	FieldRereviewPromptID  = "rereviewPromptId"
)

Fields an agent.FieldError can name, matching Input's JSON names. A per-agent field's error for one agent names it with agent.FieldFor, as in "profiles.codex".

Variables

View Source
var (
	// ErrNotKept is returned for a file that is not a copy of the launch defaults.
	ErrNotKept = errors.New("the file isn't a copy of the launch defaults")

	// ErrNewerKept is returned for a copy a newer build wrote in a format this build cannot
	// read.
	ErrNewerKept = errors.New("the copy of the launch defaults was saved by a newer version of " + brand.Name)
)
View Source
var (
	// ErrInvalidDefaults is returned when launch defaults cannot be saved (see
	// agent.ValidationError).
	ErrInvalidDefaults = errors.New("the launch defaults can't be saved")

	// ErrNotFound is returned when removing defaults that are not stored.
	ErrNotFound = errors.New("no launch defaults are stored for that org or repository")
)

Functions

func EncodeKept added in v0.2.0

func EncodeKept(kept []Kept, app string, now time.Time) ([]byte, error)

EncodeKept writes kept in the format of the launch defaults' copy, saved at now by the app version app, as indented JSON ending in a newline.

func Restore added in v0.2.0

func Restore(ctx context.Context, st *Store, kept []Kept, promptID func(nickname string) (int64, bool)) (int, error)

Restore stores kept launch defaults in a database that holds none, as after the database was set aside, damaged, or deleted, all of them or, when a write fails, none. It returns how many it stored, and stores nothing when any launch defaults are stored already. promptID finds the prompt a nickname names now; a nickname it does not find inherits. A profile is kept by name even when no profile has it now, as on a Mac without that config directory yet: the launch menu warns that it is missing, and it works again once the profile is back, where dropping it would lose the user's choice. A setting this build would refuse is left out, as is a row for no valid org or repository.

Types

type BackupPart added in v0.2.0

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

BackupPart is the launch defaults' part of a backup of the user's setup: every org's and repository's launch defaults in portable form, and what importing them does. Core adapts it to a backup.Part; it is a type of its own, apart from the Service, so the window, which binds the Service, never reaches it.

func NewBackupPart added in v0.2.0

func NewBackupPart(s *Service) *BackupPart

NewBackupPart returns the backup's part over s.

func (*BackupPart) ApplyBackup added in v0.2.0

func (bp *BackupPart) ApplyBackup(ctx context.Context, tx *sql.Tx, plan BackupPlan, find PromptFinder) (backup.Count, error)

ApplyBackup stores plan's rows inside tx, an import's transaction, each replacing the row stored for the same org or repository, its prompts found through find, and returns what it changed. A row whose prompts find doesn't find, and that then sets nothing, removes the row stored for its org or repository: it inherits every setting.

func (*BackupPart) BackupDone added in v0.2.0

func (bp *BackupPart) BackupDone(ctx context.Context)

BackupDone rewrites the copy of the launch defaults once a backup's are committed.

func (*BackupPart) ClearTx added in v0.2.0

func (bp *BackupPart) ClearTx(ctx context.Context, tx *sql.Tx) error

ClearTx deletes every stored launch default inside tx, an import's transaction, as Replace does before anything is applied.

func (*BackupPart) Kept added in v0.2.0

func (bp *BackupPart) Kept(ctx context.Context) ([]Kept, error)

Kept returns every stored launch default as the app keeps them outside its database, naming each default prompt by its nickname.

func (*BackupPart) PlanBackup added in v0.2.0

func (bp *BackupPart) PlanBackup(ctx context.Context, kept []Kept, mode backup.Mode, known Known) (BackupPlan, error)

PlanBackup works out what importing kept, a backup's launch defaults, does under mode, changing nothing. Under Merge each of the file's rows replaces this Mac's row for the same org or repository, and the other rows stay; under Replace the rows are exactly the file's. A setting this build would refuse is left out, a prompt known doesn't find inherits, and a row for no valid org or repository, or one that sets nothing, is left out, each with a note. A profile is kept by name even when no profile has it here, as a restore keeps it: the launch menu warns that it is missing.

type BackupPlan added in v0.2.0

type BackupPlan struct {
	backup.Plan
	// contains filtered or unexported fields
}

BackupPlan is what importing a backup's launch defaults does, as PlanBackup works it out.

type CloneSource added in v0.2.0

type CloneSource interface {
	// RepoNames returns each clone's origin as owner/name, each once.
	RepoNames(ctx context.Context) ([]string, error)
}

CloneSource lists the GitHub repositories of the clones in the repository locations. *scripts.Service implements it.

type Config added in v0.2.0

type Config struct {
	// Store holds the launch defaults.
	Store *Store

	// Profiles looks up the profiles a default may name.
	Profiles ProfileLookup

	// Prompts looks up the prompts a default may name.
	Prompts PromptLookup

	// Repos lists the repositories offered when adding defaults.
	Repos RepoSource

	// Clones lists the clones' repositories, offered beside the inbox's. Nil offers the
	// inbox's alone.
	Clones CloneSource

	// File is the copy of the launch defaults kept beside the database, written after
	// every change to them. Optional.
	File *File

	// Logger hears a copy that could not be written. Nil discards.
	Logger *slog.Logger
}

Config holds a Service's dependencies. Store, Profiles, and Prompts are required; Repos is needed only by Targets, and Clones is optional.

type Defaults

type Defaults struct {
	// Owner is the org or user; Name is the repository, or "" for the owner's defaults.
	Owner string `json:"owner"`
	Name  string `json:"name"`

	// Agent is the coding agent; agent.Inherit uses the app's default agent.
	Agent agent.ID `json:"agent"`

	// Profiles names each agent's profile; an agent with no entry inherits.
	Profiles map[agent.ID]string `json:"profiles"`

	// PRPromptID and IssuePromptID are the default prompts; nil inherits.
	PRPromptID    *int64 `json:"prPromptId"`
	IssuePromptID *int64 `json:"issuePromptId"`

	// ChecksPromptID, ConflictsPromptID, ChangesPromptID, and RereviewPromptID are the
	// default prompt for a pull request whose checks fail, that conflicts with its base,
	// that a reviewer asked to change, and that the user is asked to review again; nil
	// inherits.
	ChecksPromptID    *int64 `json:"checksPromptId"`
	ConflictsPromptID *int64 `json:"conflictsPromptId"`
	ChangesPromptID   *int64 `json:"changesPromptId"`
	RereviewPromptID  *int64 `json:"rereviewPromptId"`

	// Models is each agent's model; an agent with no entry inherits.
	Models map[agent.ID]string `json:"models"`

	// Effort is the effort level of every agent; "" inherits. An agent that lacks the
	// level launches with its own default.
	Effort string `json:"effort"`

	// PlanMode and Worktree turn plan mode and the worktree on or off; nil inherits.
	PlanMode *bool `json:"planMode"`
	Worktree *bool `json:"worktree"`

	// ExtraArgs is each agent's extra arguments, added after its profile's (an owner's
	// before its repository's), and ExtraFlags is them on one line, quoted.
	ExtraArgs  map[agent.ID][]string `json:"extraArgs"`
	ExtraFlags map[agent.ID]string   `json:"extraFlags"`

	// AutopilotOutside says whether Autopilot may run agents, in plan mode, on outside
	// contributors' items here; "" inherits.
	AutopilotOutside Outside `json:"autopilotOutside"`

	// UpdatedAt is when the defaults were last saved, as RFC 3339.
	UpdatedAt string `json:"updatedAt"`
}

Defaults are one org's or repository's launch defaults. Every field is a plain value.

func (Defaults) Target

func (d Defaults) Target() string

Target names the org or repository a Defaults is for: "acme-org" or "acme-org/example-repo".

type File added in v0.2.0

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

File is the copy of the launch defaults the app keeps in a plain file beside its database. The database stays their home; the file is written whole after every change to them, and after every change to the prompt library, since it names prompts by nickname and a prompt may have been renamed. When the database is lost, damaged, or set aside, Restore brings the launch defaults back from it.

func NewFile added in v0.2.0

func NewFile(path, app string, c clock.Clock) *File

NewFile returns the copy at path, which records app as the version that wrote it and stamps it from c (nil for the system clock).

func (*File) Load added in v0.2.0

func (f *File) Load() ([]Kept, error)

Load reads the file. A file that is not there is an error matching fs.ErrNotExist. Its lists are never nil.

func (*File) Path added in v0.2.0

func (f *File) Path() string

Path returns where the file is.

func (*File) Save added in v0.2.0

func (f *File) Save(ctx context.Context, st *Store, library PromptLookup) error

Save writes every stored launch default st holds to the file, replacing it in one step, naming each default prompt by its nickname in library.

type Index

type Index map[string]Defaults

Index holds launch defaults by org and repository, matched ignoring case.

func NewIndex

func NewIndex(all []Defaults) Index

NewIndex indexes launch defaults by their target.

func (Index) For

func (idx Index) For(name repo.Name) (org, own *Defaults)

For returns an org's defaults and a repository's own, each nil when none are stored.

func (Index) OutsideAllowed added in v0.4.0

func (idx Index) OutsideAllowed(name repo.Name) (allowed bool, from string)

OutsideAllowed says whether Autopilot may run agents, in plan mode, on outside contributors' items in the repository name, and where that was chosen: the repository's own choice wins over its org's, and with neither it is off, as there is no app-wide switch. from is "repo" or "org" for a choice, "" for none.

type Input

type Input struct {
	Owner         string              `json:"owner"`
	Name          string              `json:"name"`
	Agent         agent.ID            `json:"agent"`
	Profiles      map[agent.ID]string `json:"profiles"`
	PRPromptID    *int64              `json:"prPromptId"`
	IssuePromptID *int64              `json:"issuePromptId"`

	// ChecksPromptID, ConflictsPromptID, ChangesPromptID, and RereviewPromptID are the
	// default prompt for each situation a pull request can be in; nil inherits.
	ChecksPromptID    *int64 `json:"checksPromptId"`
	ConflictsPromptID *int64 `json:"conflictsPromptId"`
	ChangesPromptID   *int64 `json:"changesPromptId"`
	RereviewPromptID  *int64 `json:"rereviewPromptId"`

	Models   map[agent.ID]string `json:"models"`
	Effort   string              `json:"effort"`
	PlanMode *bool               `json:"planMode"`
	Worktree *bool               `json:"worktree"`

	// ExtraFlags is each agent's extra arguments typed on one line, quoted as in a shell.
	ExtraFlags map[agent.ID]string `json:"extraFlags"`

	// AutopilotOutside says whether Autopilot may run agents, in plan mode, on outside
	// contributors' items here; "" inherits.
	AutopilotOutside Outside `json:"autopilotOutside"`
}

Input is launch defaults as the editor saves them.

func (Input) Empty

func (in Input) Empty() bool

Empty reports whether every setting inherits.

type Kept added in v0.2.0

type Kept struct {
	Owner    string              `json:"owner"`
	Name     string              `json:"name"`
	Agent    agent.ID            `json:"agent"`
	Profiles map[agent.ID]string `json:"profiles"`

	// PRPrompt and IssuePrompt are the nicknames of the default prompts; "" inherits.
	PRPrompt    string `json:"prPrompt"`
	IssuePrompt string `json:"issuePrompt"`

	// ChecksPrompt, ConflictsPrompt, ChangesPrompt, and RereviewPrompt are the nicknames of
	// the default prompt for a pull request whose checks fail, that conflicts with its base,
	// that a reviewer asked to change, and that the user is asked to review again; "" (left
	// out) inherits. A copy without them, as an older build's, inherits.
	ChecksPrompt    string `json:"checksPrompt,omitempty"`
	ConflictsPrompt string `json:"conflictsPrompt,omitempty"`
	ChangesPrompt   string `json:"changesPrompt,omitempty"`
	RereviewPrompt  string `json:"rereviewPrompt,omitempty"`

	Models    map[agent.ID]string   `json:"models"`
	Effort    string                `json:"effort"`
	PlanMode  *bool                 `json:"planMode"`
	Worktree  *bool                 `json:"worktree"`
	ExtraArgs map[agent.ID][]string `json:"extraArgs"`

	// AutopilotOutside is whether Autopilot may run agents on outside contributors' items
	// here: "off" or "on", left out to inherit. A copy without it, as an older build's,
	// inherits.
	AutopilotOutside Outside `json:"autopilotOutside,omitempty"`
}

Kept is one org's or repository's launch defaults as the app keeps them outside its database. It names its default prompts by nickname, not by ID, so it can be matched to a prompt library brought back from a backup, whose prompts have new IDs.

func DecodeKept added in v0.2.0

func DecodeKept(data []byte) ([]Kept, error)

DecodeKept reads launch defaults in the format of their copy, of any version this build reads. Its lists are never nil.

func ReadSnapshot added in v0.2.0

func ReadSnapshot(ctx context.Context, path string, promptNickname func(id int64) string) ([]Kept, error)

ReadSnapshot reads the launch defaults in the database file at path, whichever build wrote it, without changing it. promptNickname names the prompt each of its prompt IDs stood for in that database, "" for one it does not know.

type Known added in v0.2.0

type Known func(nickname string, kind item.Kind) bool

Known reports whether a prompt nickname will name an agent prompt for kind once an import is applied.

type Outside added in v0.4.0

type Outside string

Outside says whether Autopilot may run agents on outside contributors' items in an org or a repository: "" inherits (a repository's from its org, an org's off, since there is no app-wide switch), else off or on. On still means plan mode: an automatic run never lifts the outside contributor restriction.

const (
	OutsideInherit Outside = ""
	OutsideOff     Outside = "off"
	OutsideOn      Outside = "on"
)

The choices.

func (Outside) Valid added in v0.4.0

func (o Outside) Valid() bool

Valid reports one of the choices, inherit among them.

type ProfileLookup added in v0.2.0

type ProfileLookup interface {
	Lookup(ctx context.Context, id agent.ID, name string) (profiles.Profile, error)
}

ProfileLookup finds an agent's stored profile by name, or returns profiles.ErrProfileNotFound. *profiles.Store implements it.

type PromptFinder added in v0.2.0

type PromptFinder func(ctx context.Context, nickname string, kind item.Kind) (int64, bool, error)

PromptFinder finds, inside an import's transaction, the agent prompt for kind a nickname names, and whether there is one.

type PromptLookup added in v0.2.0

type PromptLookup interface {
	Lookup(ctx context.Context, id int64) (prompts.Prompt, error)
}

PromptLookup finds a stored prompt by ID, or returns prompts.ErrPromptNotFound. *prompts.Store implements it.

type RepoSource added in v0.2.0

type RepoSource interface {
	// Repos returns every repository that is not archived, by owner and then name
	// ignoring case, each with how many of its items the inbox lists now.
	Repos(ctx context.Context) ([]Target, error)
}

RepoSource lists the repositories the inbox has seen, for choosing where to add defaults.

type Service

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

Service manages the launch defaults.

func NewService

func NewService(cfg Config) *Service

NewService returns a Service over cfg.

func (*Service) Check

func (s *Service) Check(ctx context.Context, in Input) ([]agent.FieldError, error)

Check validates launch defaults being edited, as Save would, without saving them.

func (*Service) List

func (s *Service) List(ctx context.Context) ([]Defaults, error)

List returns every stored launch default, by owner and then repository, each owner's own defaults first.

func (*Service) Remove

func (s *Service) Remove(ctx context.Context, owner, name string) error

Remove deletes an org's (name "") or a repository's launch defaults.

func (*Service) Save

func (s *Service) Save(ctx context.Context, in Input) (Defaults, error)

Save stores an org's or repository's launch defaults, replacing any it had. Defaults where every setting inherits are removed instead, since they would change nothing.

func (*Service) Targets

func (s *Service) Targets(ctx context.Context) ([]Target, error)

Targets lists the owners and repositories the inbox has seen, and those the clones in the repository locations have as their origin, each owner before its repositories, by owner and then name ignoring case, for choosing where to add defaults and what to pin or mute. It asks GitHub nothing. The inbox leaves out the repositories it knows are archived; a clone's is listed whatever GitHub says of it. A repository both have is listed once, as the inbox spells it, which is GitHub's spelling, and marked Cloned. An owner's Items adds up its repositories', it is Cloned when one of them is, and it is spelled as the first of its repositories the inbox has, else as its first.

The clones that can't be listed are logged and left out, so a location that can't be read never empties the list; only a caller that has gone gets the error.

type Store added in v0.2.0

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

Store reads and writes the stored launch defaults: the launch_defaults table, which no other package touches. The launcher reads them through it, and the prompt library learns from it where each prompt is a default.

A Store from NewStore runs each call on the pool. One joined to a transaction with WithTx runs every call inside it.

func NewStore added in v0.2.0

func NewStore(db *sql.DB, c clock.Clock) *Store

NewStore returns a Store over the pool db. Saves stamp the rows from c; a nil c is the system clock.

func (*Store) All added in v0.2.0

func (s *Store) All(ctx context.Context) ([]Defaults, error)

All returns every stored launch default, by owner and then repository ignoring case, each owner's own defaults first.

func (*Store) PromptUses added in v0.2.0

func (s *Store) PromptUses(ctx context.Context) ([]prompts.Use, error)

PromptUses lists every place a launch default names a prompt: each org's and each repository's default prompt for pull requests, for issues, and for each situation a pull request can be in, in the order All returns the defaults. It implements prompts.UsageSource.

func (*Store) WithTx added in v0.2.0

func (s *Store) WithTx(tx *sql.Tx) *Store

WithTx returns a Store that runs every call inside tx, a transaction on the same database, so its reads see what tx wrote and its writes commit or roll back with tx.

type Target

type Target struct {
	// Owner is the org or user; Name is the repository, or "" for the owner.
	Owner string `json:"owner"`
	Name  string `json:"name"`

	// Items counts the inbox items listed for it now.
	Items int `json:"items"`

	// Cloned reports that a clone in the repository locations has this repository as its
	// origin; for an owner, that one of its repositories is cloned.
	Cloned bool `json:"cloned"`
}

Target is an org or repository the inbox has seen or a clone's origin names, offered when adding defaults and when pinning or muting.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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