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

Function cli_closest_prop

src/cli/cli.c:12470–12493  ·  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

12468/* Closest schema property to `key` for a "did you mean" suggestion, or NULL
12469 * when nothing is plausibly near (distance > half the key length, min 2). */
12470static const char *cli_closest_prop(yyjson_val *props, const char *key) {
12471 const char *best = NULL;
12472 int best_d = 0;
12473 size_t idx;
12474 size_t max;
12475 yyjson_val *k;
12476 yyjson_val *v;
12477 yyjson_obj_foreach(props, idx, max, k, v) {
12478 const char *name = yyjson_get_str(k);
12479 if (!name) {
12480 continue;
12481 }
12482 int d = cli_edit_distance(key, name);
12483 if (!best || d < best_d) {
12484 best = name;
12485 best_d = d;
12486 }
12487 }
12488 int limit = (int)(strlen(key) / 2);
12489 if (limit < 2) {
12490 limit = 2;
12491 }
12492 return (best && best_d <= limit) ? best : NULL;
12493}
12494
12495/* True if the schema's required[] array contains `key`. */
12496static 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