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

Function main

scripts/lint-mem-gate.py:187–282  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

185
186
187def main():
188 if len(sys.argv) > 1 and sys.argv[1] == "--hash":
189 path, func = Path(sys.argv[2]), sys.argv[3]
190 for name, start, end, text in function_spans(path):
191 if name == func:
192 print(f"## {path} :: {func} :: <check>")
193 print(f"segment-sha256: {segment_hash(text)}")
194 return 0
195 sys.stderr.write(f"lint-mem-gate: no function {func} in {path}\n")
196 return 2
197
198 entries = parse_whitelist()
199 findings = []
200 for raw in sys.stdin:
201 m = FINDING_RE.match(raw.rstrip("\n"))
202 if not m:
203 continue
204 f = m.groupdict()
205 # Only the analyzer checks this gate is about. clang-tidy also emits
206 # clang-diagnostic-* for ordinary compiler warnings; those belong to
207 # the build's own -Werror, not here.
208 if not f["check"].startswith("clang-analyzer-"):
209 continue
210 if "/vendored/" in f["file"]:
211 continue
212 findings.append(f)
213
214 # One diagnostic can be reported once per translation unit that includes it.
215 seen = set()
216 unique = []
217 for f in findings:
218 key = (f["file"], f["line"], f["check"])
219 if key not in seen:
220 seen.add(key)
221 unique.append(f)
222
223 failures = []
224 used = set()
225 for f in unique:
226 path = Path(f["file"])
227 if not path.exists():
228 failures.append((f, "source file not found; cannot triage"))
229 continue
230 span = enclosing(path, int(f["line"]))
231 if span is None:
232 failures.append((f, "finding is outside any function; not whitelistable"))
233 continue
234 name, _, _, text = span
235 key = (f["file"], name, f["check"])
236 entry = entries.get(key)
237 if entry is None:
238 failures.append((f, f"no whitelist entry for {name}()"))
239 continue
240 current = segment_hash(text)
241 if entry.get("segment-sha256", "") != current:
242 failures.append((f, (
243 f"whitelist entry for {name}() is STALE: the function changed since it "
244 f"was triaged, so the recorded argument no longer applies to this code.\n"

Callers 1

lint-mem-gate.pyFile · 0.70

Calls 7

function_spansFunction · 0.85
segment_hashFunction · 0.85
parse_whitelistFunction · 0.85
setFunction · 0.85
enclosingFunction · 0.85
getMethod · 0.65
writeMethod · 0.45

Tested by

no test coverage detected