#compdef omp
# zsh completion for omp — generated by `omp completions zsh`

_omp_call() {
	# zsh's _arguments invokes an action function with the compadd options it
	# computed prepended ($subopts, then $expl — _arguments:465), so $1 is
	# "-J" in a stock setup and the kind arrives last. Read it from the end:
	# the prepended options can be either flags or option/value pairs.
	local kind=${argv[-1]}
	local -a items
	local line
	for line in "${(@f)$(command omp __complete $kind -- "$PREFIX" 2>/dev/null)}"; do
		[[ -z $line ]] && continue
		items+=( "${line//$'\t'/:}" )
	done
	_describe -t "$kind" "$kind" items
}
_omp_models_list() {
	local -a items
	local line
	for line in "${(@f)$(command omp __complete models 2>/dev/null)}"; do
		[[ -z $line ]] && continue
		items+=( "${line%%$'\t'*}" )
	done
	_values -s , 'models' $items
}
_omp_tools() { _values -s , 'tools' read bash edit ast_grep ast_edit ask debug ida eval github glob grep find lsp checkpoint rewind context_notes new_context security_scan task wait todo web_search write memory_edit retain recall reflect learn manage_skill }

_omp_commands() {
	local -a commands
	commands=(
		'acp:Run omp as an ACP (Agent Client Protocol) server over stdio'
		'agents:Manage bundled task agents'
		'auth-broker:Manage the omp auth-broker (credential vault)'
		'auth-gateway:Run an auth-gateway forward proxy backed by the configured broker'
		'bench:Benchmark models  TTFT/prefill vs decode throughput with p50/p95, across chat, prefill, generation, and prompt-cache workloads, or single-user vs parallel load (--detailed)'
		'browser-relay:Run the local CDP relay that lets the browser prelude drive your own Chrome tabs'
		'cleanse:Detect and fix project diagnostics with weighted parallel subagents'
		'clip:Upload a /record recording to live.omp.sh as a public clip and print its URL'
		'collab:List active local Collab host metadata without URLs; use collab link <instanceId|pid> to retrieve a control link (--view for view-only)'
		'commit:Generate a commit message and update changelogs'
		'completions:Print a shell completion script (bash, zsh, or fish)'
		'compress:Rewrite a text file into the dense prompt register, reporting what it drops'
		'config:Manage configuration settings'
		'dry-balance:Dry-run OAuth account balancing across random session ids'
		'find:Semantic search  describe a behavior, get the files and line ranges that implement it'
		'gallery:Preview tool, composer, and status-line renderers in a deterministic visual gallery'
		'gc:Run storage garbage collection'
		'git:Interactive fullscreen git UI  split diff viewer, staging sidebar, and commit composer'
		'grep:Test grep tool'
		'grievances:View, clean, or push reported tool issues (auto-QA grievances)'
		'if-bench:Benchmark instruction following and working memory  one cached thread of glyph array actions with a moving cat-sound directive'
		'images:Inspect, diagnose, probe, and purge image publication backends'
		'install:Install or link an extension package (alias of `plugin install`/`plugin link`)'
		'join:Join a shared collab session (same as /join)'
		'login:Log in to a model provider (terminal counterpart of /login)'
		'models:List, search, and refresh available models'
		'play:Replay a /record session recording in the terminal (space pauses, q quits)'
		'plugin:Manage plugins (install, uninstall, list, etc.)'
		'predict:Type a prompt and compare every word-completion engine’s ghost text live'
		'ps:List and control daemon-supervised background processes (logs, stop, kill, restart)'
		'read:Show what the read tool will return for a path, URL, or internal URI'
		'render:Draw a session’s entire thread through the production transcript pipeline (with repaint timing)'
		'say:Synthesize text with the local TTS engine and play it through the speakers'
		'search:Test web search providers'
		'setup:Run onboarding setup or install dependencies for optional features'
		'share:Share a saved session via an encrypted link (same as /share)'
		'shell:Interactive shell console'
		'skill:Install, search, publish, and manage skills on the Skillshare registry (skills.omp.sh)'
		'ssh:Manage SSH host configurations'
		'stats:View usage statistics'
		'stream:Broadcast local omp session screens and chat to your public live channel'
		'tiny-models:Download tiny local models (session titles, memory, word completion)'
		'token:Get the API key or OAuth token for a provider'
		'toks:Count a file or text with every embedded offline tokenizer (OpenAI, Claude, Qwen, …)'
		'ttsr:Inspect and test Time-Traveling Stream Rules (TTSR)'
		'update:Check for and install updates'
		'usage:Show provider usage limits for every authenticated account'
		'worktree:Add, list, or clear git worktrees (clone-first when enabled)'
	)
	_describe -t commands 'command' commands
}

_omp_cmd_acp() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]'
}

_omp_cmd_agents() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'(-f --force)'{-f,--force}'[Overwrite existing agent files]' \
		'--json[Output JSON]' \
		'--dir[Output directory (overrides --user/--project)]:file:_files' \
		'--user[Write to ~/.omp/agent/agents (default)]' \
		'--project[Write to ./.omp/agents]' \
		':action:(unpack)'
}

_omp_cmd_auth_broker() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'--json[Output JSON]' \
		'(-b --bind)'{-b,--bind}'[Bind address for `serve` (host port)]:file:_files' \
		'--regenerate[Regenerate the bearer token]' \
		'--via[SSH user@host for remote login (login --via=user@host)]:file:_files' \
		'--provider[Override provider id for `import` (e.g. when JSON `type` is unrecognized)]:file:_files' \
		'--include-disabled[Import credentials whose JSON has `disabled  true` (import)]' \
		'--from-local[migrate source  local SQLite + env vars (required for `migrate`)]' \
		'--include-env[Capture env-var API keys for providers not yet on broker (migrate)]' \
		'--include-oauth[Also upload OAuth from local SQLite during migrate (default skips them)]' \
		'--dry-run[Print actions without executing (import / login --via / migrate)]' \
		':action:(serve token login logout import migrate status list)' \
		':source:_files'
}

_omp_cmd_auth_gateway() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'--json[Output JSON (token/status/check)]' \
		'(-b --bind)'{-b,--bind}'[Bind address for `serve` (host port)]:file:_files' \
		'--regenerate[Regenerate the gateway bearer token (token)]' \
		'--no-auth[Disable inbound bearer-token auth (serve). Useful when bound to loopback — any caller is allowed.]' \
		'--strict[For `check`  additionally probe each credential against its provider’s chat-completion endpoint. Slower; consumes a tiny amount of quota per credential.]' \
		':action:(serve token status check)'
}

_omp_cmd_bench() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'--runs[Requests per model (default  10 chat, 5 prefill/generation, 9 mix); with --detailed, per phase (default  4)]:value:' \
		'--max-tokens[Max output tokens per request (default  chat 512, prefill 64, generation 2048, cache 64)]:value:' \
		'--prompt[Custom prompt text (chat and generation profiles only)]:file:_files' \
		'--profile[Benchmark workload (default chat)  chat (balanced, measures TTFT and tok/s), prefill (large cache-busted input, measures input processing), generation (long forced output, measures sustained decode), mix (rotates all three)]:value:(chat prefill generation mix)' \
		'--prefill-bytes[Synthetic input size for prefill challenges (default  32768, capped by the context window)]:value:' \
		'--detailed[Run single-user (1 concurrent), parallel (--par concurrent, with aggregate tok/s and scaling), and prefill phases per model]' \
		'--service-tier[Service tier applied per model family (default  configured `tier.*` settings; `none` omits it)]:value:(none auto default flex scale priority)' \
		'--json[Output JSON]' \
		'--par[Execute runs with N parallel queries/requests (default  4); --detailed’s parallel phase width]:value:' \
		'--cache[Run independent cold/warm prompt-cache pairs (not supported for openai-codex-responses)]' \
		'--cache-prefix-file[Stable prompt prefix file for --cache]:file:_files' \
		'--cache-prefix-bytes[Stable prefix byte budget for --cache (default  8192)]:value:' \
		'--cache-pairs[Cold/warm pairs per model for --cache (default  1)]:value:' \
		'--cache-concurrency[Concurrent cache pairs for --cache; each pair remains sequential (default  1)]:value:' \
		':models:_files'
}

_omp_cmd_browser_relay() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'(-p --port)'{-p,--port}'[Port to listen on]:value:' \
		'--token[Require the extension to present this token]:file:_files' \
		'--dir[Extension install directory (install; default ~/.omp/browser-relay/extension)]:file:_files' \
		'--no-group[Don’t gather controllable tabs into an ’omp’ tab group]' \
		'(-v --verbose)'{-v,--verbose}'[Log relay traffic summaries to stderr]' \
		':action:(serve install)'
}

_omp_cmd_cleanse() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'(-n --agents)'{-n,--agents}'[Maximum number of file-disjoint subagents]:value:' \
		'(-m --model)'{-m,--model}'[Subagent model selector]:model:_omp_call models' \
		'(-t --tests)'{-t,--tests}'[Also run configured project test suites]' \
		'(-a --all)'{-a,--all}'[Run every discovered checker without the interactive picker]' \
		':request:_files'
}

_omp_cmd_clip() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'(-t --title)'{-t,--title}'[Clip title (defaults to the recording’s title)]:file:_files' \
		'(-d --description)'{-d,--description}'[Clip description shown under the player]:file:_files' \
		'--server[Stream server base URL (overrides stream.serverUrl)]:file:_files' \
		':file:_files'
}

_omp_cmd_collab() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'--view[Request a view-only link instead of control access (link only)]' \
		'(-j --json)'{-j,--json}'[Emit deterministic machine-readable JSON]' \
		':action:(list link)' \
		':selector:_files'
}

_omp_cmd_commit() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'--push[Push after committing]' \
		'--dry-run[Preview without committing]' \
		'--no-changelog[Skip changelog updates]' \
		'--legacy[Use legacy deterministic pipeline]' \
		'(-c --context)'{-c,--context}'[Additional context for the model]:file:_files' \
		'(-m --model)'{-m,--model}'[Override model selection]:model:_omp_call models'
}

_omp_cmd_completions() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		':shell:(bash zsh fish)'
}

_omp_cmd_compress() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'(-o --out)'{-o,--out}'[Write the approved text here instead of stdout (single file)]:file:_files' \
		'(-i --inPlace)'{-i,--inPlace}'[Overwrite each source file with its approved text]' \
		'(-r --rounds)'{-r,--rounds}'[Maximum drafts per file before giving up]:value:' \
		'(-n --agents)'{-n,--agents}'[Files compressed concurrently]:value:' \
		'(-m --model)'{-m,--model}'[Model selector]:model:_omp_call models' \
		':files:_files'
}

_omp_cmd_config() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'--json[Output JSON]' \
		':action:(list get set reset path init-xdg)' \
		':key:_files' \
		':value:_files'
}

_omp_cmd_dry_balance() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'--model[Model selector (same syntax as --model on omp)]:model:_omp_call models' \
		'--count[Number of random session ids to try]:value:' \
		'--concurrency[Maximum concurrent credential resolutions]:value:' \
		'--json[Output JSON]' \
		'--bench[Send one live benchmark request per OAuth account]' \
		':model:_files'
}

_omp_cmd_find() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'*'{-k,--keyword}'[Extra lexical keyword (repeatable, or comma-separated)]:file:_files' \
		'--hidden[Include dot-files and dot-folders]' \
		'--json[Emit the full result as JSON]' \
		'(-q --quiet)'{-q,--quiet}'[Suppress progress on stderr]' \
		':query:_files' \
		':path:_files'
}

_omp_cmd_gallery() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'*--surface[Render only tool, composer, or segment surfaces (repeatable; default  all)]:value:(tool composer segment all)' \
		'(-t --tool)'{-t,--tool}'[Render a single tool by name]:file:_files' \
		'--composer[Render a single composer shape by name]:file:_files' \
		'--segment[Render a single status-line segment by name]:file:_files' \
		'*'{-s,--state}'[Render only the given lifecycle state(s)]:value:(streaming streaming args progress in progress success done error failed)' \
		'(-w --width)'{-w,--width}'[Render width in columns]:value:' \
		'(-e --expanded)'{-e,--expanded}'[Render the expanded variant of each renderer]' \
		'--plain[Strip ANSI styling from the output]' \
		'--screenshot[Capture the rendered output as PNG screenshot(s) via VHS instead of printing ANSI (requires vhs)]' \
		'(-o --out)'{-o,--out}'[Screenshot output path (with --screenshot); suffixed per image when split across multiple]:file:_files' \
		'--font[Screenshot font family (default  JetBrainsMono Nerd Font)]:file:_files' \
		'--font-size[Screenshot font size in points (default  18)]:value:'
}

