package main func powerShellCompletionScript() string { return `# GSP PowerShell completion $script:GspSubcommands = @( 'init', 'ai-init', 'version', 'completion', 'validate', 'index', 'fields', 'trace', 'flatten', 'pack', 'links', 'impact', 'message', 'graph', 'stage-check', 'help' ) $script:GspFlags = @{ 'init' = @('--name', '--entry', '--force') 'ai-init' = @('--root', '--agents', '--skill', '--all', '--force') 'version' = @('--json') 'completion' = @('powershell', 'bash', 'zsh', 'fish', 'install') 'validate' = @('--root', '--out') 'index' = @('--root', '--out') 'fields' = @('list', 'validate') 'trace' = @('--root', '--depth', '--out') 'flatten' = @('--root', '--depth', '--include-type', '--exclude-type', '--out') 'pack' = @('--root', '--for', '--stage', '--depth', '--budget', '--format', '--include-type', '--exclude-type', '--out') 'links' = @('--root', '--depth', '--format', '--out') 'impact' = @('--root', '--depth', '--format', '--out') 'message' = @('validate') 'graph' = @('--root', '--depth', '--format', '--out') 'stage-check' = @('--stage', '--root', '--out') } function script:Get-GspIds { try { $json = & gsp index --root . 2>$null if (-not $json) { return @() } $items = $json | ConvertFrom-Json return @($items | ForEach-Object { $_.id }) } catch { return @() } } function script:New-GspCompletion($value, $tooltip = $null) { if (-not $tooltip) { $tooltip = $value } [System.Management.Automation.CompletionResult]::new($value, $value, 'ParameterValue', $tooltip) } Register-ArgumentCompleter -Native -CommandName gsp -ScriptBlock { param($wordToComplete, $commandAst, $cursorPosition) $words = @($commandAst.CommandElements | ForEach-Object { $_.ToString() }) if ($words.Count -le 1) { return $script:GspSubcommands | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { New-GspCompletion $_ } } $command = $words[1] if ($words.Count -eq 2 -and $wordToComplete -ne '') { return $script:GspSubcommands | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { New-GspCompletion $_ } } $previous = '' if ($wordToComplete -eq '' -and $words.Count -ge 1) { $previous = $words[$words.Count - 1] } elseif ($words.Count -ge 2) { $previous = $words[$words.Count - 2] } switch ($previous) { '--format' { $formats = @('json', 'md', 'canvas') if ($command -eq 'graph') { $formats = @('json', 'mermaid', 'md', 'canvas') } elseif ($command -eq 'links') { $formats = @('json', 'md') } return $formats | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { New-GspCompletion $_ } } '--stage' { return @('design', 'integrate', 'implement', 'bind', 'release') | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { New-GspCompletion $_ } } '--skill' { return @('generic', 'codex') | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { New-GspCompletion $_ } } '--for' { return @('design', 'implement', 'review', 'test', 'acceptance', 'handoff', 'inspect') | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { New-GspCompletion $_ } } } if ($command -eq 'completion') { if ($words -contains 'install') { return @('powershell') | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { New-GspCompletion $_ } } return @('powershell', 'bash', 'zsh', 'fish', 'install') | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { New-GspCompletion $_ } } if ($wordToComplete -like '-*') { return @($script:GspFlags[$command]) | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { New-GspCompletion $_ } } if ($command -eq 'message') { return @($script:GspFlags[$command]) | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { New-GspCompletion $_ } } if ($command -eq 'fields') { return @($script:GspFlags[$command]) | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { New-GspCompletion $_ } } if (@('trace', 'flatten', 'pack', 'links', 'impact', 'graph') -contains $command) { return Get-GspIds | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { New-GspCompletion $_ } } return @() } ` } func bashCompletionScript() string { return `# GSP bash completion _gsp_completion() { local cur prev cmd COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" cmd="${COMP_WORDS[1]}" local commands="init ai-init version completion validate index fields trace flatten pack links impact message graph stage-check help" case "$prev" in --format) if [[ "$cmd" == "graph" ]]; then COMPREPLY=( $(compgen -W "json mermaid md canvas" -- "$cur") ) elif [[ "$cmd" == "links" ]]; then COMPREPLY=( $(compgen -W "json md" -- "$cur") ) else COMPREPLY=( $(compgen -W "json md canvas" -- "$cur") ) fi return ;; --stage) COMPREPLY=( $(compgen -W "design integrate implement bind release" -- "$cur") ); return ;; --skill) COMPREPLY=( $(compgen -W "generic codex" -- "$cur") ); return ;; --for) COMPREPLY=( $(compgen -W "design implement review test acceptance handoff inspect" -- "$cur") ); return ;; esac if [[ $COMP_CWORD -eq 1 ]]; then COMPREPLY=( $(compgen -W "$commands" -- "$cur") ) return fi if [[ "$cur" == -* ]]; then case "$cmd" in init) COMPREPLY=( $(compgen -W "--name --entry --force" -- "$cur") ) ;; ai-init) COMPREPLY=( $(compgen -W "--root --agents --skill --all --force" -- "$cur") ) ;; version) COMPREPLY=( $(compgen -W "--json" -- "$cur") ) ;; validate|index) COMPREPLY=( $(compgen -W "--root --out" -- "$cur") ) ;; fields) COMPREPLY=( $(compgen -W "list validate" -- "$cur") ) ;; trace) COMPREPLY=( $(compgen -W "--root --depth --out" -- "$cur") ) ;; flatten) COMPREPLY=( $(compgen -W "--root --depth --include-type --exclude-type --out" -- "$cur") ) ;; pack) COMPREPLY=( $(compgen -W "--root --for --stage --depth --budget --format --include-type --exclude-type --out" -- "$cur") ) ;; links) COMPREPLY=( $(compgen -W "--root --depth --format --out" -- "$cur") ) ;; impact) COMPREPLY=( $(compgen -W "--root --depth --format --out" -- "$cur") ) ;; message) COMPREPLY=( $(compgen -W "validate" -- "$cur") ) ;; graph) COMPREPLY=( $(compgen -W "--root --depth --format --out" -- "$cur") ) ;; stage-check) COMPREPLY=( $(compgen -W "--stage --root --out" -- "$cur") ) ;; completion) COMPREPLY=( $(compgen -W "powershell bash zsh fish install" -- "$cur") ) ;; esac return fi case "$cmd" in trace|flatten|pack|links|impact|graph) local ids ids=$(gsp index --root . 2>/dev/null | sed -n 's/.*"id": "\([^"]*\)".*/\1/p') COMPREPLY=( $(compgen -W "$ids" -- "$cur") ) ;; esac } complete -F _gsp_completion gsp ` } func zshCompletionScript() string { return `#compdef gsp # GSP zsh completion _gsp() { local -a commands commands=( 'init' 'ai-init' 'version' 'completion' 'validate' 'index' 'fields' 'trace' 'flatten' 'pack' 'links' 'impact' 'message' 'graph' 'stage-check' 'help' ) _describe 'command' commands } _gsp "$@" ` } func fishCompletionScript() string { return `# GSP fish completion complete -c gsp -f -n '__fish_use_subcommand' -a 'init ai-init version completion validate index fields trace flatten pack links impact message graph stage-check help' complete -c gsp -n '__fish_seen_subcommand_from fields' -a 'list validate' complete -c gsp -n '__fish_seen_subcommand_from graph' -l format -a 'json mermaid md canvas' complete -c gsp -n '__fish_seen_subcommand_from pack impact' -l format -a 'json md canvas' complete -c gsp -n '__fish_seen_subcommand_from links' -l format -a 'json md' complete -c gsp -n '__fish_seen_subcommand_from stage-check' -l stage -a 'design integrate implement bind release' complete -c gsp -n '__fish_seen_subcommand_from ai-init' -l skill -a 'generic codex' complete -c gsp -n '__fish_seen_subcommand_from pack' -l for -a 'design implement review test acceptance handoff inspect' complete -c gsp -n '__fish_seen_subcommand_from trace flatten pack links impact graph' -a '(gsp index --root . 2>/dev/null | string match -r ''"id": "([^"]+)"'' | string replace -r ''.*"id": "([^"]+)".*'' ''$1'')' ` }