refactor: decompose domain analysis and feature modules#492
refactor: decompose domain analysis and feature modules#492carlos-alm merged 25 commits intomainfrom
Conversation
- Remove dead `truncate` function from ast-analysis/shared.js (0 consumers) - Remove dead `truncStart` function from presentation/table.js (0 consumers) - Un-export `BATCH_CHUNK` in builder/helpers.js (only used internally) Skipped sync.json targets that were false positives: - BUILTIN_RECEIVERS: used by incremental.js + build-edges.js - TRANSIENT_CODES/RETRY_DELAY_MS: internal to readFileSafe - MAX_COL_WIDTH: internal to printAutoTable - findFunctionNode: re-exported from index.js, used in tests Impact: 1 functions changed, 32 affected
Impact: 29 functions changed, 105 affected
…ures Impact: 5 functions changed, 7 affected
connection.js: add debug() logging to all 8 catch-with-fallback blocks so failures are observable without changing behavior. migrations.js: replace 14 try/catch blocks in initSchema with hasColumn() and hasTable() guards. CREATE INDEX calls use IF NOT EXISTS directly. getBuildMeta uses hasTable() check instead of try/catch. Impact: 10 functions changed, 19 affected
Add debug() logging to 10 empty catch blocks across context.js, symbol-lookup.js, exports.js, impact.js, and module-map.js. All catches retain their fallback behavior but failures are now observable via debug logging. Impact: 6 functions changed, 18 affected
Add debug() logging to 6 empty catch blocks: 3 in disposeParsers() for WASM resource cleanup, 2 in ensureWasmTrees() for file read and parse failures, and 1 in getActiveEngine() for version lookup. Impact: 3 functions changed, 0 affected
Add debug() logging to 9 empty catch blocks across complexity.js (5), cfg.js (2), and dataflow.js (2). All catches for file read and parse failures now log the error message before continuing. Impact: 4 functions changed, 2 affected
Split the monolithic walkJavaScriptNode switch (13 cases, cognitive 228) into 11 focused handler functions. The dispatcher is now a thin switch that delegates to handleFunctionDecl, handleClassDecl, handleMethodDef, handleInterfaceDecl, handleTypeAliasDecl, handleVariableDecl, handleEnumDecl, handleCallExpr, handleImportStmt, handleExportStmt, and handleExpressionStmt. The expression_statement case now reuses the existing handleCommonJSAssignment helper, eliminating ~50 lines of duplication. Worst handler complexity: handleVariableDecl (cognitive 20), down from the original monolithic function (cognitive 279). Impact: 13 functions changed, 3 affected
Split walkPythonNode switch into 7 focused handlers: handlePyFunctionDef, handlePyClassDef, handlePyCall, handlePyImport, handlePyExpressionStmt, handlePyImportFrom, plus the decorated_definition inline dispatch. Moved extractPythonParameters, extractPythonClassProperties, walkInitBody, and findPythonParentClass from closures to module-scope functions. Impact: 12 functions changed, 5 affected
Split walkJavaNode switch into 8 focused handlers plus an extractJavaInterfaces helper. Moved findJavaParentClass to module scope. The class_declaration case (deepest nesting in the file) is now split between handleJavaClassDecl and extractJavaInterfaces. Impact: 12 functions changed, 5 affected
Apply the same per-category handler decomposition to all remaining language extractors: Go (6 handlers), Ruby (8 handlers), PHP (11 handlers), C# (11 handlers), Rust (9 handlers), HCL (4 handlers). Each extractor now follows the template established by the JS extractor: - Thin entry function creates ctx, delegates to walkXNode - walkXNode is a thin dispatcher switch - Each case is a named handler function at module scope - Helper functions (findParentClass, etc.) moved to module scope Impact: 66 functions changed, 23 affected
…pers Move nested handler functions to module level in cfg-visitor.js, dataflow-visitor.js, and complexity-visitor.js — reducing cognitive complexity of each factory function from 100-337 down to thin coordinators. Extract WASM pre-parse, visitor setup, result storage, and build delegation from runAnalyses into focused helper functions. Impact: 66 functions changed, 43 affected
Extract edge-building by type (import, call-native, call-JS, class hierarchy) from buildEdges. Extract per-phase insertion logic from insertNodes. Extract scoped/incremental/full-build paths and reverse-dep cascade from detectChanges. Extract setup, engine init, alias loading from pipeline.js. Extract node/edge-building helpers from incremental.js rebuildFile. Impact: 44 functions changed, 19 affected
Impact: 37 functions changed, 29 affected
Impact: 5 functions changed, 3 affected
…sification Impact: 8 functions changed, 3 affected
Impact: 10 functions changed, 5 affected
Impact: 5 functions changed, 2 affected
Impact: 5 functions changed, 2 affected
Impact: 12 functions changed, 6 affected
…age) Extract per-section validators from validateBoundaryConfig (cog 101→2). Extract buildCommunityObjects and analyzeDrift from communitiesData (cog 32→4). Extract buildTriageItems and computeTriageSummary from triageData (bugs 1.4→0.48). Impact: 13 functions changed, 11 affected
|
Claude finished @carlos-alm's task —— View job PR Review: Refactor Domain Analysis and Feature ModulesReviewing this refactoring PR following the codegraph review process... Todo List
Phase 1: Root Cause Analysis ✅Problem Being Solved: This PR continues the "Titan quality sweep" by decomposing large, monolithic functions in domain analysis and feature modules into smaller, focused helpers. The goal is to improve cognitive complexity and maintainability. Why This Approach: The refactoring extracts reusable helper functions (e.g., Risk Assessment: Low risk - pure refactoring with no behavior changes, no config relaxations detected. Phase 2: Configuration Change Detection ✅No HIGH-RISK configuration changes detected:
Phase 3: Test Integrity ✅
Phase 4: Code Quality Review ✅Refactoring Pattern: Excellent decomposition approach - extracts focused helper functions while preserving public APIs:
Quality Indicators:
Phase 5: Backlog Compliance ✅Zero-dep: ✅ — No new runtime dependencies added to package.json Critical ConcernsNone identified. This is clean architectural refactoring. Final Recommendation
Strong points:
|
Greptile SummaryThis PR is a pure structural refactoring ("Titan quality sweep — phase 5b + 6.1") that decomposes large monolithic functions across the Key changes:
Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
subgraph domain["domain/analysis/"]
CTX["context.js\ncontextData / explainData"]
DEP["dependencies.js\nfnDepsData / pathData"]
IMP["impact.js\ndiffImpactData"]
MOD["module-map.js\nstatsData"]
end
subgraph features["features/"]
BND["boundaries.js\nvalidateBoundaryConfig"]
CFG["cfg.js\nbuildCFGData"]
COM["communities.js\ncommunitiesData"]
CPX["complexity.js\nbuildComplexityMetrics"]
DFL["dataflow.js\nbuildDataflowEdges"]
SEQ["sequence.js\nsequenceData"]
STR["structure.js\nbuildStructure"]
TRI["triage.js\ntriageData"]
end
subgraph presentation["presentation/queries-cli/"]
INS["inspect.js\ncontext / explain"]
OVW["overview.js\nstats"]
end
CTX --> |"buildCallees\nbuildCallers\nbuildRelatedTests\ngetComplexityMetrics\nexplainCallees"| H1(["helpers ×5"])
DEP --> |"bfsShortestPath\nreconstructPath\nresolveEndpoints\nbuildTransitiveCallers"| H2(["helpers ×4"])
IMP --> |"findGitRoot\nrunGitDiff\nparseGitDiff\nfindAffectedFunctions\nbuildFunctionImpactResults\nlookupCoChanges / Ownership / Boundaries"| H3(["helpers ×8"])
MOD --> |"buildTestFileIds\ncountNodesByKind\ncountEdgesByKind\nfindHotspots\ncomputeQualityMetrics\n+4 more"| H4(["helpers ×9"])
BND --> |"validateModules\nvalidatePreset\nvalidateTargetList\nvalidateRules\nvalidateLayerAssignments"| H5(["helpers ×5"])
CFG --> |"initCfgParsers\ngetTreeAndLang\nbuildVisitorCfgMap\npersistCfg"| H6(["helpers ×4"])
COM --> |"buildCommunityObjects\nanalyzeDrift"| H7(["helpers ×2"])
CPX --> |"initWasmParsersIfNeeded\ngetTreeForFile\nupsertPrecomputed\nupsertAstComplexity"| H8(["helpers ×4"])
DFL --> |"initDataflowParsers\ngetDataflowForFile\ninsertDataflowEdges"| H9(["helpers ×3"])
SEQ --> |"findEntryNode\nbfsCallees\nannotateDataflow\nbuildParticipants"| H10(["helpers ×4"])
STR --> |"getAncestorDirs\ncleanupPreviousData\ncollectAllDirs\ninsertContainsEdges\ncomputeImportEdgeMaps\n+2 more"| H11(["helpers ×7"])
TRI --> |"buildTriageItems\ncomputeTriageSummary\nSORT_FNS / EMPTY_SUMMARY"| H12(["helpers ×4"])
INS --> |"renderContextResult\nrenderFileExplain\nrenderFunctionExplain"| H13(["helpers ×3"])
OVW --> |"printCountGrid\nprintNodes / Edges / Files\nprintCycles / Hotspots\nprintQuality / Roles / Complexity / Communities"| H14(["helpers ×11"])
Last reviewed commit: bb2729e |
# Conflicts: # src/ast-analysis/engine.js # src/db/migrations.js # src/domain/analysis/context.js # src/domain/analysis/impact.js # src/domain/analysis/module-map.js # src/domain/graph/builder/stages/build-edges.js # src/domain/graph/builder/stages/detect-changes.js # src/extractors/csharp.js # src/extractors/go.js # src/extractors/java.js # src/extractors/php.js # src/extractors/rust.js # src/features/cfg.js # src/features/complexity.js # src/features/dataflow.js # src/features/shared/find-nodes.js Impact: 26 functions changed, 42 affected
Impact: 27 functions changed, 80 affected
|
Resolved 16 merge conflicts with main — kept PR's refactored helpers for domain analysis and features, main's extractor guards, hasTable safety improvements, and find-nodes validation. |
…into refactor/titan-domain-features # Conflicts: # src/features/complexity.js
Summary
Titan quality sweep — phase 5b + 6.1: decompose domain analysis functions and feature modules.
Domain analysis
contextData→ split file-context from function-context assemblydiffImpactData→ separate git-diff parsing from impact aggregationstatsData→ extract stats collection and quality scoringpathData/fnDepsData→ extract path formatting helpersFeatures
buildComplexityMetrics→ extract metric collection and formattingbuildStructure→ split traversal, cohesion scoring, classificationbuildCFGData/buildDataflowEdges→ extract graph construction helperssequenceData→ separate BFS traversal from message constructionvalidateBoundaryConfig(cog 101→2) → extract per-section validatorscommunitiesData(cog 32→4) → extract community building and drift analysistriageData(bugs 1.4→0.48) → extract scoring and summary computationStacked on
Files changed (12)
src/domain/analysis/context.js,dependencies.js,impact.js,module-map.jssrc/features/complexity.js,structure.js,cfg.js,dataflow.js,sequence.jssrc/features/boundaries.js,communities.js,triage.jsTest plan