#compdef tilth

autoload -U is-at-least

_tilth() {
    typeset -A opt_args
    typeset -a _arguments_options
    local ret=1

    if is-at-least 5.2; then
        _arguments_options=(-s -S -C)
    else
        _arguments_options=(-s -C)
    fi

    local context curcontext="$curcontext" state line
    _arguments "${_arguments_options[@]}" : \
'--scope=[Directory to search within or resolve relative paths against]:SCOPE:_files' \
'--section=[Line range or markdown heading (e.g. "45-89" or "## Architecture"). Bypasses smart view]:SECTION:_default' \
'--budget=[Max tokens in response. Reduces detail to fit]:BUDGET:_default' \
'--expand=[Inline source for top N search matches (default 2 when flag bare)]::EXPAND:_default' \
'--glob=[File pattern filter (e.g. "*.rs", "!*.test.ts", "*.{go,rs}")]:GLOB:_default' \
'--completions=[Print shell completions for the given shell]:SHELL:(bash elvish fish powershell zsh)' \
'--full[Force full output (effect depends on query type — see --help)]' \
'--json[Machine-readable JSON output]' \
'--mcp[Run as MCP server (JSON-RPC on stdio)]' \
'--edit[Enable edit mode\: hashline output + tilth_write tool]' \
'--no-overview[Disable project fingerprint in MCP init]' \
'(--deps --map --edit)--callers[Find all callers of a symbol]' \
'(--callers --map --edit)--deps[Analyze blast-radius dependencies of a file]' \
'(--callers --deps --expand --section --full)--map[Generate a structural codebase map]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
'::query -- File path, symbol name, glob pattern, or text to search:_default' \
":: :_tilth_commands" \
"*::: :->tilth" \
&& ret=0
    case $state in
    (tilth)
        words=($line[2] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:tilth-command-$line[2]:"
        case $line[2] in
            (install)
_arguments "${_arguments_options[@]}" : \
'--edit[Enable edit mode (hashline output + tilth_write tool)]' \
'-h[Print help]' \
'--help[Print help]' \
':host -- MCP host to configure:_default' \
&& ret=0
;;
(diff)
_arguments "${_arguments_options[@]}" : \
'--scope=[Restrict diff to a specific file or directory]:SCOPE:_default' \
'--a=[First file for file-to-file diff (requires --b)]:A:_files' \
'--b=[Second file for file-to-file diff (requires --a)]:B:_files' \
'--patch=[Path to a .patch file to parse]:PATCH:_files' \
'--log=[Git log range for per-commit summaries (e.g. HEAD~5..HEAD)]:LOG:_default' \
'--search=[Filter output to symbols or files matching this substring]:SEARCH:_default' \
'--expand=[Expand top N changed symbols with full source context]:EXPAND:_default' \
'--budget=[Max tokens in response]:BUDGET:_default' \
'--blast[Show blast-radius warnings for signature-changed symbols]' \
'-h[Print help]' \
'--help[Print help]' \
'::source -- Diff source\: uncommitted (default), staged, or a git ref (e.g. HEAD~1, main..feat):_default' \
&& ret=0
;;
(overview)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(grok)
_arguments "${_arguments_options[@]}" : \
'--scope=[Restrict search to a subdirectory]:SCOPE:_files' \
'--full[Widen output caps (more callers, callees, siblings, tests)]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
':target -- Symbol name or path\:line:_default' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_tilth__subcmd__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:tilth-help-command-$line[1]:"
        case $line[1] in
            (install)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(diff)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(overview)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(grok)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_tilth_commands] )) ||
_tilth_commands() {
    local commands; commands=(
'install:Install tilth into an MCP host'\''s config. Supported hosts\: claude-code, cursor, windsurf, vscode, claude-desktop, opencode, gemini, codex, amp, droid, antigravity, zed, copilot-cli, augment, kiro, kilo-code, cline, roo-code, trae, qwen-code, crush, pi' \
'diff:Show structural diff with function-level change summaries' \
'overview:Show the project fingerprint (what MCP init would inject)' \
'grok:Grok a symbol — one call returns def + doc + callees + callers + siblings + tests' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'tilth commands' commands "$@"
}
(( $+functions[_tilth__subcmd__diff_commands] )) ||
_tilth__subcmd__diff_commands() {
    local commands; commands=()
    _describe -t commands 'tilth diff commands' commands "$@"
}
(( $+functions[_tilth__subcmd__grok_commands] )) ||
_tilth__subcmd__grok_commands() {
    local commands; commands=()
    _describe -t commands 'tilth grok commands' commands "$@"
}
(( $+functions[_tilth__subcmd__help_commands] )) ||
_tilth__subcmd__help_commands() {
    local commands; commands=(
'install:Install tilth into an MCP host'\''s config. Supported hosts\: claude-code, cursor, windsurf, vscode, claude-desktop, opencode, gemini, codex, amp, droid, antigravity, zed, copilot-cli, augment, kiro, kilo-code, cline, roo-code, trae, qwen-code, crush, pi' \
'diff:Show structural diff with function-level change summaries' \
'overview:Show the project fingerprint (what MCP init would inject)' \
'grok:Grok a symbol — one call returns def + doc + callees + callers + siblings + tests' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'tilth help commands' commands "$@"
}
(( $+functions[_tilth__subcmd__help__subcmd__diff_commands] )) ||
_tilth__subcmd__help__subcmd__diff_commands() {
    local commands; commands=()
    _describe -t commands 'tilth help diff commands' commands "$@"
}
(( $+functions[_tilth__subcmd__help__subcmd__grok_commands] )) ||
_tilth__subcmd__help__subcmd__grok_commands() {
    local commands; commands=()
    _describe -t commands 'tilth help grok commands' commands "$@"
}
(( $+functions[_tilth__subcmd__help__subcmd__help_commands] )) ||
_tilth__subcmd__help__subcmd__help_commands() {
    local commands; commands=()
    _describe -t commands 'tilth help help commands' commands "$@"
}
(( $+functions[_tilth__subcmd__help__subcmd__install_commands] )) ||
_tilth__subcmd__help__subcmd__install_commands() {
    local commands; commands=()
    _describe -t commands 'tilth help install commands' commands "$@"
}
(( $+functions[_tilth__subcmd__help__subcmd__overview_commands] )) ||
_tilth__subcmd__help__subcmd__overview_commands() {
    local commands; commands=()
    _describe -t commands 'tilth help overview commands' commands "$@"
}
(( $+functions[_tilth__subcmd__install_commands] )) ||
_tilth__subcmd__install_commands() {
    local commands; commands=()
    _describe -t commands 'tilth install commands' commands "$@"
}
(( $+functions[_tilth__subcmd__overview_commands] )) ||
_tilth__subcmd__overview_commands() {
    local commands; commands=()
    _describe -t commands 'tilth overview commands' commands "$@"
}

if [ "$funcstack[1]" = "_tilth" ]; then
    _tilth "$@"
else
    compdef _tilth tilth
fi
