bin/knarr

filter: Statementstmt 100% 10 / 10 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 13 / 13 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Langertha/Knarr/CLI/Cmd/Container.pm ↑ Summary blib/lib/Langertha/Knarr/Session.pm »
1 #!/usr/bin/env perl
2 # PODNAME: knarr
3 # ABSTRACT: Langertha LLM Proxy with Langfuse Tracing
4 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use Langertha::Knarr::CLI;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 Langertha::Knarr::CLI->new_with_cmd;
8  
9 __END__
10  
11 =pod
12  
13 =encoding UTF-8
14  
15 =head1 NAME
16  
17 knarr - Langertha LLM Proxy with Langfuse Tracing
18  
19 =head1 VERSION
20  
21 version 1.102
22  
23 =head1 SYNOPSIS
24  
25 knarr <command> [options]
26  
27 knarr start # Start with ./knarr.yaml
28 knarr start --from-env # Auto-detect config from ENV
29 knarr start --from-env -p 8080 -p 11434 # ENV config, explicit ports
30 knarr start -c production.yaml -p 9090 # Custom config and port
31 knarr start -c production.yaml -v # Custom config, verbose
32 knarr init > knarr.yaml # Generate config from environment
33 knarr init -e .env -e .env.local # Scan .env files
34 knarr init -l 0.0.0.0:8080 -o knarr.yaml # Listen on all interfaces
35 knarr models # List configured models
36 knarr models --format json # JSON output
37 knarr check # Validate config file
38  
39 =head1 DESCRIPTION
40  
41 C<knarr> is the command-line interface for L<Langertha::Knarr>, an LLM proxy
42 that accepts requests in OpenAI, Anthropic, Ollama, A2A, ACP, or AG-UI
43 format, routes them to any Langertha backend engine, and traces everything
44 via Langfuse.
45  
46 The configuration file format, with the environment variable behind each
47 setting, is documented in L<Langertha::Knarr::Config>; the model routing
48 order in L<Langertha::Knarr::Router/resolve>. The README of the
49 distribution covers Docker usage, passthrough and every environment
50 variable. L<Langertha::Knarr> documents the server and its Perl API.
51  
52 Long options can be written with dashes or underscores (C<--log-file>,
53 C<--log_file>) in any position.
54  
55 =head1 COMMANDS
56  
57 =over
58  
59 =item B<start> — Start the proxy server (with config file or C<--from-env>)
60  
61 =item B<init> — Scan environment and .env files for API keys, print generated YAML config
62  
63 =item B<models> — List all configured and auto-discovered models
64  
65 =item B<check> — Validate the config file and report configuration status
66  
67 =item B<container> — Deprecated alias for C<start --from-env -p 8080 -p 11434>,
68 the Docker image's own command: always C<0.0.0.0:8080> and C<0.0.0.0:11434>,
69 no options of its own; for other ports use C<start --from-env -p ...>
70  
71 =back
72  
73 =head1 GLOBAL OPTIONS
74  
75 Accepted before the subcommand, and after C<start>, C<check> and C<models>
76 (C<knarr start -c prod.yaml -v>); a value given after the subcommand wins.
77  
78 =over
79  
80 =item B<-c>, B<--config> I<path>
81  
82 Config file path. Defaults to C<./knarr.yaml>.
83  
84 =item B<-v>, B<--verbose>
85  
86 Enable verbose logging to stderr. Also enabled by C<KNARR_DEBUG=1>.
87  
88 =back
89  
90 =head1 START OPTIONS
91  
92 =over
93  
94 =item B<--from-env>
95  
96 Build config from environment variables when no config file is found:
97 one engine per API key found, C<auto_discover> and C<passthrough> on, and
98 OpenAI as the default engine when an OpenAI key is set. This is how the
99 Docker image starts (C<start --from-env -p 8080 -p 11434>).
100  
101 =item B<-p>, B<--port> I<port>
102  
103 Port to listen on, on the host from C<-H>. Repeatable (e.g. C<-p 8080 -p
104 11434>). Given at least once, it replaces the config's C<listen:>. Without
105 C<-p> Knarr listens on the config's C<listen:> addresses, which default to
106 C<127.0.0.1:8080> and C<127.0.0.1:11434> (loopback only, also under
107 C<--from-env>).
108  
109 =item B<-H>, B<--host> I<host>
110  
111 Host the C<-p> ports bind to. Defaults to C<0.0.0.0>. Has no effect
112 without C<-p>.
113  
114 =item B<-w>, B<--workers> I<n>
115  
116 Number of worker processes. Wins over the config's C<workers:> and
117 C<KNARR_WORKERS>; without any of them C<1> (one process, nothing forked).
118 Anything but a whole number of C<1> or more stops C<start> before it
119 binds anything.
120 With more, Knarr binds the listen addresses, runs auto-discovery and the
121 capability probe once, then forks I<n> workers that accept on the same
122 sockets. The first process stays as their supervisor: it restarts a worker
123 that exits (pausing up to 30 seconds when one keeps dying right after its
124 start or cannot be forked, while the others serve on) and passes
125 C<SIGTERM>/C<SIGINT> on to all of them, exiting once they are gone. Each worker keeps its own sessions: a Raider conversation
126 continues only when its next request reaches the same worker, which
127 nothing guarantees.
128  
129 =item B<-n>, B<--trace-name> I<name>
130  
131 Langfuse trace name. Overrides the config file, C<LANGFUSE_TRACE_NAME> and
132 C<KNARR_TRACE_NAME>.
133  
134 =item B<--log-file> I<path>
135  
136 JSONL log file path for request logging. Overrides C<KNARR_LOG_FILE> and
137 the config file.
138  
139 =item B<--log-dir> I<path>
140  
141 Directory for per-request JSON log files. Overrides C<KNARR_LOG_DIR> and
142 the config file.
143  
144 =back
145  
146 =head1 INIT OPTIONS
147  
148 =over
149  
150 =item B<-e>, B<--env-file> I<path>
151  
152 Additional .env file to scan. Repeatable. C<.env> and C<.env.local> in the
153 current directory and C<$HOME/.env> are scanned automatically when they
154 exist.
155  
156 =item B<-l>, B<--listen> I<addr>
157  
158 Listen address to include in generated config. Repeatable. Defaults to
159 C<127.0.0.1:8080> and C<127.0.0.1:11434>; use C<0.0.0.0:...> for a config
160 that must be reachable from outside, e.g. in a container.
161  
162 =item B<-o>, B<--output> I<path>
163  
164 Write generated config to a file instead of stdout.
165  
166 =back
167  
168 =head1 MODELS OPTIONS
169  
170 =over
171  
172 =item B<-f>, B<--format> I<format>
173  
174 Output format: C<table> (default) or C<json>.
175  
176 =back
177  
178 =head1 SUPPORT
179  
180 =head2 Issues
181  
182 Please report bugs and feature requests on GitHub at
183 L<https://github.com/Getty/langertha-knarr/issues>.
184  
185 =head2 IRC
186  
187 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
188  
189 =head1 CONTRIBUTING
190  
191 Contributions are welcome! Please fork the repository and submit a pull request.
192  
193 =head1 AUTHOR
194  
195 Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/>
196  
197 =head1 COPYRIGHT AND LICENSE
198  
199 This software is copyright (c) 2026 by Torsten Raudssus.
200  
201 This is free software; you can redistribute it and/or modify it under
202 the same terms as the Perl 5 programming language system itself.
203  
204 =cut
« blib/lib/Langertha/Knarr/CLI/Cmd/Container.pm ↑ Summary blib/lib/Langertha/Knarr/Session.pm »