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

Function snapshot

src/cli/runtime_settings.c:589–690  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

587}
588
589static char *snapshot(sqlite3 *db, const char *cache) {
590 yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);
591 if (!doc)
592 return NULL;
593 yyjson_mut_val *root = yyjson_mut_obj(doc);
594 yyjson_mut_doc_set_root(doc, root);
595 char rev[32];
596 revision(db, rev);
597 json_string(doc, root, "revision", rev);
598 json_string(doc, root, "precedence",
599 "Explicit CLI/UI configuration writes share one store; saved environment overrides "
600 "take precedence over inherited environment after restart. Per-command flags and "
601 "supervisor safety limits retain precedence.");
602 yyjson_mut_val *items = yyjson_mut_arr(doc);
603 yyjson_mut_obj_add_val(doc, root, "settings", items);
604 char canonical[SETTINGS_PATH_CAP];
605 bool current_process = initialized && cbm_canonical_path(cache, canonical, sizeof(canonical)) &&
606 strcmp(cbm_normalize_path_sep(canonical), initial_cache) == 0;
607 for (size_t i = 0; i < SETTINGS_COUNT; i++) {
608 const setting_t *setting = &settings[i];
609 char buffer[SETTINGS_VALUE_CAP];
610 bool saved = false;
611 const char *source = NULL;
612 const char *value = desired_value(db, setting, buffer, &saved, &source);
613 const char *effective = value;
614 if (current_process && strcmp(setting->apply_mode, "restart") == 0)
615 effective = initial_present[i] ? initial_values[i] : NULL;
616 const char *baseline = effective;
617 char bound_port[32];
618 int actual_port = atomic_load_explicit(&active_http_port, memory_order_relaxed);
619 if (current_process && actual_port > 0 && setting->storage == SET_UI) {
620 (void)snprintf(bound_port, sizeof(bound_port), "%d", actual_port);
621 effective = strcmp(setting->key, "ui_port") == 0 ? bound_port : "true";
622 baseline = effective;
623 }
624 if (current_process && strcmp(setting->key, "CBM_LOG_LEVEL") == 0) {
625 static const char *levels[] = {"debug", "info", "warn", "error", "none"};
626 unsigned level = (unsigned)cbm_log_get_level();
627 if (level < sizeof(levels) / sizeof(levels[0]))
628 effective = levels[level];
629 }
630 if (current_process && strcmp(setting->key, "CBM_LOG_FORMAT") == 0)
631 effective = cbm_log_get_format() == CBM_LOG_FORMAT_JSON ? "json" : "text";
632 bool pending =
633 strcmp(setting->apply_mode, "restart") == 0 &&
634 ((!value != !baseline) || (value && baseline && strcmp(value, baseline) != 0));
635 yyjson_mut_val *item = yyjson_mut_obj(doc);
636 yyjson_mut_arr_append(items, item);
637 json_string(doc, item, "key", setting->key);
638 json_string(doc, item, "label", setting->label);
639 json_string(doc, item, "description", setting->description);
640 json_string(doc, item, "category", setting->category);
641 json_string(doc, item, "type", setting->type);
642 json_string(doc, item, "defaultValue", setting->default_value);
643 json_string(doc, item, "value", value);
644 json_string(doc, item, "override", saved ? value : NULL);
645 json_string(doc, item, "effective", effective);
646 yyjson_mut_obj_add_bool(doc, item, "effectiveKnown",

Callers 2

Calls 9

revisionFunction · 0.85
json_stringFunction · 0.85
cbm_canonical_pathFunction · 0.85
cbm_normalize_path_sepFunction · 0.85
desired_valueFunction · 0.85
cbm_log_get_levelFunction · 0.85
cbm_log_get_formatFunction · 0.85
valid_valueFunction · 0.85

Tested by

no test coverage detected