_omp_cmd_gc() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'--apply[Apply changes (default is dry-run)]' \
		'--json[Output JSON]' \
		'--agent-dir[Agent directory to maintain]:file:_files' \
		'--blobs[Sweep unreferenced blobs]' \
		'--archive[Archive cold sessions]' \
		'--wal[Checkpoint history/model database WAL files]' \
		'--cold-archive-after-days[Minimum session age before archiving]:value:' \
		'--retain-newest-global[Always keep this many newest sessions active]:value:' \
		'--retain-newest-per-cwd[Always keep this many newest sessions per cwd active]:value:'
}

_omp_cmd_git() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'(-C --dir)'{-C,--dir}'[Run in another directory instead of the current one]:file:_files' \
		':revision:_files'
}

_omp_cmd_grep() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'(-g --glob)'{-g,--glob}'[Filter files by glob pattern]:file:_files' \
		'(-l --limit)'{-l,--limit}'[Max matches]:value:' \
		'(-C --context)'{-C,--context}'[Context lines]:value:' \
		'(-f --files)'{-f,--files}'[Output file names only]' \
		'(-c --count)'{-c,--count}'[Output match counts per file]' \
		'--no-gitignore[Include files excluded by .gitignore]' \
		':pattern:_files' \
		':path:_files'
}

_omp_cmd_grievances() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'(-n --limit)'{-n,--limit}'[Number of recent issues to show (list)]:value:' \
		'(-t --tool)'{-t,--tool}'[Filter by tool name (list, clean)]:file:_files' \
		'(-j --json)'{-j,--json}'[Output as JSON]' \
		'--id[Delete a single grievance by id (clean)]:value:' \
		'--all[Delete every grievance (clean)]' \
		':action:(list clean push)'
}

_omp_cmd_if_bench() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'--turns[Maximum turns per model; turn N issues N actions (default  24)]:value:' \
		'--length[Character-array length, even, 8-26 (default  24)]:value:' \
		'--max-tokens[Max output tokens per turn (default  32768)]:value:' \
		'--nya-max[Longest accepted cat sound in nya{1,N} (default  8)]:value:' \
		'--par[Models benchmarked concurrently (default  4)]:value:' \
		'--json[Output JSON]' \
		':models:_files'
}

_omp_cmd_images() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'--json[Output one JSON document]' \
		'--apply[Apply purge deletions (default is dry-run)]' \
		'--all[Purge all entries instead of expired entries only]' \
		'--dir[Project directory (default  current directory)]:file:_files' \
		'--timeout[External health probe timeout in seconds]:value:' \
		':action:(status doctor probe purge)'
}

_omp_cmd_install() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'--json[Output JSON]' \
		'--force[Force install]' \
		'--dry-run[Show actions without applying changes]' \
		'--scope[Install scope  "user" (default) or "project" (marketplace installs only)]:value:(user project)' \
		':targets:_files'
}

_omp_cmd_join() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		':link:_files'
}

_omp_cmd_login() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		':provider:_files'
}

_omp_cmd_models() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'--json[Output JSON]' \
		'--kind[Catalog kind to list]:value:(chat tiny image tts stt search judge embedding rerank video all)' \
		'*'{-e,--extension}'[Load an extension file before listing (repeatable)]:file:_files' \
		'--no-extensions[Disable extension discovery (explicit -e paths still work)]' \
		'*--config[Load an extra config.yml-style overlay for this run (repeatable)]:file:_files' \
		':action:_files' \
		':pattern:_files'
}

_omp_cmd_play() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'(-s --speed)'{-s,--speed}'[Playback speed multiplier (default  1)]:file:_files' \
		'(-i --idle-limit)'{-i,--idle-limit}'[Cap pauses between frames to this many seconds]:file:_files' \
		':file:_files'
}

