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

Function trace_cursor_decode

src/mcp/mcp.c:6163–6197  ·  view source on GitHub ↗

Decode + validate. Returns NULL on success, else a static teaching error. */

Source from the content-addressed store, hash-verified

6161
6162/* Decode + validate. Returns NULL on success, else a static teaching error. */
6163static const char *trace_cursor_decode(const char *token, const char *current_generation,
6164 uint64_t expected_qhash, trace_cursor_t *out) {
6165 memset(out, 0, sizeof(*out));
6166 if (!token || strncmp(token, "c1.", 3) != 0) {
6167 return "invalid_cursor: unrecognized token — re-run the original query without 'cursor'";
6168 }
6169 const char *p = token + 3;
6170 if (*p != 'o' && *p != 'i') {
6171 return "invalid_cursor: unrecognized token — re-run the original query without 'cursor'";
6172 }
6173 out->leg = *p;
6174 p += 2; /* leg + '.' */
6175 const char *gen_end = strchr(p, '.');
6176 if (!gen_end || (size_t)(gen_end - p) >= sizeof(out->generation)) {
6177 return "invalid_cursor: unrecognized token — re-run the original query without 'cursor'";
6178 }
6179 memcpy(out->generation, p, (size_t)(gen_end - p));
6180 out->generation[gen_end - p] = '\0';
6181 unsigned long long qh = 0;
6182 long long nid = 0;
6183 if (sscanf(gen_end + 1, "%16llx.%d.%lld", &qh, &out->hop, &nid) != 3) {
6184 return "invalid_cursor: unrecognized token — re-run the original query without 'cursor'";
6185 }
6186 out->qhash = qh;
6187 out->node_id = nid;
6188 if (out->qhash != expected_qhash) {
6189 return "cursor_params_mismatch: this cursor was issued for different arguments — "
6190 "pass the cursor back with ALL other arguments identical";
6191 }
6192 if (strcmp(out->generation, current_generation) != 0) {
6193 return "stale_cursor: the project was reindexed since this cursor was issued — "
6194 "re-run the original query without 'cursor' (node identities changed)";
6195 }
6196 return NULL;
6197}
6198
6199/* Slice a canonically-ordered traversal at the watermark: index of the first
6200 * row strictly AFTER (hop, id). */

Callers 1

handle_trace_call_pathFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected