MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / inherited_value

Function inherited_value

src/cli/runtime_settings.c:343–400  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

341}
342
343static const char *inherited_value(const setting_t *setting, char out[SETTINGS_VALUE_CAP]) {
344 if (!cbm_native_getenv(setting->key, out, SETTINGS_VALUE_CAP, NULL))
345 return NULL;
346 if (setting->storage == SET_REFERENCE)
347 return out;
348 if (strcmp(setting->key, "CBM_STARTUP_TIMEOUT_MS") == 0 ||
349 strcmp(setting->key, "CBM_HOOK_DEADLINE_MS") == 0 ||
350 strcmp(setting->key, "CBM_SQLITE_MMAP_SIZE") == 0) {
351 char *end = NULL;
352 errno = 0;
353 long long number = strtoll(out, &end, 10);
354 bool startup = strcmp(setting->key, "CBM_STARTUP_TIMEOUT_MS") == 0;
355 bool mmap_size = strcmp(setting->key, "CBM_SQLITE_MMAP_SIZE") == 0;
356 if (end == out || *end ||
357 (!startup && !mmap_size && (errno || strspn(out, "+-0123456789") != strlen(out))))
358 return out;
359 if (startup && number <= 0)
360 return out;
361 if (number < (long long)setting->minimum)
362 number = (long long)setting->minimum;
363 if (!mmap_size && number > (long long)setting->maximum)
364 number = (long long)setting->maximum;
365 (void)snprintf(out, SETTINGS_VALUE_CAP, "%lld", number);
366 return out;
367 }
368 if (strcmp(setting->type, "boolean") == 0) {
369 bool enabled;
370 if (strcmp(setting->key, "CBM_DISABLE_LSP_CROSS") == 0)
371 enabled = true;
372 else if (strcmp(setting->key, "CBM_PROFILE") == 0)
373 enabled = out[0] && out[0] != '0';
374 else if (strcmp(setting->key, "CBM_DIAGNOSTICS") == 0)
375 enabled = strcmp(out, "1") == 0 || strcmp(out, "true") == 0;
376 else if (strcmp(setting->key, "CBM_MI_THREAD_DONE") == 0)
377 enabled = out[0] != '0';
378 else
379 enabled = out[0] == '1';
380 (void)snprintf(out, SETTINGS_VALUE_CAP, "%s", enabled ? "true" : "false");
381 return out;
382 }
383 char original[SETTINGS_VALUE_CAP];
384 (void)snprintf(original, sizeof(original), "%s", out);
385 if (strcmp(setting->key, "CBM_LOG_LEVEL") == 0 || strcmp(setting->key, "CBM_LOG_FORMAT") == 0) {
386 for (char *p = out; *p; p++)
387 *p = (char)tolower((unsigned char)*p);
388 }
389 if (strcmp(setting->key, "CBM_LOG_LEVEL") == 0 && strlen(out) == 1 && out[0] >= '0' &&
390 out[0] <= '4') {
391 const char *levels[] = {"debug", "info", "warn", "error", "none"};
392 (void)snprintf(out, SETTINGS_VALUE_CAP, "%s", levels[out[0] - '0']);
393 }
394 /* Legacy readers have different permissive parsing rules. Preserve an
395 * unrecognized inherited input instead of claiming the default is active;
396 * the snapshot explicitly marks an unverified effective value below. */
397 if (!valid_value(setting, out))
398 (void)snprintf(out, SETTINGS_VALUE_CAP, "%s", original);
399 return out;
400}

Callers 1

desired_valueFunction · 0.85

Calls 2

cbm_native_getenvFunction · 0.85
valid_valueFunction · 0.85

Tested by

no test coverage detected