_omp_cmd_plugin() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'--json[Output JSON]' \
		'--fix[Attempt to fix issues (doctor)]' \
		'--force[Force install]' \
		'--dry-run[Show actions without applying changes]' \
		'(-l --local)'{-l,--local}'[Operate on local plugin directory]' \
		'--enable[Enable a feature]:file:_files' \
		'--disable[Disable a feature]:file:_files' \
		'--set[Set plugin config (key=value)]:file:_files' \
		'--scope[Install scope  "user" (default) or "project"]:value:(user project)' \
		':action:(install uninstall list link doctor features config enable disable marketplace discover upgrade)' \
		':targets:_files'
}

_omp_cmd_predict() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]'
}

_omp_cmd_ps() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'(-a --all)'{-a,--all}'[Also list other projects and exited global services (list)]' \
		'(-j --json)'{-j,--json}'[Emit machine-readable JSON]' \
		'--plain[Static listing instead of the interactive monitor (list)]' \
		'--dir[Target another project directory instead of the current one]:file:_files' \
		'--global[Target a machine-global service scope (e.g. browser-relay)]:file:_files' \
		'(-f --follow)'{-f,--follow}'[Keep streaming new output (logs)]' \
		'--head[Read from the beginning instead of the tail (logs)]' \
		'(-n --lines)'{-n,--lines}'[Number of log lines, max 1000 (logs)]:value:' \
		'--grep[Regex filter applied to log lines (logs)]:file:_files' \
		'--timeout[Grace period in seconds before hard kill (stop)]:value:' \
		':action:(list info logs stop kill restart)' \
		':name:_files'
}

_omp_cmd_read() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		':path:_files'
}

_omp_cmd_render() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'(-w --width)'{-w,--width}'[Render width in columns (default  terminal width)]:value:' \
		'--height[Viewport height in rows (default  terminal height)]:value:' \
		'(-t --timing)'{-t,--timing}'[Print phase timings and emitted byte counts to stderr]' \
		'--repaint[Benchmark N extra full clear-scrollback repaints (the /tree navigation frame)]:value:' \
		'--plain[Strip ANSI styling from the output]' \
		'(-q --quiet)'{-q,--quiet}'[Suppress transcript output (benchmark runs)]' \
		':session:_files'
}

_omp_cmd_say() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'--voice[Voice id]:value:(af_heart af_bella af_nicole af_aoede af_kore af_sarah am_michael am_fenrir am_puck bf_emma bm_george bm_fable)' \
		'--model[Local TTS model key]:model:_omp_call models' \
		'(-f --file)'{-f,--file}'[Read the text to speak from this file]:file:_files' \
		'(-o --out)'{-o,--out}'[Write WAV to this path instead of playing]:file:_files' \
		':text:_files'
}

_omp_cmd_search() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'--model[Catalog model selector]:model:_omp_call models' \
		'--recency[Recency filter]:value:(day week month year)' \
		'(-l --limit)'{-l,--limit}'[Max results to return]:value:' \
		'--compact[Render condensed output]' \
		':query:_files'
}

_omp_cmd_setup() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'(-c --check)'{-c,--check}'[Check if dependencies are installed]' \
		'--json[Output status as JSON]' \
		':component:(python speech)'
}

_omp_cmd_share() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'--gist[Upload to a secret GitHub gist instead of the share server]' \
		':session:_files'
}

_omp_cmd_shell() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'(-C --cwd)'{-C,--cwd}'[Set working directory for commands]:file:_files' \
		'(-t --timeout)'{-t,--timeout}'[Timeout per command in milliseconds]:value:' \
		'--no-snapshot[Skip sourcing snapshot from user shell]'
}

_omp_cmd_skill() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'(-g --global)'{-g,--global}'[Use the user-global skills.json (install/update/uninstall)]' \
		'(-y --yes)'{-y,--yes}'[Install or update skills that ship scripts without asking]' \
		'--json[Output JSON (search, info, token, list)]' \
		'--sort[Search order]:value:(relevance downloads recent)' \
		'--scope[Publishing scope (default  your Stencil username)]:file:_files' \
		'--tag[Dist-tag for the published version]:file:_files' \
		'--dry-run[Pack and validate without publishing]' \
		'--allow-secrets[Publish even when credential-shaped strings are found]' \
		'--registry[Registry base URL (overrides skills.registryUrl)]:file:_files' \
		'--undo[Reverse a yank or deprecation]' \
		'*--package[Restrict a new token to a package (repeatable)]:file:_files' \
		'--expires[Token lifetime in days]:value:' \
		':action:(publish version tag yank deprecate owner token import install update uninstall search info list)' \
		':targets:_files'
}

