-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathluallm.lua
More file actions
executable file
·703 lines (645 loc) · 29.6 KB
/
luallm.lua
File metadata and controls
executable file
·703 lines (645 loc) · 29.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
#!/usr/bin/env lua
-- Determine script directory for module loading
-- Resolve symlinks so that require() finds modules relative to the real file,
-- not the symlink location (e.g. ~/.local/bin/luallm → /path/to/repo/luallm.lua).
local script_path = arg[0]
do
local handle = io.popen("readlink -f " .. script_path .. " 2>/dev/null || realpath " .. script_path .. " 2>/dev/null || echo " .. script_path)
if handle then
local resolved = handle:read("*l")
handle:close()
if resolved and resolved ~= "" then
script_path = resolved
end
end
end
local script_dir = script_path:match("^(.*)/[^/]+$") or "."
package.path = script_dir .. "/src/?.lua;" ..
script_dir .. "/src/?/init.lua;" ..
script_dir .. "/?.lua;" ..
package.path
-- Set up luarocks path if needed
local function setup_luarocks_path()
local handle = io.popen("luarocks path --lr-path 2>/dev/null")
if handle then
local lr_path = handle:read("*a")
handle:close()
if lr_path and lr_path ~= "" then
package.path = lr_path:gsub("\n", "") .. ";" .. package.path
end
end
handle = io.popen("luarocks path --lr-cpath 2>/dev/null")
if handle then
local lr_cpath = handle:read("*a")
handle:close()
if lr_cpath and lr_cpath ~= "" then
package.cpath = lr_cpath:gsub("\n", "") .. ";" .. package.cpath
end
end
end
setup_luarocks_path()
-- Load modules
local config = require("config")
local util = require("util")
local format = require("format")
local history = require("history")
local pins = require("pins")
local picker = require("picker")
local resolve = require("resolve")
local resolver = require("resolver")
local model_info = require("model_info")
local notes = require("notes")
local bench = require("bench")
local doctor = require("doctor")
local recommend = require("recommend")
local join = require("join")
local state = require("state")
-- Main command dispatcher
local function main(args)
local cfg = config.load_config()
if #args == 0 then
local selected = picker.show_sectioned_picker(cfg)
if selected then
model_info.run_model(cfg, selected, nil)
end
elseif args[1] == "list" then
local models = model_info.list_models(cfg.models_dir)
if args[2] == "--json" then
format.print_model_list_json(models, cfg.models_dir, cfg)
else
print("Available models in " .. util.expand_path(cfg.models_dir) .. ":\n")
format.print_model_list(models, cfg.models_dir, cfg)
end
elseif args[1] == "info" then
model_info.handle_info_command(args, cfg)
elseif args[1] == "config" then
print("Config file: " .. config.CONFIG_FILE)
print("Edit this file to customize settings.")
elseif args[1] == "rebuild" then
model_info.rebuild_llama(cfg)
elseif args[1] == "clear-history" then
history.clear_history()
print("✓ History cleared")
elseif args[1] == "pin" then
pins.handle_pin_command(args, cfg)
elseif args[1] == "unpin" then
pins.handle_unpin_command(args, cfg)
elseif args[1] == "pinned" then
pins.handle_pinned_command(cfg)
elseif args[1] == "notes" then
notes.handle_notes_command(args, cfg)
elseif args[1] == "bench" then
bench.handle_bench_command(args, cfg)
elseif args[1] == "doctor" then
doctor.run(cfg)
elseif args[1] == "recommend" then
recommend.handle_recommend_command(args, cfg)
elseif args[1] == "join" then
join.handle_join_command(args, cfg)
elseif args[1] == "status" then
state.handle_status_command(args, cfg)
elseif args[1] == "stop" then
state.handle_stop_command(args, cfg)
elseif args[1] == "start" then
-- Background daemon launch with optional --preset support
if #args < 2 then
print("Error: missing model name")
print("Usage: luallm start <model> [--preset <profile>] [...extra args]")
os.exit(1)
end
local model_query = args[2]
if model_query:sub(1,1) == "-" then
print("Error: expected a model name but got a flag: " .. model_query)
print("The model name must come first.")
print("Usage: luallm start <model> [--preset <profile>] [...extra args]")
os.exit(1)
end
local preset_name = nil
local extra_args = {}
local i = 3
while i <= #args do
if args[i] == "--preset" and args[i+1] then
preset_name = args[i+1]; i = i + 2
else
table.insert(extra_args, args[i]); i = i + 1
end
end
model_info.start_model_daemon(cfg, model_query, extra_args, preset_name)
elseif args[1] == "logs" then
state.handle_logs_command(args, cfg)
elseif args[1] == "run" then
-- New explicit run command with --preset support
if #args < 2 then
print("Error: Missing model name")
print("Usage: luallm run <model> [--preset <profile>] [...extra args]")
os.exit(1)
end
local model_query = args[2]
local preset_name = nil
local extra_args = {}
-- Parse args looking for --preset
local i = 3
while i <= #args do
if args[i] == "--preset" and args[i + 1] then
preset_name = args[i + 1]
i = i + 2
else
table.insert(extra_args, args[i])
i = i + 1
end
end
local model_name = resolver.resolve_or_exit(cfg, model_query)
model_info.run_model(cfg, model_name, extra_args, preset_name)
elseif args[1] == "help" or args[1] == "--help" or args[1] == "-h" then
print_help(args[2], args[3])
else
local model_query = args[1]
local extra_args = {}
for i = 2, #args do
table.insert(extra_args, args[i])
end
local model_name = resolver.resolve_or_exit(cfg, model_query)
model_info.run_model(cfg, model_name, extra_args)
end
end
-- ---------------------------------------------------------------------------
-- Subcommand help pages
-- ---------------------------------------------------------------------------
local SUBCOMMAND_HELP = {}
SUBCOMMAND_HELP["run"] = function()
print("luallm run — Run a model with an optional saved preset")
print()
print("USAGE:")
print(" luallm run <model> [--preset <profile>] [extra llama.cpp flags...]")
print()
print(" Model name supports fuzzy matching (substring, case-insensitive).")
print(" The model name must come before any flags.")
print()
print("OPTIONS:")
print(" --preset <profile> Load saved preset flags for this model.")
print(" Any extra flags you pass override the preset.")
print(" Profiles: throughput, cold-start, context")
print()
print("EXAMPLES:")
print(" luallm run mistral # Run with default settings")
print(" luallm run mistral --preset throughput # Run with throughput preset")
print(" luallm run mistral --preset cold-start # Run with cold-start preset")
print(" luallm run mistral --preset throughput -c 8192 # Preset + override context")
print(" luallm run mistral -c 4096 --port 9090 # Custom flags, no preset")
end
SUBCOMMAND_HELP["bench"] = function()
print("luallm bench — Benchmark a model using llama-bench")
print()
print("USAGE:")
print(" luallm bench <model> [options]")
print(" luallm bench show [model]")
print(" luallm bench compare <model-A> <model-B> [--verbose]")
print(" luallm bench clear")
print()
print("SUBCOMMANDS:")
print(" <model> Run a benchmark sweep (5 runs, 1 warmup by default)")
print(" show [model] View saved benchmark results (picker if no model given)")
print(" compare <A> <B> Compare results for two models side by side")
print(" clear Delete all saved benchmark logs")
print()
print("OPTIONS (for bench <model>):")
print(" --n <N> Number of benchmark runs (default: 5)")
print(" --warmup <W> Warmup runs before measuring (default: 1)")
print(" --threads <T> Thread count to benchmark at")
print()
print("OPTIONS (for bench compare):")
print(" --verbose Include hardware and build environment details")
print()
print("EXAMPLES:")
print(" luallm bench mistral # 5 runs, 1 warmup")
print(" luallm bench mistral --n 10 # 10 runs")
print(" luallm bench mistral --n 10 --warmup 2 # 10 runs, 2 warmup")
print(" luallm bench mistral --threads 8 # Benchmark at 8 threads")
print(" luallm bench show # Pick model to view results")
print(" luallm bench show TheDrummer # View specific model")
print(" luallm bench compare Cydonia Maginum # Compare two models")
print(" luallm bench compare Cydonia Maginum --verbose")
print(" luallm bench clear # Wipe all benchmark logs")
end
SUBCOMMAND_HELP["recommend"] = function()
print("luallm recommend — Generate optimised run presets for a model")
print()
print("USAGE:")
print(" luallm recommend <profile> [model]")
print()
print(" Presets are saved to config and applied with: luallm run <model> --preset <profile>")
print(" Model name supports fuzzy matching. Picker shown if omitted.")
print()
print("PROFILES:")
print(" throughput Benchmark sweep to find the flags that maximise token/s.")
print(" Tests combinations of thread counts, KV cache types, and")
print(" flash attention. Saves the best result as a preset.")
print()
print(" cold-start Static preset optimised for fast model load time.")
print(" Uses a small context, reduced GPU layers (Metal), and")
print(" disables flash attention to minimise startup cost.")
print()
print(" context (not yet implemented)")
print()
print("EXAMPLES:")
print(" luallm recommend throughput mistral # Sweep and save best preset")
print(" luallm recommend throughput # Pick model interactively")
print(" luallm recommend cold-start mistral # Generate cold-start preset")
print(" luallm run mistral --preset throughput # Use the saved preset")
end
SUBCOMMAND_HELP["notes"] = function()
print("luallm notes — Attach freeform notes to a model")
print()
print("USAGE:")
print(" luallm notes [model]")
print(" luallm notes add <model> <text...>")
print(" luallm notes edit [model]")
print(" luallm notes list")
print(" luallm notes path <model>")
print()
print("SUBCOMMANDS:")
print(" [model] View notes for a model (picker if omitted)")
print(" add <model> <text> Append a timestamped note")
print(" edit [model] Open notes file in $EDITOR (picker if omitted)")
print(" list List all models that have notes")
print(" path <model> Print the path to the notes file")
print()
print("OPTIONS:")
print(" --json Output as JSON instead of human-readable text")
print(" Works with: luallm notes --json")
print(" luallm notes <model> --json")
print(" luallm notes list --json")
print()
print("EXAMPLES:")
print(" luallm notes mistral # View notes")
print(" luallm notes add mistral \"great for coding\" # Add a note")
print(" luallm notes edit mistral # Edit in $EDITOR")
print(" luallm notes list # See all annotated models")
print(" luallm notes list --json # Machine-readable list")
print(" luallm notes mistral --json # Machine-readable notes")
end
SUBCOMMAND_HELP["info"] = function()
print("luallm info — Show cached metadata for a model")
print()
print("USAGE:")
print(" luallm info [model] [--kv] [--raw]")
print()
print(" Metadata is captured the first time a model is run and cached locally.")
print(" Picker shown if no model name is given.")
print()
print("OPTIONS:")
print(" --kv Show the structured GGUF key-value pairs")
print(" --raw Show the raw captured llama.cpp output")
print()
print("EXAMPLES:")
print(" luallm info # Pick model interactively")
print(" luallm info mistral # Show summary")
print(" luallm info mistral --kv # Show GGUF KV data")
print(" luallm info mistral --raw # Show raw captured output")
end
SUBCOMMAND_HELP["join"] = function()
print("luallm join — Merge multi-part GGUF files into a single file")
print()
print("USAGE:")
print(" luallm join [query]")
print()
print(" Scans your models directory for files matching the multi-part naming")
print(" convention and merges them using llama-gguf-split --merge.")
print(" If multiple models are found, an interactive picker is shown.")
print()
print(" Multi-part files look like:")
print(" ModelName-00001-of-00003.gguf")
print(" ModelName-00002-of-00003.gguf")
print(" ModelName-00003-of-00003.gguf")
print(" Output: ModelName.gguf (same directory)")
print()
print(" Requires llama-gguf-split, which ships with llama.cpp.")
print(" It is found automatically if llama_cpp_path is configured.")
print(" You can also set llama_gguf_split_path explicitly in config.")
print()
print("EXAMPLES:")
print(" luallm join # Find and merge any multi-part GGUFs")
print(" luallm join llama-405b # Merge a specific model by name")
end
SUBCOMMAND_HELP["pin"] = function()
print("luallm pin / unpin / pinned — Pin models for quick access")
print()
print("USAGE:")
print(" luallm pin <model>")
print(" luallm unpin <model>")
print(" luallm pinned")
print()
print(" Pinned models appear at the top of the interactive picker.")
print()
print("EXAMPLES:")
print(" luallm pin mistral # Pin a model")
print(" luallm unpin mistral # Unpin a model")
print(" luallm pinned # List all pinned models")
end
SUBCOMMAND_HELP["start"] = function()
print("luallm start — Start a model as a background daemon")
print()
print("USAGE:")
print(" luallm start <model> [--preset <profile>] [extra llama.cpp flags...]")
print()
print(" Launches llama-server in the background and returns immediately.")
print(" The model name must come before any flags.")
print()
print(" PID is captured exactly via shell $! and written to state.json.")
print(" stdout/stderr are redirected to a log file (overwritten each launch).")
print(" Log: ~/.cache/luallm/logs/<model>.log")
print()
print(" Multiple servers can run simultaneously on different ports.")
print(" Use different --port values in default_params or via extra flags.")
print()
print("OPTIONS:")
print(" --preset <profile> Load saved preset flags (throughput, cold-start)")
print()
print("EXAMPLES:")
print(" luallm start mistral # Start with default settings")
print(" luallm start mistral --preset throughput # Start with preset")
print(" luallm start mistral --port 8081 # Start on a specific port")
print(" luallm logs mistral --follow # Tail the log")
print(" luallm stop mistral # Stop it")
end
SUBCOMMAND_HELP["logs"] = function()
print("luallm logs — View the log file for a daemon-mode server")
print()
print("USAGE:")
print(" luallm logs [model] [--follow]")
print()
print(" Daemon servers (started with luallm start) redirect their output")
print(" to a log file instead of stdout.")
print(" Log location: ~/.cache/luallm/logs/<model>.log")
print(" The log file is overwritten each time the model is started.")
print()
print("OPTIONS:")
print(" --follow, -f Tail the log in real time (like tail -f)")
print()
print("EXAMPLES:")
print(" luallm logs mistral # Print full log")
print(" luallm logs mistral --follow # Tail in real time")
print(" luallm logs # Pick from available logs")
end
SUBCOMMAND_HELP["stop"] = function()
print("luallm stop — Stop a running llama-server instance")
print()
print("USAGE:")
print(" luallm stop <model>")
print(" luallm stop all")
print()
print(" Model name supports fuzzy matching.")
print(" Sends SIGTERM, waits 1 second, escalates to SIGKILL if still running.")
print(" PID is resolved from: pidfile (daemon) → state.json → lsof")
print()
print("EXAMPLES:")
print(" luallm stop mistral # Stop a specific server")
print(" luallm stop all # Stop every running server")
end
SUBCOMMAND_HELP["list"] = function()
print("luallm list — List all available models")
print()
print("USAGE:")
print(" luallm list")
print(" luallm list --json")
print()
print(" Scans models_dir and shows name, size, quantization, and last run time.")
print(" Results are sorted most-recently-used first.")
print()
print("OPTIONS:")
print(" --json Output model list as a JSON array (for scripting)")
print()
print("JSON FIELDS (per model):")
print(" name Model filename without .gguf extension")
print(" size Human-readable file size (e.g. \"7.2 GB\")")
print(" quantization Quantization level extracted from name (e.g. \"Q4_K_M\")")
print(" last_run Human-readable last run time (e.g. \"2 days ago\")")
print()
print("EXAMPLES:")
print(" luallm list # Human-readable table")
print(" luallm list --json # Machine-readable JSON array")
print(" luallm list --json | jq '.[].name' # Extract just model names")
end
SUBCOMMAND_HELP["help"] = function()
print("luallm help — Show help for commands")
print()
print("USAGE:")
print(" luallm help")
print(" luallm help <command>")
print(" luallm help --json")
print(" luallm help <command> --json")
print()
print("OPTIONS:")
print(" --json Output help as a structured JSON object or array")
print()
print("JSON FIELDS (per command):")
print(" name Command name")
print(" group Category (running, management, benchmarking, utilities)")
print(" description One-line description")
print(" options Array of {flag, description} objects")
print(" subcommands Array of {name, description} objects (if applicable)")
print()
print("EXAMPLES:")
print(" luallm help # Full human-readable help")
print(" luallm help bench # Detailed help for bench")
print(" luallm help --json # Full command catalogue as JSON")
print(" luallm help bench --json # Bench command detail as JSON")
end
SUBCOMMAND_HELP["status"] = function()
print("luallm status — Show running and recently stopped servers")
print()
print("USAGE:")
print(" luallm status")
print(" luallm status --json")
print()
print(" Reads ~/.cache/luallm/state.json and displays a summary.")
print(" State is written automatically whenever a model is started or stopped.")
print()
print("OPTIONS:")
print(" --json Output the raw state.json as JSON (for scripting)")
print()
print("STATE FILE: " .. require("state").STATE_FILE)
print()
print("EXAMPLES:")
print(" luallm status # Human-readable summary")
print(" luallm status --json # Machine-readable JSON")
print(" cat ~/.cache/luallm/state.json # Direct file access")
end
function print_help(subcommand, flag)
local want_json = (flag == "--json") or (subcommand == "--json")
if subcommand == "--json" then subcommand = nil end
-- JSON output: structured data for all commands or a specific subcommand
if want_json then
local json_ok, json = pcall(require, "cjson")
if not json_ok then
io.stderr:write("Error: cjson not available for JSON output\n")
os.exit(1)
end
-- Top-level command catalogue
local commands = {
{ name = "run", group = "running", description = "Run a model in the foreground with optional --preset flag" },
{ name = "start", group = "running", description = "Start a model as a background daemon" },
{ name = "stop", group = "running", description = "Stop a running server" },
{ name = "status", group = "running", description = "Show running and recently stopped servers" },
{ name = "logs", group = "running", description = "View daemon log (--follow to tail)" },
{ name = "list", group = "management", description = "List all models" },
{ name = "info", group = "management", description = "Show cached metadata for a model" },
{ name = "join", group = "management", description = "Merge multi-part GGUF files" },
{ name = "pin", group = "management", description = "Pin a model for quick picker access" },
{ name = "unpin", group = "management", description = "Unpin a model" },
{ name = "pinned", group = "management", description = "List all pinned models" },
{ name = "notes", group = "management", description = "Attach freeform notes to a model" },
{ name = "bench", group = "benchmarking",description = "Benchmark a model using llama-bench" },
{ name = "recommend", group = "benchmarking",description = "Generate optimised run presets" },
{ name = "doctor", group = "utilities", description = "Run configuration diagnostics" },
{ name = "config", group = "utilities", description = "Show config file location" },
{ name = "rebuild", group = "utilities", description = "Rebuild llama.cpp from source" },
{ name = "clear-history", group = "utilities", description = "Clear run history" },
}
-- Options per command
local options = {
run = { { flag = "--preset <profile>", description = "Load saved preset flags (throughput, cold-start, context)" } },
start = { { flag = "--preset <profile>", description = "Load saved preset flags" } },
status = { { flag = "--json", description = "Output raw state as JSON" } },
logs = { { flag = "--follow, -f", description = "Tail the log in real time" } },
list = { { flag = "--json", description = "Output model list as JSON" } },
info = {
{ flag = "--kv", description = "Show GGUF key-value pairs" },
{ flag = "--raw", description = "Show raw captured llama.cpp output" },
},
bench = {
{ flag = "--n <N>", description = "Number of benchmark runs (default: 5)" },
{ flag = "--warmup <W>", description = "Warmup runs before measuring (default: 1)" },
{ flag = "--threads <T>", description = "Thread count to benchmark at" },
{ flag = "--verbose", description = "Include hardware details (bench compare)" },
},
notes = { { flag = "--json", description = "Output notes as JSON" } },
help = { { flag = "--json", description = "Output help as JSON" } },
}
-- Subcommands per command
local subcommands_map = {
bench = {
{ name = "show [model]", description = "View saved benchmark results" },
{ name = "compare <A> <B>", description = "Compare results for two models side by side" },
{ name = "clear", description = "Delete all saved benchmark logs" },
},
notes = {
{ name = "add <model> <text>", description = "Append a timestamped note" },
{ name = "edit [model]", description = "Open notes file in $EDITOR" },
{ name = "list", description = "List all models that have notes" },
{ name = "path <model>", description = "Print the path to the notes file" },
},
}
if subcommand then
-- Single-command detail
local found = nil
for _, c in ipairs(commands) do
if c.name == subcommand then found = c; break end
end
if not found then
io.stderr:write("No help available for '" .. subcommand .. "'\n")
os.exit(1)
end
local out = {
name = found.name,
group = found.group,
description = found.description,
options = options[found.name] or {},
subcommands = subcommands_map[found.name] or {},
}
print(json.encode(out))
else
-- Full catalogue
local out = {}
for _, c in ipairs(commands) do
table.insert(out, {
name = c.name,
group = c.group,
description = c.description,
options = options[c.name] or {},
subcommands = subcommands_map[c.name] or {},
})
end
print(json.encode(out))
end
return
end
-- Subcommand detail page (human-readable)
if subcommand and SUBCOMMAND_HELP[subcommand] then
print()
SUBCOMMAND_HELP[subcommand]()
print()
return
end
-- Unknown subcommand passed to help
if subcommand then
print("No detailed help available for '" .. subcommand .. "'.")
print()
end
print("luaLLM — Local LLM manager")
print()
print("USAGE: luallm <command> [args...]")
print(" luallm help <command> Show detailed help for a command")
print()
print("RUNNING MODELS:")
print(" luallm Interactive picker (most-recent first)")
print(" luallm <model> Run a model in the foreground (fuzzy name match)")
print(" luallm run <model> Run in foreground with optional --preset flag")
print(" luallm start <model> Start as background daemon (returns immediately)")
print(" luallm stop <model> Stop a running server")
print(" luallm status Show running and recently stopped servers")
print(" luallm logs <model> View daemon log (--follow to tail)")
print()
print("MODEL MANAGEMENT:")
print(" luallm list List all models")
print(" luallm info [model] Show cached metadata")
print(" luallm join [query] Merge multi-part GGUF files")
print(" luallm pin/unpin Pin models for quick picker access")
print(" luallm notes Attach notes to a model")
print()
print("BENCHMARKING & PRESETS:")
print(" luallm bench <model> Benchmark with llama-bench")
print(" luallm recommend Generate optimised run presets")
print()
print("UTILITIES:")
print(" luallm doctor Run configuration diagnostics")
print(" luallm config Show config file location")
print(" luallm rebuild Rebuild llama.cpp from source")
print(" luallm clear-history Clear run history")
print(" luallm test Run test suite")
print()
print("DETAILED HELP:")
print(" luallm help run Running models with presets and flags")
print(" luallm help start Background daemon launch, PID tracking, log files")
print(" luallm help logs Viewing daemon server logs")
print(" luallm help stop Stopping a running server")
print(" luallm help status Checking server state (--json output)")
print(" luallm help bench Benchmarking and comparing models")
print(" luallm help recommend Generating optimised presets")
print(" luallm help notes Attaching notes to models (--json output)")
print(" luallm help list Listing models (--json output)")
print(" luallm help info Viewing model metadata")
print(" luallm help join Merging multi-part GGUF files")
print(" luallm help pin Pinning models")
print(" luallm help help Help command options (--json output)")
print()
print("Config: " .. config.CONFIG_FILE)
print()
end
-- "test" is handled before main() so it never requires a config file.
if arg[1] == "test" then
local script_dir = (arg[0]:match("^(.*)/[^/]+$") or ".")
local test_runner = require("test_runner")
test_runner.run_all(script_dir .. "/src")
end
local ok, err = xpcall(function()
main(arg)
end, debug.traceback)
if not ok then
local err_msg = tostring(err)
if err_msg:match("interrupted") then
os.exit(130)
end
io.stderr:write(err .. "\n")
os.exit(1)
end