Documentation
¶
Index ¶
- Constants
- Variables
- type AgentError
- type ArgumentMetadata
- type CommandSchema
- type FlagSchema
- type Logger
- type Metadata
- type ProgressEvent
- type ReturnSchema
- type SubcommandSchema
- type Writer
- func (w *Writer) Flush()
- func (w *Writer) IsTTY() bool
- func (w *Writer) Log(msg string)
- func (w *Writer) Progress(msg string)
- func (w *Writer) WriteError(err *AgentError)
- func (w *Writer) WriteEvent(v any)
- func (w *Writer) WriteProgress(evt ProgressEvent)
- func (w *Writer) WriteSuccess(humanText string, jsonPayload any)
Constants ¶
const ( ExitOK = 0 // Success ExitUserError = 1 // Bad input or arguments ExitToolError = 2 // Environment/internal failure ExitPartial = 3 // Some operations succeeded, some failed )
Exit codes 0–3: table-stakes (present since v0.1).
const ( ExitTimeout = 4 // Operation timed out; retry may succeed ExitNotFound = 5 // Requested resource does not exist ExitPermission = 6 // Caller lacks permission; not retryable without auth change ExitConflict = 7 // State conflict (e.g. resource already exists) ExitRateLimited = 8 // Rate limit hit; retry after RetryAfterMs ExitCancelled = 9 // Operation cancelled by signal or context )
Exit codes 4–9: extended taxonomy (v0.2).
const SchemaVersion = "0.2"
SchemaVersion is the murli envelope schema version. Frozen at "1.0" once v1.0 ships; incrementing requires a documented migration.
Variables ¶
var ExitFunc = os.Exit
ExitFunc is swapped out in tests to capture exit codes without terminating.
var ToolVersion = ""
ToolVersion is the version of the CLI tool using murli. Set this in your main() using a version variable injected at build time:
murli.ToolVersion = version // where `version` is set via -ldflags "-X main.version=1.2.3"
Or inject directly at build time:
-ldflags "-X github.com/allank/murli.ToolVersion=1.2.3"
Functions ¶
This section is empty.
Types ¶
type AgentError ¶
type AgentError struct {
Code int `json:"code"`
ErrorType string `json:"error"`
Message string `json:"message"`
Suggestion string `json:"suggestion,omitempty"`
Recoverable bool `json:"recoverable"`
ValidValues []string `json:"valid_values,omitempty"`
RetryAfterMs int `json:"retry_after_ms,omitempty"`
DocURL string `json:"doc_url,omitempty"`
Field string `json:"field,omitempty"`
SchemaVersion string `json:"schema_version,omitempty"`
ToolVersion string `json:"tool_version,omitempty"`
}
AgentError is the structured error envelope written to stderr. Fields are serialised as JSON in agent mode; SchemaVersion and ToolVersion are auto-populated by WriteError — do not set them manually.
func NewToolError ¶
func NewToolError(message string) *AgentError
NewToolError returns a non-recoverable AgentError for internal/environment failures. Use when the fault is in the environment (network, filesystem, dependency) not the caller.
func NewUserError ¶
func NewUserError(message, suggestion string) *AgentError
NewUserError returns a recoverable AgentError for bad input. Use when the caller supplied invalid arguments or configuration.
func (*AgentError) Error ¶
func (e *AgentError) Error() string
Error implements the standard Go error interface.
type ArgumentMetadata ¶
type ArgumentMetadata struct {
Name string `json:"name"`
Type string `json:"type"`
Required bool `json:"required"`
Description string `json:"description"`
}
ArgumentMetadata documents a single positional argument.
type CommandSchema ¶
type CommandSchema struct {
Name string `json:"name"`
Summary string `json:"summary"`
WhenToUse string `json:"when_to_use,omitempty"`
AgentDescription string `json:"agent_description,omitempty"`
Idempotent bool `json:"idempotent"`
Arguments []ArgumentMetadata `json:"arguments,omitempty"`
Flags []FlagSchema `json:"flags,omitempty"`
Returns *ReturnSchema `json:"returns,omitempty"`
Examples []string `json:"examples,omitempty"`
Subcommands []SubcommandSchema `json:"subcommands,omitempty"`
}
CommandSchema is the JSON payload emitted by --schema.
type FlagSchema ¶
type FlagSchema struct {
Name string `json:"name"`
Type string `json:"type"`
Default any `json:"default"`
Description string `json:"description"`
}
FlagSchema represents a single CLI flag in the JSON schema.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger writes diagnostic messages to stderr. TTY mode: human-readable plain text. Agent mode: one NDJSON object per line {ts, level, msg}; consecutive duplicates are collapsed into a single entry with a "repeated" count.
func (*Logger) Log ¶
Log writes a message. In TTY mode: plain text. In agent mode: NDJSON with deduplication.
func (*Logger) LogProgress ¶
LogProgress writes a progress message. TTY: overwrites current line with carriage return. Agent: NDJSON with level "progress" and deduplication.
type Metadata ¶
type Metadata struct {
// AgentDescription is a detailed description of the command's scope.
AgentDescription string `json:"agent_description"`
// WhenToUse specifies when an agent should select this command.
WhenToUse string `json:"when_to_use"`
// Idempotent specifies if the command is safe to re-run on failure.
Idempotent bool `json:"idempotent"`
// Mutating marks commands that write, delete, or otherwise change state.
// When true and the output is not a TTY, the adapter rejects the command with a
// confirmation_required error to prevent accidental mutation in non-interactive mode.
// A bypass flag (--force / --yes) will be added in a future release.
Mutating bool `json:"mutating,omitempty"`
// Arguments defines explicit positional argument documentation.
Arguments []ArgumentMetadata `json:"arguments,omitempty"`
// Returns defines the expected output format on success.
Returns *ReturnSchema `json:"returns,omitempty"`
// Examples contains concrete shell invocations for agent in-context learning.
Examples []string `json:"examples,omitempty"`
}
Metadata provides LLM-specific parameters to supplement standard CLI command definitions.
type ProgressEvent ¶
type ProgressEvent struct {
Stage string `json:"stage,omitempty"`
Current int `json:"current,omitempty"`
Total int `json:"total,omitempty"`
Percent float64 `json:"percent,omitempty"`
EtaMs int64 `json:"eta_ms,omitempty"`
Message string `json:"message,omitempty"`
}
ProgressEvent carries typed progress state for long-running operations. All fields are optional — populate what is meaningful for the operation.
type ReturnSchema ¶
type ReturnSchema struct {
Type string `json:"type"`
Description string `json:"description"`
Shape map[string]any `json:"shape,omitempty"`
}
ReturnSchema describes the shape of successful command output.
type SubcommandSchema ¶
SubcommandSchema represents a registered subcommand.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer handles dynamic output routing based on terminal presence and agent flags.
func NewWriter ¶
NewWriter returns a configured output writer. Set agentMode true to force JSON output regardless of TTY state.
func (*Writer) Log ¶
Log writes a message to stderr, deduplicating consecutive duplicates in agent mode.
func (*Writer) Progress ¶
Progress writes a progress update; overwrites current line in TTY, collapses in agent mode.
func (*Writer) WriteError ¶
func (w *Writer) WriteError(err *AgentError)
WriteError writes the structured error to stderr and exits with the error's exit code. In TTY mode: human-readable. In agent mode: JSON envelope with schema_version and tool_version.
func (*Writer) WriteEvent ¶
WriteEvent writes a single minified JSON object to stdout on one line. It is safe to call WriteEvent concurrently from multiple goroutines. However, WriteSuccess and WriteError are not mutex-protected — call them only after all WriteEvent goroutines have completed (e.g., after a sync.WaitGroup.Wait()). In TTY mode WriteEvent is a no-op (events are machine-only).
func (*Writer) WriteProgress ¶
func (w *Writer) WriteProgress(evt ProgressEvent)
WriteProgress emits a structured progress event to stderr. Agent mode: minified JSON on one line (via json.Marshal, consistent with WriteEvent). TTY mode: formatted human-readable line with carriage return to overwrite.
func (*Writer) WriteSuccess ¶
WriteSuccess writes to stdout. TTY mode writes humanText; agent mode writes a JSON envelope with status, schema_version, tool_version (if set), and result.