Skip to content

Extend #1264's per-language class_start named-entity extraction to the remaining 13 languages #1295

Closed

Description

@squid-protocol

Summary

#1264 fixed detector.py's named-entity class extractor to reuse each language's own class_start rule (from language_standards.py) instead of one hardcoded, language-agnostic regex -- see _CLASS_START_NAMED_EXTRACTION_LANGS in gitgalaxy/core/detector.py. That switch is currently scoped to an allowlist of 18 languages verified clean via tests/tools/tree_sitter_accuracy_audit.py against the language-crucible corpus: apex, cpp, csharp, fortran, groovy, java, javascript, lua, makefile, matlab, php, powershell, python, scala, shell, solidity, tcl, typescript.

The remaining 13 languages with a tree-sitter baseline regressed when tried against their own class_start and were left on the legacy fallback regex pending real hardening:

Language Regression when switched to its own class_start Likely cause
c found_classes 45→0, extra_classes 7→23 class_start has no capture group (by design -- it also intentionally matches bare struct-TYPE-usage sites like struct foo_ops ops; for risk-signal purposes, epic #813/#822). Needs a real declaration-vs-usage distinction before it can safely name entities, not just an added capture group.
swift found_classes 9→0 class_start has no capture group at all (pure occurrence counting). Needs a capture group added around the name -- likely the simplest fix in this list.
zig extra_classes 0→629 Huge over-match. const X = struct {...} is zig's pervasive per-file-as-namespace idiom; class_start is probably firing on many declarations tree-sitter's class_node_types doesn't count as "classes". Needs investigation into what's actually matching before deciding whether to narrow the regex or the ground-truth scope.
go extra_classes 0→69 Likely legitimate type X struct/type X interface matches that tree-sitter's class_node_types for go doesn't fully cover, or GitGalaxy matching plain type aliases too broadly. Needs a real diff (same method used for csharp/fortran in #1264) before concluding which side is wrong.
css extra_classes 0→90 class_start in CSS means something different (selectors), not OOP classes -- almost certainly a ground-truth scope mismatch, not a detector bug. Worth confirming CSS should even be in scope for this kind of "class" extraction at all.
rust extra_classes 10→25 pub struct/enum/union/trait -- needs the same real-vs-noise diff method #1264 used for csharp (dump gg_classes - real_classes per file and inspect, not just trust the aggregate count).
perl extra_classes 1→20 package/role -- perl's package declarations are extremely common and may not all correspond to what tree-sitter's ground truth considers a "class".
dart extra_classes 8→33 Compound modifier stack (`abstract
haskell extra_classes 0→15 data/newtype/class/type -- haskell's class_start covers typeclasses AND data/newtype declarations, likely broader than tree-sitter's class_node_types scope.
html extra_classes 0→4 Small; probably an easy diff to run down.
kotlin extra_classes 3→5 Small; compound modifier stack like dart/scala.
objective-c extra_classes 0→5 Small; probably an easy diff to run down.
ruby extra_classes 2→9 class/module -- ruby's module keyword may be over-broad relative to tree-sitter's class_node_types.

Precedent from #1264

For csharp (kept in the allowlist despite extra_classes: 0 -> 13), the per-file diff showed the "regression" was not a detector bug: 12 of the 13 were real enum declarations that csharp's own class_start intentionally treats as class-like risk-signal entities (by design, matching how TypeScript/Java also fold enums in), which tree-sitter's class_node_types for csharp deliberately excludes; the 13th was a real class name (LanguageParser) that tree-sitter's own C# grammar failed to parse due to error-recovery limits on that large file (confirmed directly against tree_sitter_language_pack). Do the same per-file diff for each language above before assuming the regex is broken -- the method is in #1264's PR description: query class_data vs a fresh tree-sitter walk per file, print gg_classes - real_classes and real_classes - gg_classes, and read the actual file content at those lines.

Suggested approach

Same shape as epic #813 (extraction hardening) / #1069 (strict-signature hardening) / #1227 (tree-sitter accuracy): one sub-issue per language (or a batch of the "small" ones together -- html/objective-c/kotlin/ruby all show single-digit extra_classes and may be quick), each ending with:

  1. Add the language to _CLASS_START_NAMED_EXTRACTION_LANGS in gitgalaxy/core/detector.py.
  2. python tests/tools/tree_sitter_accuracy_audit.py --lang <x> --regenerate to lock in the improved baseline.
  3. python tests/tools/crucible_check.py (both modes) before pushing, since this touches parsing logic.

C and Swift are the two most likely to need actual language_standards.py regex changes (not just measurement); the rest may turn out to be ground-truth scope mismatches like csharp's enums, fixable with no code change at all beyond flipping the allowlist.

Activity

  1. added
    enhancement
    testing
    core-engine
    on Aug 12, 2026
  2. squid-protocol commented on Aug 12, 2026

    @squid-protocol
    OwnerAuthor

    Scaffolding done: tooling + a significant scope revision

    Built out the process for this epic (checklist doc, offline triage script, skill, subagent -- PR incoming). While building the triage tool I found something that changes the priority order significantly.

    7 of the 13 languages listed above aren't measuring class recall at all right now. real_classes reads as 0 in tree_sitter_accuracy_audit.py for go, css, zig, perl, kotlin, objective-c, and html -- not because those languages lack real class/struct/interface-shaped code (they obviously don't), but because the ground-truth extraction itself is broken or mismatched:

    • go, kotlin, objective-c, zig: confirmed, fixable bug in _get_node_name -- the chosen class_node_types node (type_declaration, class_declaration, class_interface, ContainerDecl) exists and matches real declarations, but has no name field itself; the name lives on a child (type_spec for go, a positional type_identifier/identifier child for kotlin/objective-c) or an ancestor (VarDecl for zig's const Foo = struct{} idiom). Same kind of fix as the Fortran/C-declarator/Make special cases already in _get_node_name -- just needs the same treatment for these four. Exact node structure for each is in the new doc.
    • perl: ground truth targets class_statement (the new Perl 5.38+ class keyword), but real-world corpus code (exiftool) uses the traditional package Foo; idiom almost exclusively -- a different node type. Needs a judgment call on whether to add package_statement to class_node_types.
    • css, html: likely a conceptual mismatch rather than a bug -- rule_set/element don't have "names" the way GitGalaxy's own class_start regexes for those languages think about them (CSS selectors, a curated HTML tag list). Worth deciding whether these belong in this exercise at all.

    Only 6 languages currently have trustworthy ground truth to test a class_start regex against: c, swift, rust, dart, ruby, haskell. Recommend treating the ground-truth fixes (go/kotlin/objective-c/zig, all in tests/tools/tree_sitter_accuracy_audit.py, none touch language_standards.py) as their own small batch of PRs, separate from and probably before the regex-hardening work on the 6 languages above.

    Full detail, per-language diagnosis table, and the recurring-cause checklist are in tests/extraction/how_to_extend_class_start_named_extraction.md (landing in the scaffolding PR). New tool: python tests/tools/class_start_diff.py --lang <x> -- previews the real per-file extra/missing name diff for any language using the live pipeline's exact name-resolution algorithm, without needing to add it to the allowlist first.

  3. added 4 commits that reference this issue on Aug 12, 2026
  4. squid-protocol commented on Aug 12, 2026

    @squid-protocol
    OwnerAuthor

    go and objective-c done -- PR #1344

    Both were confirmed ground-truth measurement gaps (see the scaffolding comment above), not regex
    bugs. Fixed _get_node_name in tree_sitter_accuracy_audit.py:

    • go: type_declaration has no name field -- it's on the child type_spec. Flipped into
      _CLASS_START_NAMED_EXTRACTION_LANGS: found_classes 0→69, extra_classes 0→0. The 15
      tree-sitter-only "missing" are all plain type aliases (type WaitStatus uint32) that go's own
      class_start intentionally excludes (requires struct/interface to follow) -- a scope
      mismatch, not a recall bug, same shape as csharp's enum precedent in [TIER 1] Class detection is 0% across apex/csharp/fortran/solidity despite near-perfect function detection #1264.
    • objective-c: class_interface/class_implementation/class_declaration have no name
      field -- first positional identifier child is the name. Flipped into the allowlist:
      found_classes 0→5, extra_classes 0→0, a perfect match.

    crucible_check.py both modes clean, full core_engine/extraction suite passes (6573 tests),
    audit_check.py clean.

    Also found while there: kotlin and zig's ground-truth gaps are already fixed

    Not by this PR -- as a side effect of #1313's earlier function-extraction work, which added
    _get_node_name branches for kotlin's class_declaration and zig's ContainerDecl that also
    happen to resolve class names correctly. real_classes now reads 4 for kotlin and 642 for zig
    (previously 0 for both per the scaffolding comment above). Neither is flipped into the allowlist
    yet:

    • kotlin: found_classes is still 0, extra_classes is 5, all "Anonymous_Class" --
      class_start has no capture group (same shape as C/Swift). Needs the regex workflow, not more
      measurement-tool work. Moved from the "fixable now" table to "ground truth already works" in
      the checklist doc.
    • zig: extra_classes is 10, missing_classes is 23 -- needs a real per-file diff (same
      method as csharp/fortran in [TIER 1] Class detection is 0% across apex/csharp/fortran/solidity despite near-perfect function detection #1264) before concluding what's over/under-matching. Also moved to
      "ground truth already works."

    Updated tests/extraction/how_to_extend_class_start_named_extraction.md's tables to reflect all
    of this so the next pass doesn't re-derive it. Remaining: c, css, dart, haskell, html, kotlin,
    perl, ruby, rust, swift, zig
    (11 languages) -- of these, c/swift/rust/dart/ruby/haskell/kotlin/
    zig (8) are ready for the regex workflow now; css/html/perl (3) still need the judgment call
    described in the doc.

  5. squid-protocol commented on Aug 12, 2026

    @squid-protocol
    OwnerAuthor

    swift done -- PR #1361

    Two fixes, not one:

    1. class_start had no capture group around the name -- added one, widened to a dotted chain so nested-type extensions (extension AFError.ParameterEncoderFailureReason { ... }) capture their full qualified name.
    2. Found another ground-truth gap of the same shape go/kotlin/objective-c/zig hit: tree-sitter-swift gives protocols their own protocol_declaration node type, separate from class_declaration, which NODE_MAPS["swift"] didn't include -- undercounted real_classes by exactly the protocols with no same-named extension elsewhere in the corpus to accidentally surface them (e.g. Alamofire's RequestDelegate).

    found_classes 23→38, real_classes 37→38, extra_classes stays 0 -- perfect match. crucible_check.py (both modes) clean, full core_engine/extraction suite passes (6584 tests), audit_check.py clean.

    Remaining per the doc's tables: c, css, dart, haskell, html, kotlin, perl, ruby, rust, zig (10 languages, swift now off the list). kotlin and zig both need the regex workflow (ground truth already fixed, per the previous comment) -- kotlin is the same no-capture-group shape swift just went through, likely another quick one.

  6. squid-protocol commented on Aug 12, 2026

    @squid-protocol
    OwnerAuthor

    kotlin done -- PR #1365

    Flagged as "likely another quick one" (same no-capture-group shape swift just went through) -- turned out to be three stacked bugs:

    1. class_start had no capture group at all -- added group 1 for the main class|interface|object|enum class branch, group 2 for companion object's own optional name.
    2. fun interface Foo (SAM declarations, Kotlin 1.4+) wasn't recognized -- fun was missing from the modifier list. Real recall gap, confirmed against okhttp's fun interface Factory.
    3. Another ground-truth gap of the [TIER 1] Class detection is 0% across apex/csharp/fortran/solidity despite near-perfect function detection #1264/Extend #1264's per-language class_start named-entity extraction to the remaining 13 languages #1295 shape: kotlin's object declarations (including actual/expect multiplatform variants) get their own object_declaration node type, not class_declaration. Undercounted real_classes by every object singleton in the corpus.

    found_classes 3→7, real_classes 4→7, extra_classes stays 0 -- perfect match. Golden master updated both modes (okhttp/Call.kt's class count 1→2, all other diffs downstream numeric fallout of that one signal change). crucible_check.py clean, full suite passes, audit_check.py clean.

    Remaining per the doc's tables: c, css, dart, haskell, html, perl, ruby, rust, zig (9 languages). zig's ground truth already works (real_classes=642) but needs a real per-file diff before the regex workflow -- likely next since it's already unblocked.

  7. 11 remaining items

  8. squid-protocol commented on Aug 12, 2026

    @squid-protocol
    OwnerAuthor

    Correction + final update: 11 of 13 done, css/html closed by design

    My prior comment was stale (said "4 remain" / dart+ruby "pending merge" -- all 4 of that batch are
    now merged: #1377 haskell, #1378 c, #1385 dart, #1386 ruby).

    perl done -- PR #1393. Same shape as the other "quick" fixes this epic: no regex change, pure
    ground-truth gap. Perl's own class_start already correctly matches package|class|role;
    NODE_MAPS["perl"] only targeted the brand-new Perl 5.38+ class keyword, which real-world code
    (bugzilla, exiftool) essentially never uses -- the traditional package Foo::Bar; idiom is what
    actually needed to be added. real_classes 0→20, extra_classes 0 throughout, perfect match.

    css and html -- decided, not left open. Both were flagged from the start as needing a
    judgment call rather than a quick fix. Checked what class_data (this epic's target table)
    actually models: class_name/inheritance_parents/method_count/state_entanglement -- a real
    OOP-class schema. Neither css selectors nor generic HTML elements fit that shape (no methods, no
    code-structural inheritance) -- populating it with them would just be permanent
    method_count=0/inheritance_parents=[] noise in any downstream query, not a data-completeness
    win. Their class_start numeric signal (used in risk-scoring equations, a separate consumer)
    is completely unaffected -- this decision is scoped only to named extraction. Decision:
    permanently out of scope
    , documented in the checklist doc's own "Decided: not extending css or
    html" section so it doesn't get re-opened cold later.

    Final state: 11/13 done (go, objective-c, swift, kotlin, zig, rust, haskell, c, ruby, dart,
    perl). css/html closed by design. One small optional follow-up remains, documented not urgent:
    ruby's singleton_class has no real name to resolve (3 occurrences total, cosmetic).

    Epic is effectively complete pending #1393's merge.

  9. squid-protocol commented on Aug 13, 2026

    @squid-protocol
    OwnerAuthor

    Closing -- 11/13 languages done (go, objective-c, swift, kotlin, zig, rust, haskell, c, ruby, dart, perl), all confirmed wired into _CLASS_START_NAMED_EXTRACTION_LANGS in gitgalaxy/core/detector.py. Final language, perl, landed via #1393 (merged 2026-08-12). css and html are permanently out of scope by design (documented in the epic's checklist doc) -- neither fits class_data's OOP-class schema (no methods, no inheritance), so named extraction would just produce permanent noise; their existing numeric class_start risk-scoring signal is unaffected. One optional cosmetic follow-up remains (ruby's singleton_class has no real name to resolve, 3 occurrences total) but is low priority and not blocking closure.

  10. added this to the v2.4.8 milestone on Aug 16, 2026
  11. added a commit that references this issue on Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    core-engineenhancementtesting

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions