doc-agent.fish

  1function doc-agent --description "Invoke Claude as a documentation-focused sub-agent"
  2    # Define available docsets
  3    set -l available_sets go
  4
  5    # Docset: go
  6    set -l go_tools "go doc"
  7    set -l go_allowed_tools "Bash(go doc:*)"
  8    # These aren't global because WebFetch might be useful later for
  9    # obtaining docs from pages that don't have CLI tooling
 10    set -l go_disallowed_tools "Bash(*) Explore Edit Read WebFetch WebSearch Glob Grep NotebookEdit NotebookRead SlashCommand Task Write"
 11    set -l go_usage "\
 12Looking up Go stdlib, types, functions, methods, interfaces, or third-party \
 13package APIs, ask about usage, combining functions from across APIs, etc. For \
 14complex questions about i.e. combining modules, specify the -m sonnet model \
 15for a higher-quality answer."
 16    set -l go_system_prompt "\
 17You are a focused documentation agent for Go. Use 'go doc' to look up \
 18information about Go packages, types, functions, methods, and other symbols. \
 19Look at specific symbols rather than reading entire packages unless necessary \
 20to understand context. Answer queries thoroughly. You are disallowed from \
 21running any tool but Bash to execute `go doc` subcommands. You _must_ use\
 22`go doc` to answer the query and nothing else."
 23
 24    argparse 'h/help' 's/set=' 'm/model=' -- $argv
 25    or return 1
 26
 27    # Show help if requested
 28    if set -q _flag_help
 29        echo "Usage: doc-agent -s <set> [-m <haiku|sonnet>] <query>"
 30        echo
 31        echo "Options:"
 32        echo "  -s, --set     Documentation set to use (required)"
 33        echo "  -m, --model   Model to use: haiku (default) or sonnet"
 34        echo "  -h, --help    Show this help message"
 35        echo
 36        echo "Available documentation sets:"
 37        echo
 38
 39        for docset in $available_sets
 40            set -l tools_var "$docset"_tools
 41            set -l usage_var "$docset"_usage
 42
 43            echo "- $docset"
 44            echo "  - Allowed tools: $$tools_var"
 45            echo "  - When to use: $$usage_var" | fold -s -w 78 | sed '1!s/^/    /'
 46            echo
 47        end
 48
 49        echo "Tips:"
 50        echo "- Encourage looking at specific symbols rather than entire"
 51        echo "  packages unless context requires it."
 52        echo "- If Haiku doesn't provide a satisfactory answer, retry with a"
 53        echo "  better prompt before escalating to sonnet."
 54        echo "- The doc-agent will only have access to its specific"
 55        echo "  documentation tools; it can't read files, search the web, etc."
 56        return 0
 57    end
 58
 59    # Validate required arguments
 60    if not set -q _flag_set
 61        echo "Error: --set/-s is required" >&2
 62        echo "Run 'doc-agent -h' for usage information" >&2
 63        return 1
 64    end
 65
 66    # Default model to haiku
 67    set -l model haiku
 68    if set -q _flag_model
 69        set model $_flag_model
 70    end
 71
 72    # Validate model
 73    if not contains $model haiku sonnet
 74        echo "Error: model must be 'haiku' or 'sonnet'" >&2
 75        return 1
 76    end
 77
 78    # Validate docset exists
 79    if not contains $_flag_set $available_sets
 80        echo "Error: unknown documentation set '$_flag_set'" >&2
 81        echo "Run 'doc-agent -h' to see available sets" >&2
 82        return 1
 83    end
 84
 85    # Configure the doc set
 86    switch $_flag_set
 87        case go
 88            set allowed_tools $go_allowed_tools
 89            set disallowed_tools $go_disallowed_tools
 90            set system_prompt $go_system_prompt
 91
 92        case '*'
 93            echo "Error: unknown documentation set '$_flag_set'" >&2
 94            return 1
 95    end
 96
 97    claude --model $model \
 98        --allowed-tools "$allowed_tools" \
 99        --disallowed-tools "$disallowed_tools" \
100        --append-system-prompt "$system_prompt" \
101        -p $argv
102end