Documentation
¶
Overview ¶
Package ask answers the questions the addon queues with /ask (schema 1, see docs/ask.md). It reads WoWCompanionDB.asks from the addon's SavedVariables file, runs a headless agent CLI once per unanswered question, and writes the WoWCompanion_Answers slot addon's Answers.lua.
The agent gets the question and the character key, never the capture: it reads facts through the advisor's MCP tools.
Index ¶
- Constants
- Variables
- func AnswersLua(answers map[string]Answer) string
- func Argv(tmpl []string, prompt, mcpConfig string) []string
- func CheckAnswers(text string) error
- func CheckInstalled(answersPath string) error
- func Clean(s string) string
- func Command(ctx context.Context, argv []string) *exec.Cmd
- func Detect(pathEnv string, extra []string) (name, path string, ok bool)
- func DetectedPath(source string, command []string) string
- func ExtraDirs(getenv func(string) string) []string
- func GeminiPolicy() []byte
- func MCPConfig(exe string, env map[string]string) []byte
- func Paths(foreverScribe string) (savedVariables, answers string, err error)
- func PolicyPath(mcpConfig string) string
- func Prompt(q Question) string
- func ReadAnswers(path string) map[string]Answer
- func ResolveAgent(flagValue, configPath string) ([]string, error)
- func Respond(ctx context.Context, cfg Config, q Question, prompt string, stream bool, ...) (text string, streamed bool, err error)
- func Sources(s string) []string
- func Stamp(path string) string
- func Summary(r Result, answersPath string) string
- func Watch(ctx context.Context, cfg Config, every time.Duration, out io.Writer) error
- func WriteAnswers(path string, answers map[string]Answer) error
- type Agent
- type Answer
- type Config
- type Question
- type Result
Constants ¶
const ( MaxAnswer = 1500 MaxOutput = 64 << 10 DefaultTimeout = 2 * time.Minute DefaultMaxPerRun = 5 )
Limits. MaxAnswer is in characters. MaxOutput bounds what is read from the agent at all.
const ( SourceFlag = "flag" // --agent SourceConfig = "config" // "agent" in the config file SourceAuto = "auto" // found on this machine SourceNone = "none" // no agent configured and none found )
Where an agent came from, as the companion's handshake reports it.
const AutoAgent = "auto"
AutoAgent is the --agent (or config) value that asks for detection even when the config file names an agent.
const Schema = 1
Schema is the Answers.lua format version this package writes.
const ServerName = "wowc-advisor"
ServerName is the advisor's name in the generated MCP config and in each CLI's own settings.
const SlotAddon = "WoWCompanion_Answers"
SlotAddon is the data-only addon the answers are written into.
ToolsUnavailable is the answer when the AI client would not run the advisor's tools.
Variables ¶
var DetectOrder = []string{"claude", "codex", "gemini"}
DetectOrder is the order the AI CLIs are looked for in; the first one found is used.
var Presets = map[string][]string{ "claude": {"claude", "-p", "{prompt}", "--mcp-config", "{mcp_config}", "--strict-mcp-config", "--allowedTools", "mcp__" + ServerName, "--disallowedTools", "Bash", "Edit", "Write", "NotebookEdit", "WebFetch", "WebSearch", "Read", "Glob", "Grep"}, "codex": {"codex", "exec", "--skip-git-repo-check", "-s", "read-only", "-c", "mcp_servers." + ServerName + "={mcp_codex}", "{prompt}"}, "gemini": {"gemini", "--allowed-mcp-server-names", ServerName, "--policy", "{mcp_policy}", "-p", "{prompt}"}, }
Presets are the documented agent commands (docs/ask.md lists what each passes). {prompt} is the question text, {mcp_config} the path of a generated MCP config file, {mcp_codex} the advisor server as a Codex inline config table, {mcp_policy} the path of a generated Gemini policy file; a command without {prompt} gets the prompt as its last argument.
Each preset pre-allows the advisor's tools and nothing else, because a headless run refuses what it cannot ask about.
var StreamArgs = []string{"--output-format", "stream-json", "--verbose", "--include-partial-messages"}
StreamArgs are appended to a Claude command to make it print stream-json with partial messages.
var Tools = []string{"character_brief", "list_characters", "server_info", "update_digest", "upgrade_finder", "whats_next"}
Tools are the advisor tool names; an answer that names one gets it in its sources line.
Functions ¶
func AnswersLua ¶
AnswersLua renders the answers as the one data-only `WoWCompanionAnswers = {...}` assignment.
func Argv ¶
Argv fills the placeholders in the command template; with no {prompt}, the prompt is appended. An argument that needs the MCP config is dropped, with the flag before it, when there is none.
func CheckAnswers ¶
CheckAnswers is the slot rule: the text must be exactly one `WoWCompanionAnswers = {...}` assignment of literals (the safe reader refuses anything else), schema 1, and every answer must have answered_at and text, with sources, when present, a list of strings.
func CheckInstalled ¶
CheckInstalled is an error when the slot addon's folder is not there. Nothing is created.
func Clean ¶
Clean trims the agent's output and cuts it to MaxAnswer characters, at a rune boundary.
func Command ¶
Command is exec.CommandContext for the agent argv. On Windows a .cmd or .bat shim (npm's) runs through cmd.exe and a .ps1 script through PowerShell; anything else runs directly.
func Detect ¶
Detect finds the first of DetectOrder in the PATH list, else in the extra directories, and the full path to it.
func DetectedPath ¶
DetectedPath is the executable a detected agent runs ("" for any other source).
func ExtraDirs ¶
ExtraDirs are the places the AI CLIs' installers put them that a desktop app's PATH may lack. getenv supplies USERPROFILE, APPDATA, LOCALAPPDATA and ProgramFiles (Windows) or HOME.
On Windows:
%USERPROFILE%\.local\bin Claude Code's native installer (claude.exe) %USERPROFILE%\.claude\local Claude Code's local install %APPDATA%\npm npm install -g shims (claude.cmd, codex.cmd, gemini.cmd) %LOCALAPPDATA%\Microsoft\WinGet\Links WinGet's command links %LOCALAPPDATA%\Programs\claude %USERPROFILE%\scoop\shims Scoop shims %ProgramFiles%\nodejs a system-wide npm prefix
func GeminiPolicy ¶
func GeminiPolicy() []byte
GeminiPolicy is the Gemini CLI policy file: the advisor's tools run without asking, and shell, file writes and web access are denied outright (a headless run cannot ask).
func MCPConfig ¶
MCPConfig renders the MCP config JSON handed to the agent: it starts this binary as a stdio server on the capture. The agent reads facts through it and is never given the file itself.
func Paths ¶
Paths derives the addon's SavedVariables file and Answers.lua from the ForeverScribe SavedVariables path, the way the digest path is derived: the same SavedVariables folder holds WoWCompanion.lua, and the answers go to <game>/Interface/AddOns/WoWCompanion_Answers/Answers.lua.
func PolicyPath ¶
PolicyPath is where the Gemini policy file sits: next to the generated MCP config.
func Prompt ¶
Prompt is what the agent is asked: the question and the character key, where the facts are, and what to say if the tools are missing.
func ReadAnswers ¶
ReadAnswers returns the answers a valid Answers.lua holds; a missing or invalid file holds none.
func ResolveAgent ¶
ResolveAgent turns the --agent value, or else the config file's "agent" field, into an argv. A preset name (claude, codex, gemini) expands to its command; anything else is split on spaces.
func Respond ¶
func Respond(ctx context.Context, cfg Config, q Question, prompt string, stream bool, onText func(string)) (text string, streamed bool, err error)
Respond runs the agent for q with prompt (see Prompt) and returns the answer. With stream set the command is Claude's: its text deltas are passed to onText as they arrive and streamed is true when any did. Otherwise the output is read whole, cut like ask does, and streamed is false.
func Summary ¶
Summary is the one line a pass prints; it reminds the player to /reload when answers were written.
Types ¶
type Agent ¶
Agent is a resolved agent: its argv, its short name and where it came from. A Source of SourceNone has no Command.
func ResolveAuto ¶
ResolveAuto is ResolveAgent for callers that can run without an agent: with nothing configured, or the value "auto", it looks for the first of DetectOrder installed. Nothing found is no error.
type Config ¶
type Config struct {
SavedVariables string // the addon's WoWCompanion.lua
AnswersPath string // Answers.lua to write
Command []string // the agent argv, see Presets; empty when no agent is set up (the companion only)
Name, Source string // the agent's short name and where it came from (see Agent); may be empty
MCPConfig string // path of the MCP config file handed to the agent; may be empty
Timeout time.Duration
MaxPerRun int
Now func() time.Time
}
Config is one pass's settings.