prompts

package
v1.2.19 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 17 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 prompts holds the slash-command registry assembly shared by the REPL (internal/cli/repl) and the forthcoming TUI (internal/cli/tui). It was sunk out of the repl package (#383) so both front-ends wire the same built-in, live-state, plugin-declared, prompt-template and skill commands from one owner, avoiding drift between the two command surfaces.

The logic here is a verbatim move of repl's former private buildSlashRegistry/loadPromptPaths/promptTemplateSources (plus their register helpers), exported unchanged so REPL behavior is identical.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildSlashRegistry

func BuildSlashRegistry(live *cli.LiveConfig, creds *provider.CredentialStore, skills []*runtime.Skill, mgr *plugin.Manager, srcs PromptTemplateSources) (*runtime.SlashRegistry, error)

BuildSlashRegistry assembles the slash-command registry: compile-time built-ins seeded by runtime.NewSlashRegistry, the live-state action commands (/model, /help) bound to live, user declarative templates loaded from ~/.golder/commands (or $GOLDER_HOME/commands), plugin-declared commands from the loaded Manager, plus the pre-loaded skills — each surfaced as a "/skill-name" command (mirrors Claude Code's /skill invocation). A missing directory is not an error. Names that collide with a built-in are shadowed (the built-in wins) and reported on stderr. The skills slice is loaded once by setupAgentEnv (empty under --no-skills), so no /skill-name commands are registered when it is empty. mgr may be nil (no plugins loaded). creds may be nil, which disables "/model" live catalog discovery.

func CachedModelCatalog

func CachedModelCatalog(live *cli.LiveConfig) []string

CachedModelCatalog returns the live model catalog without touching the network: the session's already-fetched list when present, else a fresh on-disk entry (younger than the shared catalog TTL). A hit is marked on live so the rest of the session reuses it. Nil when neither cache has anything.

func CredentialAvailable

func CredentialAvailable(creds *provider.CredentialStore, name string) bool

CredentialAvailable reports whether any credential layer can supply a key for a provider. It is a presence probe: no value is read or returned.

func CredentialSummary

func CredentialSummary(creds *provider.CredentialStore, name string) string

CredentialSummary reports a provider's credential availability as a short, value-free label for listings and pickers: "set", "set via config file", "set via --api-key", "set via oauth", or "not set". It is a presence probe that never names which variable satisfied it — the listing already shows the candidate variables in their own column, so repeating one here is noise. creds may be nil, which probes the environment layer only.

func EnsureModelCatalog

func EnsureModelCatalog(live *cli.LiveConfig, creds *provider.CredentialStore) ([]string, error)

EnsureModelCatalog returns the live catalog, preferring the session cache, then a fresh disk cache, and only then the network.

func LoadPromptPaths

func LoadPromptPaths(paths []string) []runtime.SlashCommand

LoadPromptPaths loads prompt templates from each path (file or dir), skipping and warning on paths that don't exist or fail to read. It is tier-agnostic; the caller registers each result at the desired tier (AddSettings/AddCLI).

func ProviderEndpointParts added in v1.2.0

func ProviderEndpointParts(live *cli.LiveConfig, spec provider.ProviderSpec) (envVar, baseURL, source, proxy string)

ProviderEndpointParts breaks the endpoint summary into its structured pieces: the consulted base-url env var(s), the effective URL, where it came from ("default", a variable name, or "base_url override"), and the proxy routing. It backs both the one-line text listing (ProviderEndpointSummary) and the TUI picker's labeled detail block.

func ProviderEndpointSummary

func ProviderEndpointSummary(live *cli.LiveConfig, spec provider.ProviderSpec) string

ProviderEndpointSummary is shared by the terminal picker and text listing.

func ProvidersAvailableFirst

func ProvidersAvailableFirst(creds *provider.CredentialStore) []provider.ProviderSpec

ProvidersAvailableFirst returns the built-in provider specs ordered for display: providers with a credential found first (so the ready-to-use ones are quick to pick), then the rest. Both groups keep registry order.

func ProxyProvidersSelectedFirst

func ProxyProvidersSelectedFirst(selected []string) []provider.ProviderSpec

ProxyProvidersSelectedFirst keeps registry order within the selected and unselected groups. Both the picker and text listing use this ordering.

func RegisterLiveCommands

func RegisterLiveCommands(reg *runtime.SlashRegistry, live *cli.LiveConfig, creds *provider.CredentialStore)

func RegisterPermissionCommand

func RegisterPermissionCommand(reg *runtime.SlashRegistry, st *permissions.State, lang func() string)

RegisterPermissionCommand installs the /permissions action command: with an argument it switches the live approval mode (read-only / ask / auto / full-access); with none it lists the modes and marks the current one. The closure captures the shared state object, so the switch applies to the next tool call in both the plain REPL and the TUI. lang reports the language of the recent conversation ("zh"/"en") so the output matches what the user is writing; a nil lang defaults to English.

func RegisterPluginCommands

func RegisterPluginCommands(reg *runtime.SlashRegistry, mgr *plugin.Manager)

RegisterPluginCommands installs each plugin-declared slash command (Manager.Commands()) into the registry as a hybrid (Run) command. Invoking it RPCs the owning plugin (Plugin.CallCommand), returns the plugin's notifications as the outcome Message, and returns the plugin's Prompt to run as the next turn. Plugin commands are registered with AddPlugin so a same-named built-in still wins (existing precedence preserved) and a collision is reported as shadowed. mgr may be nil (no plugins), in which case this is a no-op.

The args passed to CallCommand are the invocation's raw argument text encoded as a JSON string (json.RawMessage of a quoted string), never null: the host (node #263) expects a JSON string for a no-arg command, so a bare "/cmd" sends `""` rather than nil. Each command captures its own plugin and spec name (loop variables copied per-iteration).

Types

type PromptTemplateSources

type PromptTemplateSources struct {
	Settings []string
	CLI      []string
	// Disable (--no-prompt-templates) turns off all prompt-template discovery
	// (global, project, settings, CLI); built-ins and skills are unaffected.
	Disable bool
	// ProjectDir is the project-local prompts dir (.golder/prompts in the working
	// dir), loaded at the project tier only when ProjectTrusted is true.
	ProjectDir string
	// ProjectTrusted reports whether the working directory is trusted; project
	// templates load only then (mirrors pi: project prompts after the project is
	// trusted).
	ProjectTrusted bool
}

PromptTemplateSources carries the prompt-template discovery sources that BuildSlashRegistry loads beyond the global ~/.golder/{commands,prompts} dirs. Settings is the config.toml `prompts` array (TierSettings); CLI is the --prompt-template flag list (TierCLI, wired in #339). Each entry is a file or directory (loaded non-recursively). Missing paths are warned and skipped.

Jump to

Keyboard shortcuts

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