
_openclaw_completion() {
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    
    # Simple top-level completion for now
    opts="completion crestodian setup onboard configure config backup migrate doctor dashboard reset uninstall message mcp transcripts agent agents status health sessions commitments tasks acp gateway daemon logs system models infer approvals exec-policy nodes devices node sandbox tui cron dns docs proxy hooks webhooks qr clawbot pairing plugins channels directory security secrets skills update --version --container --dev --profile --log-level --no-color"
    
    case "${prev}" in
      completion)
        opts=" --shell --install --write-state --yes"
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      crestodian)
        opts=" --message --yes --json"
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      setup)
        opts=" --workspace --wizard --non-interactive --accept-risk --mode --import-from --import-source --import-secrets --remote-url --remote-token"
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      onboard)
        opts=" --workspace --reset --reset-scope --non-interactive --modern --accept-risk --flow --mode --auth-choice --token-provider --token --token-profile-id --token-expires-in --secret-input-mode --cloudflare-ai-gateway-account-id --cloudflare-ai-gateway-gateway-id --alibaba-model-studio-api-key --anthropic-api-key --arceeai-api-key --openrouter-api-key --byteplus-api-key --cerebras-api-key --chutes-api-key --cloudflare-ai-gateway-api-key --comfy-api-key --deepinfra-api-key --deepseek-api-key --fal-api-key --fireworks-api-key --github-copilot-token --gmi-api-key --gemini-api-key --huggingface-api-key --kilocode-api-key --kimi-code-api-key --litellm-api-key --lmstudio-api-key --minimax-api-key --mistral-api-key --moonshot-api-key --novita-api-key --nvidia-api-key --ollama-cloud-api-key --openai-api-key --opencode-zen-api-key --opencode-go-api-key --qianfan-api-key --modelstudio-standard-api-key-cn --modelstudio-standard-api-key --modelstudio-api-key-cn --modelstudio-api-key --qwen-oauth-token --runway-api-key --stepfun-api-key --synthetic-api-key --tokenhub-api-key --together-api-key --venice-api-key --ai-gateway-api-key --volcengine-api-key --vydra-api-key --xai-api-key --xiaomi-api-key --xiaomi-token-plan-api-key --zai-api-key --custom-base-url --custom-api-key --custom-model-id --custom-provider-id --custom-compatibility --custom-image-input --custom-text-input --gateway-port --gateway-bind --gateway-auth --gateway-token --gateway-token-ref-env --gateway-password --remote-url --remote-token --tailscale --tailscale-reset-on-exit --install-daemon --no-install-daemon --skip-daemon --daemon-runtime --skip-channels --skip-skills --skip-bootstrap --skip-search --skip-health --skip-ui --suppress-gateway-token-output --skip-hooks --node-manager --import-from --import-source --import-secrets --json"
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      configure)
        opts=" --section"
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      config)
        opts="get set patch unset file schema validate --section"
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      backup)
        opts="create verify "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      migrate)
        opts="list plan apply --from --include-secrets --no-auth-credentials --overwrite --dry-run --yes --skill --plugin --backup-output --no-backup --force --json --verify-plugin-apps"
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      doctor)
        opts=" --no-workspace-suggestions --yes --repair --fix --force --non-interactive --generate-gateway-token --allow-exec --deep --lint --post-upgrade --json --severity-min --skip --only"
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      dashboard)
        opts=" --no-open --yes"
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      reset)
        opts=" --scope --yes --non-interactive --dry-run"
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      uninstall)
        opts=" --service --state --workspace --app --all --yes --non-interactive --dry-run"
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      message)
        opts="send broadcast poll react reactions read edit delete pin unpin pins permissions search thread emoji sticker role channel member voice event timeout kick ban "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      mcp)
        opts="serve list show status probe doctor add set tools configure login logout reload unset "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      transcripts)
        opts="list show path "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      agent)
        opts=" --message --to --session-key --session-id --agent --model --thinking --verbose --channel --reply-to --reply-channel --reply-account --local --deliver --json --timeout"
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      agents)
        opts="list bindings bind unbind add set-identity delete "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      status)
        opts=" --json --all --usage --deep --timeout --verbose --debug"
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      health)
        opts=" --json --timeout --verbose --debug"
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      sessions)
        opts="list cleanup tail export-trajectory --json --verbose --store --agent --all-agents --active --limit"
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      commitments)
        opts="list dismiss --json --agent --status --all"
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      tasks)
        opts="list audit maintenance show notify cancel flow --json --runtime --status"
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      acp)
        opts="client --url --token --token-file --password --password-file --session --session-label --require-existing --reset-session --no-prefix-cwd --provenance --verbose"
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      gateway)
        opts="run status install uninstall start stop restart call usage-cost health stability diagnostics probe discover --port --bind --token --auth --password --password-file --tailscale --tailscale-reset-on-exit --allow-unconfigured --dev --reset --force --verbose --cli-backend-logs --claude-cli-logs --ws-log --compact --raw-stream --raw-stream-path"
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      daemon)
        opts="status install uninstall start stop restart "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      logs)
        opts=" --limit --max-bytes --follow --interval --json --plain --no-color --local-time --utc --url --token --timeout --expect-final"
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      system)
        opts="event heartbeat presence "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      models)
        opts="list status set set-image aliases fallbacks image-fallbacks scan auth --status-json --status-plain --agent"
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      infer)
        opts="list inspect model image audio tts video web embedding "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      approvals)
        opts="get set allowlist "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      exec-policy)
        opts="show preset set "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      nodes)
        opts="status describe list pending approve reject remove rename invoke notify push camera screen location "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      devices)
        opts="list remove clear approve reject rotate revoke "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      node)
        opts="run status install uninstall stop start restart "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      sandbox)
        opts="list recreate explain "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      tui)
        opts=" --local --url --token --password --session --deliver --thinking --message --timeout-ms --history-limit"
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      cron)
        opts="status list add rm enable disable get show runs run edit "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      dns)
        opts="setup "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      docs)
        opts=" "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      proxy)
        opts="start run validate coverage sessions query blob purge "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      hooks)
        opts="list info check enable disable relay install update "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      webhooks)
        opts="gmail "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      qr)
        opts=" --remote --url --public-url --token --password --setup-code-only --no-ascii --json"
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      clawbot)
        opts="qr "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      pairing)
        opts="list approve "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      plugins)
        opts="list search inspect enable disable uninstall install update registry doctor build validate init marketplace "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      channels)
        opts="list status capabilities resolve logs add remove login logout "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      directory)
        opts="self peers groups "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      security)
        opts="audit "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      secrets)
        opts="reload audit configure apply "
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      skills)
        opts="search install update verify workshop list info check --agent"
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
      update)
        opts="finalize wizard status --json --no-restart --dry-run --channel --tag --timeout --yes"
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
        ;;
    esac

    if [[ ${cur} == -* ]] ; then
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
    fi
    
    COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
}

complete -F _openclaw_completion openclaw