_omp_cmd_ssh() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'--json[Output JSON]' \
		'--host[Host address]:file:_files' \
		'--user[Username]:file:_files' \
		'--port[Port number]:file:_files' \
		'--key[Identity key path]:file:_files' \
		'--desc[Host description]:file:_files' \
		'--compat[Enable compatibility mode]' \
		'--scope[Config scope (project|user)]:value:(project user)' \
		':action:(add remove list)' \
		':targets:_files'
}

_omp_cmd_stats() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'(-p --port)'{-p,--port}'[Port for the dashboard server]:value:' \
		'--host[Host to bind]:file:_files' \
		'(-j --json)'{-j,--json}'[Output stats as JSON]' \
		'(-s --summary)'{-s,--summary}'[Print summary to console]'
}

_omp_cmd_stream() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'--title[Stream title (defaults to the current directory name)]:file:_files' \
		'--server[Stream server base URL (overrides stream.serverUrl)]:file:_files' \
		'--no-tui[Use the line-oriented console instead of the interactive TUI]'
}

_omp_cmd_tiny_models() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'--json[Output JSON]' \
		':action:(download list)' \
		':model:_files'
}

_omp_cmd_token() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'--raw[Output the raw credential value without parsing nested JSON structures]' \
		'--force-refresh[Force refresh the OAuth token even if it has not expired]' \
		'(-a --account)'{-a,--account}'[Select the Nth OAuth account (1-based) in stored order instead of the round-robin default]:value:' \
		'(-l --list)'{-l,--list}'[List the provider’s OAuth accounts (index + identity) and exit]' \
		':provider:_files'
}

_omp_cmd_toks() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'--json[Output JSON]' \
		':input:_files'
}

_omp_cmd_ttsr() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'--file[Snippet file path, or - for stdin (ttsr test)]:file:_files' \
		'(-r --rule)'{-r,--rule}'[Rule markdown file to test in isolation (skips project rule loading)]:file:_files' \
		'--source[Match source  text, thinking, or tool (inferred from --file when omitted)]:value:(text thinking tool)' \
		'--tool[Tool name when source is tool (e.g. edit, write); defaults to edit]:file:_files' \
		'(-p --path)'{-p,--path}'[Candidate file path for scope/glob matching and AST language inference]:file:_files' \
		'--agent[Agent name to evaluate rule `agents` scoping as (ttsr test); defaults to main]:file:_files' \
		'(-v --verbose)'{-v,--verbose}'[Show every evaluated rule, not just triggered ones]' \
		'--json[Output JSON]' \
		'--no-gitignore[Include files excluded by .gitignore (ttsr scan)]' \
		'--max-bytes[Maximum file size to scan in bytes; 0 disables the limit (ttsr scan)]:value:' \
		':action:(test list scan)' \
		':snippet:_files'
}

_omp_cmd_update() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'(-f --force)'{-f,--force}'[Force update]' \
		'(-c --check)'{-c,--check}'[Check for updates without installing]' \
		'(-l --plugins)'{-l,--plugins}'[Update installed plugins]' \
		'--canary[Switch to the canary channel and update]' \
		'--stable[Switch back to the stable channel]'
}

_omp_cmd_usage() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'(-j --json)'{-j,--json}'[Output usage reports as JSON]' \
		'(-p --provider)'{-p,--provider}'[Only show usage for this provider id (e.g. anthropic)]:file:_files' \
		'(-r --redact)'{-r,--redact}'[Redact account emails/ids (shortest unique prefix) for sharing screenshots]' \
		'--history[Show recorded usage-limit history (hourly snapshots) instead of a live snapshot]' \
		'(-d --days)'{-d,--days}'[History window in days (with --history or clients)]:value:' \
		'*'{-e,--extension}'[Load an extension file before fetching usage (repeatable)]:file:_files' \
		'--no-extensions[Disable extension discovery (explicit -e paths still work)]' \
		':action:(invalidate clients)'
}

