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

Function cli_closest_prop

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

13975/* Closest schema property to `key` for a "did you mean" suggestion, or NULL
13976 * when nothing is plausibly near (distance > half the key length, min 2). */
13977static const char *cli_closest_prop(yyjson_val *props, const char *key) {
13978 const char *best = NULL;
13979 int best_d = 0;
13980 size_t idx;
13981 size_t max;
13982 yyjson_val *k;
13983 yyjson_val *v;
13984 yyjson_obj_foreach(props, idx, max, k, v) {
13985 const char *name = yyjson_get_str(k);
13986 if (!name) {
13987 continue;
13988 }
13989 int d = cli_edit_distance(key, name);
13990 if (!best || d < best_d) {
13991 best = name;
13992 best_d = d;
13993 }
13994 }
13995 int limit = (int)(strlen(key) / 2);
13996 if (limit < 2) {
13997 limit = 2;
13998 }
13999 return (best && best_d <= limit) ? best : NULL;
14000}
14001
14002/* True if the schema's required[] array contains `key`. */
14003static 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