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
|
#ifndef LLSH_CONFIG_H
#define LLSH_CONFIG_H
#include "dotagents.h"
#include "util.h"
/* Mirrors config.rs: CLI + file config + merged Config. */
typedef enum {
PROV_OPENAI,
PROV_ANTHROPIC,
PROV_OLLAMA,
} provider_kind;
#define LLSH_VERSION "0.1.0"
typedef struct {
char *prompt;
char *model;
char *provider;
char *base_url;
char *api_key;
char *cwd;
char *preamble;
unsigned long max_turns;
bool has_max_turns;
unsigned long max_retries;
bool has_max_retries;
unsigned long context_limit;
bool has_context_limit;
double compact_threshold;
bool has_compact_threshold;
double clear_threshold;
bool has_clear_threshold;
bool verbose;
bool allow_mcp;
bool confirm_destructive;
bool has_confirm_destructive;
strlist shell_allowlist;
strlist shell_denylist;
bool debug;
bool no_rubric; /* --no-rubric-compaction */
unsigned long rubric_max_summaries;
bool has_rubric_max_summaries;
unsigned long skill_index_cap;
bool has_skill_index_cap;
unsigned long shell_timeout_secs;
bool has_shell_timeout_secs;
unsigned long max_output_chars;
bool has_max_output_chars;
unsigned long max_file_bytes;
bool has_max_file_bytes;
char *resume;
} cli;
typedef struct {
provider_kind provider;
char *model;
char *base_url; /* may be NULL */
char *api_key; /* may be NULL */
char *preamble;
unsigned long max_turns;
unsigned long max_retries;
unsigned long context_limit;
double compact_threshold;
double clear_threshold;
bool rubric_enabled;
unsigned long rubric_max_summaries; /* 0 = unlimited */
bool verbose;
unsigned long skill_index_cap;
unsigned long shell_timeout_secs;
unsigned long max_output_chars;
unsigned long max_file_bytes;
strlist shell_allowlist;
strlist shell_denylist;
bool confirm_destructive;
} config;
/* Parse argv (without program name). 0 on success; -2 prints help and returns
* CLI_HELP (call should exit); -1 error. */
#define CLI_HELP (-2)
int cli_parse(int argc, char **argv, cli *out, char **err);
void cli_free(cli *c);
/* Merge CLI + file with precedence CLI > file > defaults. Changes CWD. */
/* Build the merged config directly from CLI arguments (the former
* config-file layer was removed; connection presets live in
* `.agents/models.json`). */
int config_from_cli(const cli *cli, config *out, char **err);
int config_merge(const cli *cli, config *out, char **err);
void config_free(config *c);
/* Reject key-requiring providers with neither api_key nor base_url. Run
* after a models.json preset may have supplied them (the merge itself no
* longer checks). */
int config_require_key_or_base(const config *c, char **err);
provider_kind provider_parse(const char *raw, char **err);
const char *provider_name(provider_kind k);
const char *provider_default_model(provider_kind k);
/* Apply a models.json `default` preset (see dotagents). Returns preset name
* (caller frees) or NULL + *err. */
char *config_apply_models_preset(config *cfg, const models_file *models,
const cli *cli, char **err);
#endif
|