|
21 | 21 | #include "foundation/platform.h" |
22 | 22 | #include "foundation/constants.h" |
23 | 23 | #include "foundation/log.h" |
| 24 | +#include "foundation/mem.h" |
24 | 25 | #include "foundation/sha256.h" |
25 | 26 | #include "cli/client_adapter.h" |
26 | 27 | #include "mcp/mcp.h" // cbm_mcp_tool_input_schema — CLI flag parser + per-tool --help |
@@ -7016,13 +7017,19 @@ bool cbm_config_load_index_policy(cbm_config_t *cfg, cbm_index_resource_policy_t |
7016 | 7017 | return false; |
7017 | 7018 | } |
7018 | 7019 | cbm_index_policy_init(policy); |
| 7020 | + const char *profile = cbm_config_get(cfg, CBM_INDEX_CONFIG_RESOURCE_PROFILE, "off"); |
| 7021 | + if (!cbm_index_policy_set_profile(policy, profile, error, error_size)) { |
| 7022 | + return false; |
| 7023 | + } |
7019 | 7024 | for (size_t index = 0; index < cbm_index_policy_key_count(); index++) { |
7020 | 7025 | const char *key = cbm_index_policy_key_at(index); |
7021 | | - const char *value = cbm_config_get(cfg, key, cbm_index_policy_default_value(key)); |
7022 | | - if (!cbm_index_policy_set(policy, key, value, error, error_size)) { |
| 7026 | + const char *value = cbm_config_get(cfg, key, NULL); |
| 7027 | + if (value && !cbm_index_policy_set(policy, key, value, error, error_size)) { |
7023 | 7028 | return false; |
7024 | 7029 | } |
7025 | 7030 | } |
| 7031 | + cbm_system_info_t system = cbm_system_info(); |
| 7032 | + cbm_index_policy_finalize(policy, (uint64_t)system.total_ram, (uint64_t)cbm_mem_budget()); |
7026 | 7033 | return true; |
7027 | 7034 | } |
7028 | 7035 |
|
@@ -7050,6 +7057,7 @@ static const config_key_def_t CONFIG_KEYS[] = { |
7050 | 7057 | {CBM_CONFIG_UI_LANG, "auto", "Pin graph UI language: en, zh, or auto"}, |
7051 | 7058 | {CBM_CONFIG_UI_ENABLED, "false", "Serve the graph UI on a loopback HTTP port"}, |
7052 | 7059 | {CBM_CONFIG_UI_PORT, "9749", "Port for the graph UI listener when enabled"}, |
| 7060 | + {CBM_INDEX_CONFIG_RESOURCE_PROFILE, "off", "Index resource profile: off, balanced, or strict"}, |
7053 | 7061 | {CBM_INDEX_CONFIG_MAX_FILES, "off", "Max accepted source files per index, or off"}, |
7054 | 7062 | {CBM_INDEX_CONFIG_MAX_SOURCE_MB, "off", "Max accepted source MiB per index, or off"}, |
7055 | 7063 | {CBM_INDEX_CONFIG_MAX_RSS_MB, "off", "Max worker process-tree RSS MiB, or off"}, |
@@ -7083,19 +7091,17 @@ static bool config_key_is_ui(const char *key) { |
7083 | 7091 | } |
7084 | 7092 |
|
7085 | 7093 | static bool config_key_is_index_policy(const char *key) { |
7086 | | - for (size_t index = 0; key && index < cbm_index_policy_key_count(); index++) { |
7087 | | - if (strcmp(key, cbm_index_policy_key_at(index)) == 0) { |
7088 | | - return true; |
7089 | | - } |
7090 | | - } |
7091 | | - return false; |
| 7094 | + return cbm_index_policy_is_config_key(key); |
7092 | 7095 | } |
7093 | 7096 |
|
7094 | 7097 | static int config_index_policy_write(cbm_config_t *config, const char *key, const char *value) { |
7095 | 7098 | cbm_index_resource_policy_t candidate; |
7096 | 7099 | cbm_index_policy_init(&candidate); |
7097 | 7100 | char error[CLI_BUF_256]; |
7098 | | - if (!cbm_index_policy_set(&candidate, key, value, error, sizeof(error))) { |
| 7101 | + bool valid = strcmp(key, CBM_INDEX_CONFIG_RESOURCE_PROFILE) == 0 |
| 7102 | + ? cbm_index_policy_set_profile(&candidate, value, error, sizeof(error)) |
| 7103 | + : cbm_index_policy_set(&candidate, key, value, error, sizeof(error)); |
| 7104 | + if (!valid) { |
7099 | 7105 | (void)fprintf(stderr, "error: %s\n", error); |
7100 | 7106 | return CLI_ERR; |
7101 | 7107 | } |
|
0 commit comments