Command helpers for chat-style agents.
This module intentionally keeps command execution policy out of the primitive parser. Concrete agents decide whether a command replies inline, emits an event, calls a handler directly, or streams.
Functions
arg
fn (text: Str): Str
Return only the parsed command argument.
Example
::ai::agent::command/arg("/remind tomorrow 9am") // "tomorrow 9am"
find
fn (commands: Vec<Command>, parsed: ParsedCommand): Command?
Find the first command matching parsed input, or null.
Example
::command ::ai::agent::command
commands [::command/Command({name: "help", aliases: ["h"]}), ::command/Command({name: "why"})]
::command/find(commands, ::command/parse("/h")).name // "help"
::command/find(commands, ::command/parse("/nope")) // null
matches
fn (parsed: ParsedCommand, command: Command): Bool
True when parsed command parsed matches a command's name or aliases.
Example
::command ::ai::agent::command
cmd ::command/Command({name: "memory", aliases: ["mem"]})
::command/matches(::command/parse("/mem"), cmd) // true
::command/matches(::command/parse("/forget"), cmd) // false
parse
fn (text: Str): ParsedCommand
Parse /command rest of text into {is-command, name, arg, raw}.
The leading slash is removed, the command name is lowercased, and
bot suffixes like /ask@MyBot become ask.
Example
::command ::ai::agent::command
parsed ::command/parse("/Ask@MyBot what now?")
parsed.name // "ask"
parsed.arg // "what now?"
::command/parse("hello").is-command // false
usage-line
fn (command: Command): Str
Render one command as a concise help line.
Example
::command ::ai::agent::command
::command/usage-line(::command/Command({name: "why"})) // "/why"
::command/usage-line(::command/Command({name: "why", description: "Explain the last answer."})) // "/why — Explain the last answer."
Types
Command
Command type {
name: Str,
aliases: Vec<Str>?,
description: Str?,
usage: Str?,
route: Str?,
is-async: Bool?,
handler: Fn?,
meta: Map?
}
Declarative command metadata for docs, help text, and dispatch tables.
ParsedCommand
ParsedCommand type {
is-command: Bool,
name: Str,
arg: Str,
raw: Str
}
Result of parsing a slash-style command from text.