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

Function cli_closest_prop

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

11726/* Closest schema property to `key` for a "did you mean" suggestion, or NULL
11727 * when nothing is plausibly near (distance > half the key length, min 2). */
11728static const char *cli_closest_prop(yyjson_val *props, const char *key) {
11729 const char *best = NULL;
11730 int best_d = 0;
11731 size_t idx;
11732 size_t max;
11733 yyjson_val *k;
11734 yyjson_val *v;
11735 yyjson_obj_foreach(props, idx, max, k, v) {
11736 const char *name = yyjson_get_str(k);
11737 if (!name) {
11738 continue;
11739 }
11740 int d = cli_edit_distance(key, name);
11741 if (!best || d < best_d) {
11742 best = name;
11743 best_d = d;
11744 }
11745 }
11746 int limit = (int)(strlen(key) / 2);
11747 if (limit < 2) {
11748 limit = 2;
11749 }
11750 return (best && best_d <= limit) ? best : NULL;
11751}
11752
11753/* True if the schema's required[] array contains `key`. */
11754static 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