_omp_cmd_worktree() {
	_arguments -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'(-C --cwd)'{-C,--cwd}'[Repository/base directory (add)]:file:_files' \
		'(-b --branch)'{-b,--branch}'[Create a new branch (add)]:file:_files' \
		'(-B --force-branch)'{-B,--force-branch}'[Create or reset a branch (add)]:file:_files' \
		'(-d --detach)'{-d,--detach}'[Detach HEAD (add)]' \
		'(-q --quiet)'{-q,--quiet}'[Suppress add output]' \
		'--all[Clear every entry, including live PR-checkout worktrees (clear)]' \
		'(-n --dry-run)'{-n,--dry-run}'[Print what would be removed without touching the filesystem (clear)]' \
		'(-j --json)'{-j,--json}'[Emit machine-readable JSON]' \
		':action:(list clear add)' \
		':path:_files' \
		':commit:_files'
}

_omp() {
	local curcontext="$curcontext" state line
	typeset -A opt_args
	_arguments -C -s \
		'(-h --help)'{-h,--help}'[Show help]' \
		'(-v --version)'{-v,--version}'[Show version]' \
		'--model[Model to use (fuzzy match  "opus", "gpt-5.2", or "openai/gpt-5.2")]:model:_omp_call models' \
		'--smol[Smol/fast model for lightweight tasks (or PI_SMOL_MODEL env)]:model:_omp_call models' \
		'--slow[Slow/reasoning model for thorough analysis (or PI_SLOW_MODEL env)]:model:_omp_call models' \
		'--plan[Plan model for architectural planning (or PI_PLAN_MODEL env)]:model:_omp_call models' \
		'--prewalk[Switch from the active model to a fast/cheap model at the first edit/write after the plan’s todo list exists (default off; see prewalk.enabled)]' \
		'--no-prewalk[Disable prewalk even if prewalk.enabled is set]' \
		'--prewalk-into[Target model for prewalk (default the "smol" role)]:file:_files' \
		'--plan-yolo[Force read-only plan mode at start, auto-approve the plan on the model’s first resolve call, then switch to --plan-yolo-into to implement it]' \
		'--plan-yolo-into[Target model for plan-yolo execution (default the "smol" role)]:file:_files' \
		'--provider[Provider to use (legacy; prefer --model)]:file:_files' \
		'--api-key[API key (defaults to env vars)]:file:_files' \
		'--system-prompt[System prompt (default  coding assistant prompt)]:file:_files' \
		'--system-prompt-template[Handlebars system prompt template (mutually exclusive with --system-prompt)]:file:_files' \
		'--append-system-prompt[Append text or file contents to the system prompt]:file:_files' \
		'--allow-home[Allow starting in ~ without auto-switching to a temp dir]' \
		'--profile[Use an isolated profile for auth, sessions, settings, and caches]:file:_files' \
		'--alias[Create a shell shortcut for the selected profile and exit]:file:_files' \
		'--cwd[Directory to start in (overrides the launch cwd)]:file:_files' \
		'--mode[Output mode  text (default), json, rpc, or rpc-ui]:value:(text json rpc acp rpc-ui)' \
		'*--config[Load an extra config.yml-style overlay for this run (repeatable)]:file:_files' \
		'*--add-dir[Add a workspace directory beyond the working directory (repeatable)]:file:_files' \
		'(-p --print)'{-p,--print}'[Non-interactive mode  process prompt and exit]' \
		'(-c --continue)'{-c,--continue}'[Continue previous session]' \
		'(-r --resume)'{-r,--resume}'[Resume a session (by ID prefix, path, or picker if omitted)]:session:_omp_call sessions' \
		'--from-claude[Import a Claude Code session into OMP]' \
		'--from-codex[Import a Codex session into OMP]' \
		'--session-dir[Directory for session storage and lookup]:dir:_files -/' \
		'--no-session[Don’t save session (ephemeral)]' \
		'--models[Comma-separated model patterns for Ctrl+P cycling]:models:_omp_models_list' \
		'--no-tools[Disable all built-in tools]' \
		'--no-lsp[Disable LSP tools, formatting, and diagnostics]' \
		'--no-pty[Disable PTY-based interactive bash execution]' \
		'--tools[Comma-separated list of tools to enable (default  all)]:value:_omp_tools' \
		'--thinking[Set thinking level  off, minimal, low, medium, high, xhigh, max, auto]:value:(off minimal low medium high xhigh max auto)' \
		'--service-tier[OpenAI service tier for this session (none omits service_tier)]:value:(none auto default flex scale priority)' \
		'--hide-thinking[Hide thinking blocks in TUI output (display only, does not disable model thinking)]' \
		'--advisor[Enable the advisor runtime (passively reviews each turn and injects notes)]' \
		'--external-thinking[Use a private scratchpad while disabling supported GPT, Claude, and Gemini reasoning (at your own risk  providers have flagged this request shape as abuse)]' \
		'*--hook[Load a hook/extension file (can be used multiple times)]:file:_files' \
		'*'{-e,--extension}'[Load an extension file (can be used multiple times)]:file:_files' \
		'--no-extensions[Disable extension discovery (explicit -e paths still work)]' \
		'--no-skills[Disable skills discovery and loading]' \
		'--skills[Comma-separated glob patterns to filter skills (e.g., git-*,docker)]:file:_files' \
		'--no-rules[Disable rules discovery and loading]' \
		'--export[Export session file to HTML and exit]:file:_files' \
		'--no-title[Disable title auto-generation]' \
		'--no-ui[With --mode rpc  run extensions headless (no extension_ui_request dialogs for the host)]' \
		'--print-thoughts[Include thinking blocks in print mode text output]' \
		'--max-time[Stop the session after this duration (e.g., 600, 10m, 1h)]:file:_files' \
		'--auto-approve[Auto-approve all tool calls (skip approval prompts)]' \
		'--approval-mode[Override tools.approvalMode for this session (always-ask|write|yolo)]:value:(always-ask write yolo)' \
		'1: :_omp_commands' \
		'*::arg:->args'
	case $state in
		args)
			case $line[1] in
			acp) _omp_cmd_acp ;;
			agents) _omp_cmd_agents ;;
			auth-broker) _omp_cmd_auth_broker ;;
			auth-gateway) _omp_cmd_auth_gateway ;;
			bench) _omp_cmd_bench ;;
			browser-relay) _omp_cmd_browser_relay ;;
			cleanse) _omp_cmd_cleanse ;;
			clip) _omp_cmd_clip ;;
			collab) _omp_cmd_collab ;;
			commit) _omp_cmd_commit ;;
			completions) _omp_cmd_completions ;;
			compress) _omp_cmd_compress ;;
			config) _omp_cmd_config ;;
			dry-balance) _omp_cmd_dry_balance ;;
			find) _omp_cmd_find ;;
			gallery) _omp_cmd_gallery ;;
			gc) _omp_cmd_gc ;;
			git) _omp_cmd_git ;;
			grep) _omp_cmd_grep ;;
			grievances) _omp_cmd_grievances ;;
			if-bench) _omp_cmd_if_bench ;;
			images|img) _omp_cmd_images ;;
			install) _omp_cmd_install ;;
			join) _omp_cmd_join ;;
			login) _omp_cmd_login ;;
			models) _omp_cmd_models ;;
			play) _omp_cmd_play ;;
			plugin|plugins) _omp_cmd_plugin ;;
			predict) _omp_cmd_predict ;;
			ps) _omp_cmd_ps ;;
			read) _omp_cmd_read ;;
			render) _omp_cmd_render ;;
			say) _omp_cmd_say ;;
			search|q|web-search) _omp_cmd_search ;;
			setup) _omp_cmd_setup ;;
			share) _omp_cmd_share ;;
			shell) _omp_cmd_shell ;;
			skill|skills) _omp_cmd_skill ;;
			ssh) _omp_cmd_ssh ;;
			stats) _omp_cmd_stats ;;
			stream) _omp_cmd_stream ;;
			tiny-models) _omp_cmd_tiny_models ;;
			token) _omp_cmd_token ;;
			toks) _omp_cmd_toks ;;
			ttsr) _omp_cmd_ttsr ;;
			update) _omp_cmd_update ;;
			usage) _omp_cmd_usage ;;
			worktree|wt) _omp_cmd_worktree ;;
			esac
			;;
	esac
}
# Works both ways: autoloaded from $fpath (file named _omp) or eval'd from a
# startup file. When autoloaded, funcstack[1] is _omp and we invoke it; when
# sourced/eval'd we register it with compdef instead.
if [ "$funcstack[1]" = "_omp" ]; then
	_omp "$@"
else
	compdef _omp omp
fi

