MingaEditor.Agent.SlashCommand (Minga v0.1.0)

Copy Markdown View Source

Slash command registry and dispatcher for the agent chat input.

When the user types / at the start of input and submits, the text is routed here instead of being sent to the LLM. Each command is a simple {description, handler_fn} where the handler receives the editor state and any arguments after the command name.

Summary

Types

A registered slash command.

A completion candidate for agent slash input.

Editor state (same as EditorState.t()).

Functions

Returns the list of all registered slash commands (static and dynamic).

Returns completion candidates for the current slash input, without the leading slash.

Returns commands whose names start with the given prefix.

Returns slash commands contributed by loaded extensions.

Parses and executes a slash command from raw input text.

Returns true when a slash command may contain secrets and must not enter prompt history.

Returns true if the given text is a slash command (starts with /).

Types

command()

@type command() :: MingaEditor.Agent.SlashCommand.Command.t()

A registered slash command.

completion_candidate()

@type completion_candidate() :: %{
  label: String.t(),
  insert: String.t(),
  description: String.t()
}

A completion candidate for agent slash input.

state()

@type state() :: map()

Editor state (same as EditorState.t()).

Functions

commands()

@spec commands() :: [command()]

Returns the list of all registered slash commands (static and dynamic).

completion_candidates(state, input)

@spec completion_candidates(state(), String.t()) :: [completion_candidate()]

Returns completion candidates for the current slash input, without the leading slash.

completions(prefix)

@spec completions(String.t()) :: [command()]

Returns commands whose names start with the given prefix.

detect_project_root()

See Minga.Project.resolve_root/0.

dynamic_commands()

@spec dynamic_commands() :: [MingaEditor.Agent.SlashCommand.Command.t()]

Returns slash commands contributed by loaded extensions.

execute(state, arg2)

@spec execute(state(), String.t()) :: {:ok, state()} | {:error, String.t()}

Parses and executes a slash command from raw input text.

Returns {:ok, state} if the command was recognized and executed, or {:error, message} if the command is unknown.

sensitive_command?(arg1)

@spec sensitive_command?(String.t()) :: boolean()

Returns true when a slash command may contain secrets and must not enter prompt history.

slash_command?(arg1)

@spec slash_command?(String.t()) :: boolean()

Returns true if the given text is a slash command (starts with /).