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

Function cli_closest_prop

src/cli/cli.c:11798–11821  ·  view source on GitHub ↗

Closest schema property to `key` for a "did you mean" suggestion, or NULL * when nothing is plausibly near (distance > half the key length, min 2). */

Source from the content-addressed store, hash-verified

11796/* Closest schema property to `key` for a "did you mean" suggestion, or NULL
11797 * when nothing is plausibly near (distance > half the key length, min 2). */
11798static const char *cli_closest_prop(yyjson_val *props, const char *key) {
11799 const char *best = NULL;
11800 int best_d = 0;
11801 size_t idx;
11802 size_t max;
11803 yyjson_val *k;
11804 yyjson_val *v;
11805 yyjson_obj_foreach(props, idx, max, k, v) {
11806 const char *name = yyjson_get_str(k);
11807 if (!name) {
11808 continue;
11809 }
11810 int d = cli_edit_distance(key, name);
11811 if (!best || d < best_d) {
11812 best = name;
11813 best_d = d;
11814 }
11815 }
11816 int limit = (int)(strlen(key) / 2);
11817 if (limit < 2) {
11818 limit = 2;
11819 }
11820 return (best && best_d <= limit) ? best : NULL;
11821}
11822
11823/* True if the schema's required[] array contains `key`. */
11824static bool cli_schema_required_has(yyjson_val *required, const char *key) {

Callers 1

cbm_cli_build_args_jsonFunction · 0.85

Calls 1

cli_edit_distanceFunction · 0.85

Tested by

no test coverage detected