llmctl-cli 0.4.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
llmctl/completions.py ADDED
@@ -0,0 +1,321 @@
1
+ """Shell completion generators for Bash, Zsh, Fish, and PowerShell."""
2
+
3
+ from __future__ import annotations
4
+
5
+ SUBCOMMANDS: list[tuple[str, str]] = [
6
+ ("add", "Añadir o buscar modelos GGUF en Hugging Face"),
7
+ ("set", "Modificar o quitar opciones de un preset en models.ini"),
8
+ ("rm", "Eliminar un preset y opcionalmente su caché"),
9
+ ("ls", "Listar presets configurados y tamaño de caché"),
10
+ ("ps", "Ver modelos cargados y disponibles en el router"),
11
+ ("pull", "Pre-descargar y cargar un modelo vía llama-server"),
12
+ ("clean", "Detectar y limpiar modelos huérfanos en caché"),
13
+ ("chat", "Chatear en terminal con streaming SSE y soporte de pipes"),
14
+ ("bench", "Comparar rendimiento (TTFT y tok/s) entre modelos"),
15
+ ("test", "Probar capacidades y velocidad de un modelo"),
16
+ ("gpu", "Mostrar uso de VRAM/Metal/Vulkan, CPU y RAM"),
17
+ ("doctor", "Comprobar dependencias, hardware, perfil y servicio"),
18
+ ("free", "Descargar modelo activo de la VRAM"),
19
+ ("on", "Iniciar llama-server"),
20
+ ("off", "Detener llama-server"),
21
+ ("restart", "Reiniciar llama-server"),
22
+ ("status", "Ver estado del servicio y del endpoint"),
23
+ ("logs", "Mostrar logs de llama-server"),
24
+ ("config", "Abrir o inspeccionar models.ini / config.toml"),
25
+ ("profile", "Gestionar perfiles locales y remotos (con API key)"),
26
+ ("server", "Instalar o actualizar binarios oficiales de llama.cpp"),
27
+ ("service", "Instalar, desinstalar o inspeccionar el backend de servicio"),
28
+ ("skill", "Gestionar, importar y ejecutar skills centralizadas"),
29
+ ("completion", "Generar autocompletado para bash, zsh, fish o powershell"),
30
+ ]
31
+
32
+ TEST_FLAGS = ["--text", "--vision", "--tools", "--embed", "--fim", "--all"]
33
+ SKILL_SUBCOMMANDS = ["add", "import", "list", "rm", "run"]
34
+ SERVICE_SUBCOMMANDS = ["install", "uninstall", "info"]
35
+ PROFILE_SUBCOMMANDS = ["list", "set", "use", "rm"]
36
+ SERVER_SUBCOMMANDS = ["install", "update", "info"]
37
+ SHELLS = ["bash", "zsh", "fish", "powershell"]
38
+
39
+
40
+ def generate_bash() -> str:
41
+ cmds = " ".join(name for name, _ in SUBCOMMANDS)
42
+ test_flags = " ".join(TEST_FLAGS)
43
+ skill_cmds = " ".join(SKILL_SUBCOMMANDS)
44
+ service_cmds = " ".join(SERVICE_SUBCOMMANDS)
45
+ profile_cmds = " ".join(PROFILE_SUBCOMMANDS)
46
+ server_cmds = " ".join(SERVER_SUBCOMMANDS)
47
+ shells = " ".join(SHELLS)
48
+ return f"""# Bash completion for llmctl
49
+ _llmctl_aliases() {{
50
+ llmctl ls --names-only 2>/dev/null
51
+ }}
52
+
53
+ _llmctl_skills() {{
54
+ llmctl skill list --names-only 2>/dev/null
55
+ }}
56
+
57
+ _llmctl_complete() {{
58
+ local cur prev cmd
59
+ COMPREPLY=()
60
+ cur="${{COMP_WORDS[COMP_CWORD]}}"
61
+ prev="${{COMP_WORDS[COMP_CWORD-1]}}"
62
+ cmd="${{COMP_WORDS[1]}}"
63
+
64
+ if [[ $COMP_CWORD -eq 1 ]]; then
65
+ COMPREPLY=( $(compgen -W "{cmds} --help --version --interactive --json" -- "$cur") )
66
+ return 0
67
+ fi
68
+
69
+ case "$cmd" in
70
+ rm|borrar|pull|set|chat|bench)
71
+ COMPREPLY=( $(compgen -W "$(_llmctl_aliases)" -- "$cur") )
72
+ ;;
73
+ test)
74
+ if [[ $COMP_CWORD -eq 2 ]]; then
75
+ COMPREPLY=( $(compgen -W "$(_llmctl_aliases)" -- "$cur") )
76
+ else
77
+ COMPREPLY=( $(compgen -W "{test_flags}" -- "$cur") )
78
+ fi
79
+ ;;
80
+ skill)
81
+ if [[ $COMP_CWORD -eq 2 ]]; then
82
+ COMPREPLY=( $(compgen -W "{skill_cmds}" -- "$cur") )
83
+ elif [[ $COMP_CWORD -eq 3 && ( "${{COMP_WORDS[2]}}" == "run" || "${{COMP_WORDS[2]}}" == "rm" ) ]]; then
84
+ COMPREPLY=( $(compgen -W "$(_llmctl_skills)" -- "$cur") )
85
+ elif [[ $COMP_CWORD -eq 4 && "${{COMP_WORDS[2]}}" == "run" ]]; then
86
+ COMPREPLY=( $(compgen -W "$(_llmctl_aliases)" -- "$cur") )
87
+ fi
88
+ ;;
89
+ service)
90
+ COMPREPLY=( $(compgen -W "{service_cmds}" -- "$cur") )
91
+ ;;
92
+ profile)
93
+ COMPREPLY=( $(compgen -W "{profile_cmds}" -- "$cur") )
94
+ ;;
95
+ server)
96
+ COMPREPLY=( $(compgen -W "{server_cmds}" -- "$cur") )
97
+ ;;
98
+ completion)
99
+ COMPREPLY=( $(compgen -W "{shells}" -- "$cur") )
100
+ ;;
101
+ esac
102
+ }}
103
+
104
+ complete -F _llmctl_complete llmctl
105
+ """
106
+
107
+
108
+ def generate_zsh() -> str:
109
+ entries = "\n".join(f" '{name}:{desc}'" for name, desc in SUBCOMMANDS)
110
+ return f"""#compdef llmctl
111
+
112
+ _llmctl_aliases() {{
113
+ local -a aliases
114
+ aliases=(${{(f)"$(llmctl ls --names-only 2>/dev/null)"}})
115
+ (( ${{#aliases}} )) && _describe 'modelo' aliases
116
+ }}
117
+
118
+ _llmctl_skills() {{
119
+ local -a skills
120
+ skills=(${{(f)"$(llmctl skill list --names-only 2>/dev/null)"}})
121
+ (( ${{#skills}} )) && _describe 'skill' skills
122
+ }}
123
+
124
+ _llmctl() {{
125
+ local curcontext="$curcontext" state line
126
+ typeset -A opt_args
127
+
128
+ _arguments -C \\
129
+ '1:comando:->cmds' \\
130
+ '*::arg:->args'
131
+
132
+ case "$state" in
133
+ cmds)
134
+ local -a subcmds
135
+ subcmds=(
136
+ {entries}
137
+ )
138
+ _describe 'subcomando' subcmds
139
+ ;;
140
+ args)
141
+ case "$line[1]" in
142
+ rm|borrar|pull|set|chat|bench)
143
+ (( CURRENT == 2 )) && _llmctl_aliases
144
+ ;;
145
+ test)
146
+ if (( CURRENT == 2 )); then
147
+ _llmctl_aliases
148
+ else
149
+ local -a flags
150
+ flags=(
151
+ '--text:Probar generación de texto o razonamiento'
152
+ '--vision:Probar visión con imagen y mmproj'
153
+ '--tools:Probar tool calling / function calling'
154
+ '--embed:Probar embeddings en /v1/embeddings'
155
+ '--fim:Probar autocompletado en /infill'
156
+ '--all:Ejecutar toda la batería de tests'
157
+ )
158
+ _describe 'flag' flags
159
+ fi
160
+ ;;
161
+ skill)
162
+ if (( CURRENT == 2 )); then
163
+ local -a s_cmds
164
+ s_cmds=(
165
+ 'add:Instalar skill desde GitHub o ruta local'
166
+ 'import:Importar skills locales al almacén central'
167
+ 'list:Listar skills instaladas'
168
+ 'rm:Eliminar una skill instalada'
169
+ 'run:Ejecutar una skill contra el servidor LLM'
170
+ )
171
+ _describe 'acción' s_cmds
172
+ elif (( CURRENT == 3 )) && [[ "$line[2]" == "run" || "$line[2]" == "rm" ]]; then
173
+ _llmctl_skills
174
+ elif (( CURRENT == 4 )) && [[ "$line[2]" == "run" ]]; then
175
+ _llmctl_aliases
176
+ fi
177
+ ;;
178
+ service)
179
+ local -a svc_cmds
180
+ svc_cmds=(
181
+ 'install:Instalar definición de servicio del SO'
182
+ 'uninstall:Eliminar definición de servicio del SO'
183
+ 'info:Mostrar detalles del backend activo'
184
+ )
185
+ _describe 'servicio' svc_cmds
186
+ ;;
187
+ profile)
188
+ local -a prof_cmds
189
+ prof_cmds=(
190
+ 'list:Listar perfiles configurados'
191
+ 'set:Crear o actualizar un perfil'
192
+ 'use:Activar un perfil'
193
+ 'rm:Eliminar un perfil'
194
+ )
195
+ _describe 'perfil' prof_cmds
196
+ ;;
197
+ server)
198
+ local -a srv_cmds
199
+ srv_cmds=(
200
+ 'install:Descargar e instalar binario oficial de llama.cpp'
201
+ 'update:Actualizar llama-server a la última release'
202
+ 'info:Ver binario detectado y gestionado'
203
+ )
204
+ _describe 'servidor' srv_cmds
205
+ ;;
206
+ completion)
207
+ local -a shells
208
+ shells=('bash' 'zsh' 'fish' 'powershell')
209
+ _describe 'shell' shells
210
+ ;;
211
+ esac
212
+ ;;
213
+ esac
214
+ }}
215
+
216
+ _llmctl "$@"
217
+ """
218
+
219
+
220
+ def generate_fish() -> str:
221
+ lines = ["# Fish completion for llmctl"]
222
+ for name, desc in SUBCOMMANDS:
223
+ escaped = desc.replace("'", "\\'")
224
+ lines.append(f"complete -c llmctl -n '__fish_use_subcommand' -a '{name}' -d '{escaped}'")
225
+ lines.extend(
226
+ [
227
+ "complete -c llmctl -n '__fish_seen_subcommand_from rm pull test set chat bench' -a '(llmctl ls --names-only 2>/dev/null)'",
228
+ "complete -c llmctl -n '__fish_seen_subcommand_from test' -l text -d 'Test de texto'",
229
+ "complete -c llmctl -n '__fish_seen_subcommand_from test' -l vision -d 'Test de visión'",
230
+ "complete -c llmctl -n '__fish_seen_subcommand_from test' -l tools -d 'Test de tools'",
231
+ "complete -c llmctl -n '__fish_seen_subcommand_from test' -l embed -d 'Test de embeddings'",
232
+ "complete -c llmctl -n '__fish_seen_subcommand_from test' -l fim -d 'Test FIM /infill'",
233
+ "complete -c llmctl -n '__fish_seen_subcommand_from test' -l all -d 'Todos los tests'",
234
+ "complete -c llmctl -n '__fish_seen_subcommand_from skill' -a 'add import list rm run'",
235
+ "complete -c llmctl -n '__fish_seen_subcommand_from service' -a 'install uninstall info'",
236
+ "complete -c llmctl -n '__fish_seen_subcommand_from profile' -a 'list set use rm'",
237
+ "complete -c llmctl -n '__fish_seen_subcommand_from server' -a 'install update info'",
238
+ "complete -c llmctl -n '__fish_seen_subcommand_from completion' -a 'bash zsh fish powershell'",
239
+ ]
240
+ )
241
+ return "\n".join(lines) + "\n"
242
+
243
+
244
+ def generate_powershell() -> str:
245
+ cmds_ps = ", ".join(f"'{name}'" for name, _ in SUBCOMMANDS)
246
+ test_flags_ps = ", ".join(f"'{flag}'" for flag in TEST_FLAGS)
247
+ skill_ps = ", ".join(f"'{c}'" for c in SKILL_SUBCOMMANDS)
248
+ service_ps = ", ".join(f"'{c}'" for c in SERVICE_SUBCOMMANDS)
249
+ profile_ps = ", ".join(f"'{c}'" for c in PROFILE_SUBCOMMANDS)
250
+ server_ps = ", ".join(f"'{c}'" for c in SERVER_SUBCOMMANDS)
251
+ shells_ps = ", ".join(f"'{s}'" for s in SHELLS)
252
+ return f"""# PowerShell completion for llmctl
253
+ Register-ArgumentCompleter -Native -CommandName llmctl -ScriptBlock {{
254
+ param($wordToComplete, $commandAst, $cursorPosition)
255
+ $tokens = $commandAst.CommandElements | ForEach-Object {{ $_.ToString() }}
256
+ $count = $tokens.Count
257
+
258
+ $commands = @({cmds_ps})
259
+ if ($count -le 2 -and ($count -eq 1 -or $wordToComplete -ne '')) {{
260
+ $commands | Where-Object {{ $_ -like "$wordToComplete*" }} | ForEach-Object {{
261
+ [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
262
+ }}
263
+ return
264
+ }}
265
+
266
+ $cmd = $tokens[1]
267
+ switch ($cmd) {{
268
+ {{ $_ -in 'rm', 'pull', 'test', 'set', 'chat', 'bench' }} {{
269
+ if ($count -le 3) {{
270
+ $aliases = @(llmctl ls --names-only 2>$null)
271
+ $aliases | Where-Object {{ $_ -like "$wordToComplete*" }} | ForEach-Object {{
272
+ [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
273
+ }}
274
+ }} elseif ($cmd -eq 'test') {{
275
+ @({test_flags_ps}) | Where-Object {{ $_ -like "$wordToComplete*" }} | ForEach-Object {{
276
+ [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
277
+ }}
278
+ }}
279
+ }}
280
+ 'skill' {{
281
+ @({skill_ps}) | Where-Object {{ $_ -like "$wordToComplete*" }} | ForEach-Object {{
282
+ [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
283
+ }}
284
+ }}
285
+ 'service' {{
286
+ @({service_ps}) | Where-Object {{ $_ -like "$wordToComplete*" }} | ForEach-Object {{
287
+ [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
288
+ }}
289
+ }}
290
+ 'profile' {{
291
+ @({profile_ps}) | Where-Object {{ $_ -like "$wordToComplete*" }} | ForEach-Object {{
292
+ [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
293
+ }}
294
+ }}
295
+ 'server' {{
296
+ @({server_ps}) | Where-Object {{ $_ -like "$wordToComplete*" }} | ForEach-Object {{
297
+ [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
298
+ }}
299
+ }}
300
+ 'completion' {{
301
+ @({shells_ps}) | Where-Object {{ $_ -like "$wordToComplete*" }} | ForEach-Object {{
302
+ [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
303
+ }}
304
+ }}
305
+ }}
306
+ }}
307
+ """
308
+
309
+
310
+ def generate_completion(shell: str) -> str:
311
+ """Return completion script text for the requested shell."""
312
+ normalized = shell.strip().lower()
313
+ if normalized == "bash":
314
+ return generate_bash()
315
+ if normalized == "zsh":
316
+ return generate_zsh()
317
+ if normalized == "fish":
318
+ return generate_fish()
319
+ if normalized in {"powershell", "pwsh"}:
320
+ return generate_powershell()
321
+ raise ValueError(f"Shell no soportada: {shell!r}. Usa bash, zsh, fish o powershell.")