published: true
description: "An open-source refactor, a lint rule that kept missing cases, and the two checks I ran before pushing AI-written code."
tags: ai, opensource, typescript, testing
GitNexus turns a codebase into a knowledge graph: symbols, calls, imports, files inside folders. Links in that graph carry a confidence value: a number for how sure the graph is that the link is real.
Its ticket #948 asks for the confidence and weight constants to come from gitnexus-shared, with no numbers typed inline. The weights already did; the edge confidences didn't. My PR, #4187, does that. An AI coding agent made the edits. This post is about what it took before I trusted them.
What changed
There is now one as const map, EdgeConfidence, with 32 named keys, and 58 places in the code read from it. No value changed. Some before/after pairs from the diff:
// before const ROUTE_EDGE_CONFIDENCE = 0.5; confidence: confidence * 0.8, // after const ROUTE_EDGE_CONFIDENCE = EdgeConfidence.routeControllerCall; confidence: confidence * EdgeConfidence.guessedRouteMethodMultiplier, The PR also adds a local ESLint rule, gitnexus/no-inline-confidence, so a new inline value in the covered files fails lint.
The first pass missed values
The first audit searched for lines shaped like confidence: 0.85. That missed two shapes:
// a conditional const confidence = site.kind === 'write' || site.kind === 'read' ? 1.0 : 0.85; // a positional argument: the 8th parameter of tryEmitEdge is `confidence` const ok = tryEmitEdge( graph, scopes, nodeLookup, site, memberDef, 'global', seen, 0.85, collapse, calleeCapture, The project's review bot flagged a constant that doesn't exist, in a file that doesn't exist. But it was pointing in the right direction: the pass it meant still had inline values in exactly these shapes.
So instead of fixing one more shape, a sweep listed every decimal literal in the covered files, and each one was read. That found 20 more sites. After converting them, the same sweep leaves 6 lines, and none of them is a confidence: five langRatio progress values in pipeline/phase.ts and one heap-size check in pipeline/run.ts.
The lint rule kept missing cases
The rule had the same weakness as the audit. It started with plain literals (confidence: 0.85), and every version listed the shapes it checked. The bot kept finding the next one:
- A static template key:
{ [`confidence`]: 0.5 }. - Compound assignment and arithmetic other than
*:edge.confidence *= 0.8,1 - penalty.
What ended it was to stop listing. The final rule walks the whole value assigned to a confidence name, including *=, += and the rest, and reports every numeric literal inside it. It skips only what can't be a confidence:
- the test of a conditional (
targets.size === 1 ? … : …) - the operands of a comparison
- a computed index like
a[0]
One limit stays: a positional argument can't be matched by name, so the tryEmitEdge calls were converted but the rule can't guard them.
Check 1: compare every number, without the agent
The agent reported that every value was unchanged. Instead of taking its word, a separate script walked the diff from main to the PR, hunk by hunk. For each hunk it collected the numbers that were removed and the EdgeConfidence keys that were added, looked up each key's value in the map, and compared the two lists.
53 of 54 hunks matched automatically. The 54th had a comparison (targets.size === 1) on the same line as the two values. It was checked by hand: 0.8 became singleCallableValueTarget (0.8), and 0.7 became multipleCallableValueTargets (0.7).
Check 2: run the rule on real code, then plant bad values
The last commit only touched the rule and its test, so it couldn't change how GitNexus behaves. It could still be wrong. Before pushing, I ran three checks in my own terminal:
- The rule's tests pass.
- The rule runs clean on all the real code it covers.
- Planted values: append known-bad lines to a covered file, count the reports, then restore the file.
f=gitnexus/src/core/ingestion/structure-processor.ts printf '\nexport const vA = { confidence: 1 - 0.2 };\nexport const vB = { confidence: 0 };\nvB.confidence *= 0.8;\nexport const vC = { confidence: vA.confidence === 1 ? vA.confidence : vB.confidence };\n' >> "$f" n=$(npx eslint --quiet "$f" | grep -c "no-inline-confidence"); git checkout -- "$f" [ "$n" = "4" ] && echo PASS || echo "FAIL: $n" vA holds two bad numbers, vB and the *= line hold one each, so the guard must report exactly 4, and nothing for the === 1 in vC.
The first time through, check 2 failed. The rule flagged the 1 in targets.size === 1 in callable-value-flow.ts. That's a count, not a confidence. At first it looked like a copy-paste error, but the log showed the command had run correctly. The fix was the "skip comparisons and conditional tests" rule above, and the planted vC line now guards it.
Where it stands
All four findings from the review bot are resolved. The PR is open and waiting for a maintainer's review.
What I'm keeping from this: when the agent's summary says "all values unchanged" and "lint passes", I run a check that doesn't depend on its summary.
If you review AI-written code, what do you check that the tool's own report can't tell you?
This article and the code changes in the PR were made with the help of AI (Claude and an AI coding agent). Every number above was checked against the PR before publishing.
