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

Function extract_kv

src/cli/progress_sink.c:157–178  ·  view source on GitHub ↗

Extract a field from either structured text or JSON worker logs. */

Source from the content-addressed store, hash-verified

155
156/* Extract a field from either structured text or JSON worker logs. */
157static const char *extract_kv(const char *line, const char *key, char *buf, int buf_len) {
158 if (!line || !key || !buf || buf_len <= 0) {
159 return NULL;
160 }
161 size_t klen = strlen(key);
162 const char *p = line;
163 while (*p) {
164 if ((p == line || p[-SKIP_ONE] == ' ') && strncmp(p, key, klen) == 0 && p[klen] == '=') {
165 const char *val = p + klen + SKIP_ONE;
166 int i = 0;
167 while (val[i] && val[i] != ' ' && i < buf_len - SKIP_ONE) {
168 buf[i] = val[i];
169 i++;
170 }
171 buf[i] = '\0';
172 return buf;
173 }
174 p++;
175 }
176 const char *json_key = strcmp(key, "msg") == 0 ? "event" : key;
177 return extract_json_field(line, json_key, buf, buf_len);
178}
179
180void cbm_progress_sink_init(FILE *out) {
181 progress_sink_mutex_ensure();

Callers 8

on_discoverFunction · 0.85
on_routeFunction · 0.85
on_pass_startFunction · 0.85
on_pass_timingFunction · 0.85
on_gbuf_dumpFunction · 0.85
on_doneFunction · 0.85
on_extract_progressFunction · 0.85
cbm_progress_sink_fnFunction · 0.85

Calls 1

extract_json_fieldFunction · 0.85

Tested by

no test coverage detected