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

Function output_explosion_smell

tests/test_mcp.c:4100–4126  ·  view source on GitHub ↗

── Tool-output regression suite (gating) ────────────────────────── * Context-explosion detector: flags the measured smells that re-introduce * token bloat into default outputs, independent of any specific tool: * 1. blocked internal fields (fp/sp/bt) appearing anywhere; * 2. repeated-key JSON envelopes — the same key emitted per row instead of * a header-once table (the un-TOONed en

Source from the content-addressed store, hash-verified

4098 * belongs in tool descriptions or docs, not repeated per response.
4099 * Returns NULL when clean, else a static description of the violation. */
4100static const char *output_explosion_smell(const char *inner) {
4101 static const char *row_keys[] = {
4102 "\"name\":", "\"label\":", "\"file\":", "\"path\":", "\"qualified_name\":", "\"qn\":"};
4103 if (strstr(inner, "\"fp\":") || strstr(inner, "\"sp\":") || strstr(inner, "\"bt\":")) {
4104 return "blocked internal field (fp/sp/bt) leaked into output";
4105 }
4106 for (size_t k = 0; k < sizeof(row_keys) / sizeof(row_keys[0]); k++) {
4107 int n = 0;
4108 for (const char *p = strstr(inner, row_keys[k]); p && n <= 32;
4109 p = strstr(p + 1, row_keys[k])) {
4110 n++;
4111 }
4112 if (n > 32) {
4113 return "repeated-key envelope (>32x same JSON key) — emit a header-once table";
4114 }
4115 }
4116 for (const char *p = strstr(inner, "\"note\":\""); p; p = strstr(p + 1, "\"note\":\"")) {
4117 const char *end = strchr(p + 9, '"');
4118 while (end && end[-1] == '\\') {
4119 end = strchr(end + 1, '"');
4120 }
4121 if (end && end - (p + 9) > 220) {
4122 return "embedded note exceeds one line (~220 chars)";
4123 }
4124 }
4125 return NULL;
4126}
4127
4128/* Run one tool call on the fixture server, apply the explosion detector and
4129 * an absolute byte ceiling, and require a semantic-floor marker so trimming

Callers 1

check_tool_outputFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected