Documentation
¶
Index ¶
Constants ¶
const DefaultProgramName = "nib"
DefaultProgramName is what nib calls itself when no embedder has renamed it.
Variables ¶
This section is empty.
Functions ¶
func ProgramNameOr ¶ added in v0.6.0
ProgramNameOr renders a program name for a string a human will read as a command to type: a usage line, an "enable it later" hint, or the sentence in the system prompt that the MODEL will relay as advice. Empty means "nib", so standalone nib is unchanged wherever this is used.
It lives here, in the lowest package the callers share, so the rule has ONE definition. cmd, skill and the prompt renderer all go through it; a second copy would be a second thing to keep in step.
The words are re-joined with single spaces. That is not cosmetic: the name comes from an embedder, and every string this feeds is either read as nib speaking or handed to a model as instructions. A name carrying a newline would otherwise be able to forge a LINE of either.
A line is all it stops. Same-line injection remains possible, and that is fine: this value is the embedder's own Go source, not user input, and an embedder that wanted to steer the model would set Config.Prompt instead. The flattening is there so an accidental newline cannot silently restructure someone's output or prompt.
Types ¶
type AgentOptions ¶
type AgentOptions struct {
Iterations int `yaml:"iterations"`
MaxAttempts int `yaml:"max_attempts"`
MaxRetries int `yaml:"max_retries"`
ForceReasoning bool `yaml:"force_reasoning"`
}
AgentOptions holds configuration for the cogito ExecuteTools function
type AgentTypeConfig ¶
type AgentTypeConfig struct {
Name string `yaml:"name"`
Description string `yaml:"description"`
SystemPrompt string `yaml:"system_prompt"`
Tools []string `yaml:"tools"`
Model string `yaml:"model"`
Temperature float32 `yaml:"temperature"`
Iterations int `yaml:"iterations"`
MaxAttempts int `yaml:"max_attempts"`
MaxRetries int `yaml:"max_retries"`
// Metadata overlays the global Config.Metadata for this agent type
// (per-key: agent keys win, global-only keys are inherited).
Metadata map[string]string `yaml:"metadata,omitempty"`
}
AgentTypeConfig is a wiz-facing sub-agent type. It maps 1:1 to a cogito.AgentDefinition. Zero-valued numeric fields mean "inherit".
type BrowserConfig ¶ added in v0.5.0
type BrowserConfig struct {
Enabled bool `yaml:"enabled,omitempty"`
ChromePath string `yaml:"chrome_path,omitempty"` // installed Chrome binary; "" = auto-discover
ProfileDir string `yaml:"profile_dir,omitempty"` // persistent user-data-dir (login-once)
AllowPrivateURLs bool `yaml:"allow_private_urls,omitempty"` // default false = block localhost/RFC1918
SessionID string `yaml:"-"` // runtime only
}
BrowserConfig configures the built-in browser MCP server. When Enabled, nib starts a headed Chromium (reusing ChromePath, or auto-discovered) on the dedicated persistent profile ProfileDir and exposes the browser_* tools.
type CommandConfig ¶
type CommandConfig struct {
Name string `yaml:"name"`
Description string `yaml:"description"`
Prompt string `yaml:"prompt"`
Agent string `yaml:"agent,omitempty"`
}
CommandConfig is a named slash command: a prompt template (text/template with {{.Args}} and {{.CurrentDirectory}}) optionally routed through a sub-agent.
type CompactionConfig ¶
type CompactionConfig struct {
// Disabled turns OFF automatic compaction. Zero value (false) = auto ON.
Disabled bool `yaml:"disabled"`
// MaxContextTokens is the model context window used to compute the trigger.
// 0 → default 128000.
MaxContextTokens int `yaml:"max_context_tokens"`
// Threshold is the fraction of MaxContextTokens at which auto-compaction
// fires. 0 → default 0.8.
Threshold float64 `yaml:"threshold"`
// KeepRecent is the number of trailing messages kept verbatim. 0 → default 8.
KeepRecent int `yaml:"keep_recent"`
}
CompactionConfig controls conversation compaction: summarizing older turns into a single summary message while keeping recent turns verbatim.
type ComputerConfig ¶ added in v0.5.0
type ComputerConfig struct {
Enabled bool
Command string
Args []string
Env map[string]string
SessionID string
}
ComputerConfig configures the built-in computer_use MCP server. When Enabled, nib spawns Command (the cua-driver binary) as a stdio MCP child. nib never bundles the binary; Command is resolved by the consumer (or NIB_CUA_DRIVER_CMD).
type Config ¶
type Config struct {
Model string `yaml:"model"`
APIKey string `yaml:"api_key"`
BaseURL string `yaml:"base_url"`
// Specialist models for attachment handling. Empty ⇒ LocalAI auto-selects
// by usecase (FLAG_TRANSCRIPT / FLAG_VISION).
TranscribeModel string `yaml:"transcribe_model,omitempty" json:"transcribe_model,omitempty"`
VisionModel string `yaml:"vision_model,omitempty" json:"vision_model,omitempty"`
VideoModel string `yaml:"video_model,omitempty" json:"video_model,omitempty"`
LogLevel string `yaml:"log_level"`
Prompt string `yaml:"prompt"`
// Metadata is a per-request metadata object attached verbatim to every
// chat-completion request (the OpenAI "metadata" field). Backends such as
// LocalAI use it for per-request flags, e.g. {"enable_thinking": "false"}
// to disable reasoning. Applied to the main session and inherited by
// sub-agents (see AgentTypeConfig.Metadata for per-agent overrides).
Metadata map[string]string `yaml:"metadata,omitempty"`
// ReasoningEffort sets the OpenAI "reasoning_effort" on every request
// ("none"/"low"/"medium"/"high"). Unlike Metadata.enable_thinking, this binds
// even when the model's chat template has no enable_thinking toggle (e.g.
// LFM2.5), so it's the reliable way to disable a reasoning model's thinking
// ("none"). Empty leaves the field unset.
ReasoningEffort string `yaml:"reasoning_effort,omitempty"`
MCPServers map[string]MCPServer `yaml:"mcp_servers"`
AgentOptions AgentOptions `yaml:"agent_options"`
Compaction CompactionConfig `yaml:"compaction"`
Agents []AgentTypeConfig `yaml:"agents"`
PromptFragments []string `yaml:"prompt_fragments"`
Skills []Skill `yaml:"skills"`
Commands []CommandConfig `yaml:"commands"`
Hooks []HookConfig `yaml:"hooks"`
// ApprovalMode controls tool-call gating:
// "" / "prompt" ask the user, but auto-approve read-only calls
// "strict" ask the user for every call (no read-only auto-approval)
// "allowlist" auto-approve only the tools in AllowedTools, prompt the rest
// "auto" approve every tool call
ApprovalMode string `yaml:"approval_mode"`
// AllowedTools are tool names pre-approved without prompting (always honored;
// the basis of "allowlist" mode).
AllowedTools []string `yaml:"allowed_tools"`
// BuiltinTools, if non-empty, restricts which built-in tools and
// self-config tools are exposed to the model (by name) — an allowlist.
// Empty means all of them. Trims the prompt for small local models;
// independent of AllowedTools (which gates approval). Never restricts
// tools from user-configured MCP servers (mcp_servers:) — those are
// always exposed, since restricting them would defeat the point of
// configuring the server. See chat.Session's MCP tool filter.
BuiltinTools []string `yaml:"builtin_tools,omitempty"`
// ReadOnlyCommands extends the built-in set of bash commands treated as
// read-only (auto-approved in the default "prompt" mode). An entry with a
// space is a command+subcommand pair (e.g. "terraform plan"); otherwise it
// matches that command at any arguments. User entries are merged with, not
// replacing, the built-in set.
ReadOnlyCommands []string `yaml:"read_only_commands"`
// TraceDir, when non-empty, enables session tracing: each LLM call's raw
// request/response is appended to <TraceDir>/trace.ndjson. Set at runtime
// from the --trace-dir flag or NIB_TRACE_DIR env, not from the YAML config.
TraceDir string `yaml:"-"`
// InitialHistory seeds a new session with a prior conversation so the very
// next SendMessage continues with full memory of it (resume/rehydration).
// Typically these are the messages a previous session returned from
// Session.ExportHistory, persisted to disk and reloaded. They MUST NOT
// include the system prompt: it is regenerated per-model/locale from Prompt
// and re-applied on every turn (see Session.SendMessage), so a seeded system
// message would duplicate it. Set at runtime, never from the YAML config.
InitialHistory []openai.ChatCompletionMessage `yaml:"-"`
// WorkingDir, when non-empty, is the directory host tools (bash, filesystem)
// operate in. Runtime-only; empty means the process cwd (legacy behavior).
WorkingDir string `yaml:"-"`
// BaseDir overrides the config/plugins/skills root for this invocation, so
// an embedder's state does not collide with a separately installed nib.
// Set by config.LoadWith from LoadOptions.BaseDir; empty means nib's own
// default resolution, so resolve it through plugin.BaseDirIn (or
// config.WritablePathIn for the config file) rather than using it raw.
// Runtime-only: never read from or written to YAML.
BaseDir string `yaml:"-"`
// ProgramName is what the user types to reach this program, e.g. "nib" or an
// embedder's "local-ai chat". Empty means "nib".
//
// It rides on Config for one reason: the system prompt is rendered from
// Config, and that prompt tells the MODEL how the user can register MCP
// servers from the command line. Named wrong, the model repeats the wrong
// command as advice, in its own words, whenever it seems relevant, and the
// user has no cue that the tool is called something else here.
//
// Runtime-only, exactly like TraceDir: set by the embedder through
// app.Options.ProgramName, never read from or written to YAML, so no config
// file can rename the program out from under the binary that is running.
// A user template can still read it as {{.Config.ProgramName}}.
ProgramName string `yaml:"-"`
// Computer is the opt-in desktop-control capability (cua-driver). Runtime-only.
Computer ComputerConfig `yaml:"-"`
// Browser is the opt-in browser-automation capability (chromedp-driven).
Browser BrowserConfig `yaml:"browser,omitempty"`
}
Config holds configuration for creating a new session
type HookConfig ¶
type HookConfig struct {
Event string `yaml:"event"`
Matcher string `yaml:"matcher,omitempty"`
Command string `yaml:"command"`
Dir string `yaml:"-"` // plugin root; set during merge, not parsed
}
HookConfig is a shell command bound to a lifecycle event. Matcher (optional) is matched against the tool name for PreToolUse/PostToolUse. Dir is the plugin root (set during merge); it is the command's working directory and is exported as ${NIB_PLUGIN_ROOT}/${CLAUDE_PLUGIN_ROOT}.
type MCPServer ¶
type MCPServer struct {
Command string `yaml:"command,omitempty"`
Args []string `yaml:"args,omitempty"`
Env map[string]string `yaml:"env,omitempty"`
URL string `yaml:"url,omitempty"` // remote: presence selects an HTTP/SSE transport
Transport string `yaml:"transport,omitempty"` // remote transport: "http" (default) or "sse"
BearerToken string `yaml:"token,omitempty"` // remote only: sent as "Authorization: Bearer <token>"
Headers map[string]string `yaml:"headers,omitempty"` // remote only: custom HTTP headers
// Disabled, when true, keeps the server in config (so the UI can list and
// re-enable it) but excludes it from EffectiveConfig, so it starts no
// transport. Absent (omitempty) reads as enabled — no migration needed.
Disabled bool `yaml:"disabled,omitempty"`
}
type Skill ¶
type Skill struct {
Name string `yaml:"name"`
Description string `yaml:"description"`
Instructions string `yaml:"instructions"` // resolved body (inline, or loaded from a plugin file)
Tools []string `yaml:"tools,omitempty"`
Dir string `yaml:"-"` // absolute on-disk dir for bundled files; runtime-only, never serialized
}
Skill is a named, on-demand instruction set. Its Description is listed in the system prompt; the agent calls the load_skill tool to read Instructions.