Skip to content

fix: address remaining quality issues across domains#774

Merged
carlos-alm merged 2 commits intofix/empty-catch-blocksfrom
fix/remaining-quality-issues
Apr 3, 2026
Merged

fix: address remaining quality issues across domains#774
carlos-alm merged 2 commits intofix/empty-catch-blocksfrom
fix/remaining-quality-issues

Conversation

@carlos-alm
Copy link
Copy Markdown
Contributor

Summary

  • Address remaining FAIL-level quality issues across multiple domains
  • Fix halsteadEffort violations in domain analysis, features, MCP, and presentation modules

Titan Audit Context

Changes

  • src/domain/analysis/context.ts - Reduce complexity
  • src/domain/analysis/dependencies.ts - Reduce complexity
  • src/domain/parser.ts - Reduce complexity
  • src/features/communities.ts - Reduce complexity
  • src/mcp/server.ts - Reduce complexity
  • src/presentation/dataflow.ts - Reduce complexity
  • src/presentation/queries-cli/exports.ts - Reduce complexity
  • src/presentation/queries-cli/impact.ts - Reduce complexity
  • src/presentation/queries-cli/overview.ts - Reduce complexity
  • src/presentation/queries-cli/path.ts - Reduce complexity
  • src/presentation/viewer.ts - Reduce complexity

Test plan

  • CI passes (lint + build + tests)
  • No new functions above complexity thresholds

Extract sub-functions to reduce halsteadEffort and cognitive complexity
in 11 FAIL targets: dependencies, communities, server, parser, context,
overview, impact, exports, path, viewer, dataflow. All functions now
pass gate thresholds (cognitive <= 30, halstead.bugs <= 1.0, MI >= 20).
@claude
Copy link
Copy Markdown

claude bot commented Apr 3, 2026

Claude finished @carlos-alm's task —— View job


PR Review: Quality Issues Fix

Reviewing PR #774 for quality improvements across multiple domains.

Todo List:

  • Phase 1: Root cause analysis
  • Phase 2: Configuration change detection
  • Phase 3: Test integrity check
  • Phase 4: Code quality review of changed files
  • Phase 5: Backlog compliance assessment
  • Final assessment and recommendation

Root Cause Analysis

Problem Being Solved: Addresses FAIL-level quality issues (halsteadEffort violations) identified by quality analysis across multiple modules. Part of structured quality improvement effort following PRs #764 (empty catch fixes) and #765 (console.log fixes).

Why This Approach: Uses proper refactoring by extracting helper functions rather than suppressing linting rules. Breaks down complex 80+ line functions into focused 20-30 line helpers with clear single responsibilities.

Risk Assessment: Very low risk. Pure refactoring with no behavior changes, following established codebase patterns.

Backlog Compliance

  • Zero-dep: ✓ — No new runtime dependencies
  • Foundation-aligned: ✓ — Code quality improvements support P5 (embeddable-first) by improving maintainability
  • Problem-fit: 3 — Quality improvements indirectly support AI agent usage but don't directly address the core token waste/dependency hallucination problem
  • Breaking: No — Pure internal refactoring, no API changes
  • Tier: 1 — Foundation-aligned, zero-dep quality improvement

Critical Concerns

None found. This is exemplary refactoring work:

Quality of refactoring: All extractions follow Single Responsibility Principle
Function naming: Clear, descriptive names (buildIntraFileDataFlow, buildTransitiveCallers, etc.)
No behavior changes: Preserved all existing functionality and error handling
Consistent patterns: Follows existing codebase conventions for helper function extraction
Test coverage: No test changes needed since behavior is preserved

Specific improvements:

  • src/domain/analysis/context.ts:267 - Extracted buildIntraFileDataFlow() helper
  • src/domain/analysis/dependencies.ts:68 - Extracted buildTransitiveCallers() for BFS logic
  • src/domain/parser.ts:310 - Split monolithic patches into focused helpers
  • All presentation modules properly separated display logic from business logic

Final Recommendation

  • Rating: ⭐⭐⭐⭐☆ (4/5)
  • Action: APPROVE
  • Reasoning: High-quality refactoring that meaningfully improves code maintainability. Addresses quality debt in a proper way (extraction over suppression). No risks or concerns identified. The only reason it doesn't get 5 stars is that it's addressing technical debt rather than delivering new user value.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 3, 2026

Greptile Summary

This PR is a pure complexity-reduction refactor across 11 files — no behavioral changes. Each changed file applies the same mechanical pattern: inline logic blocks that exceeded Halstead-effort thresholds are extracted into small, named helper functions. The extracted helpers (buildIntraFileDataFlow, buildNodeDepsResult, disposeMapEntries, createCallToolHandler, resolvePlotConfig, etc.) are all module-private and have clear, single responsibilities.

Key observations:

  • All extractions are behaviorally equivalent to their inline originals — indentation strings, sort orders, guard conditions, and output formats are preserved exactly.
  • The previously flagged hc: Map<unknown, unknown> type error in dependencies.ts has been corrected to Map<string, string | null>.
  • disposeMapEntries in parser.ts correctly unifies three identical try/catch loops while preserving the null-check and typeof item.delete === 'function' guard for each entry type.
  • createCallToolHandler in mcp/server.ts converts implicitly captured closure variables into explicit parameters, making the handler's dependencies auditable at the call site.
  • No new symbols are exported; all helpers are file-private, keeping the public API surface unchanged.

Confidence Score: 5/5

Safe to merge — all changes are pure extract-function refactors with no behavioral differences.

Every extracted function is a mechanically faithful lift of its inline predecessor. The prior P1 type error on hc has been fixed. No new logic, no new exports, no API surface changes. All 11 files score 5/5 individually. No P0 or P1 findings remain.

No files require special attention.

Important Files Changed

Filename Overview
src/domain/analysis/context.ts Extracted buildIntraFileDataFlow helper from explainFileImpl — pure refactor, behavior unchanged.
src/domain/analysis/dependencies.ts Extracted collectCallersWithHierarchy and buildNodeDepsResult; hc type corrected to Map<string, string
src/domain/parser.ts Unified three identical try/catch dispose loops into disposeMapEntries; null-check and .delete guard preserved, behavioral parity confirmed.
src/features/communities.ts Split analyzeDrift into buildDirToCommunities, findSplitCandidates, and findMergeCandidates — straightforward decomposition with no logic changes.
src/mcp/server.ts Extracted createCallToolHandler factory from startMCPServer; all captured values are now explicit parameters, handler closure semantics identical to inline version.
src/presentation/dataflow.ts Extracted printDataflowFlows, printDataflowReturns, printDataflowMutations — output format fully preserved.
src/presentation/queries-cli/exports.ts Extracted groupByOriginFile and printReexportSymbol; indentation strings passed as argument match original hardcoded values exactly.
src/presentation/queries-cli/impact.ts Extracted printFnImpactLevels — logic and output format identical to inlined version.
src/presentation/queries-cli/overview.ts Extracted groupByRole and printRoleGroup from roles — clean decomposition, no behavioral changes.
src/presentation/queries-cli/path.ts Extracted printFilePathNotFound and printFilePathSteps from filePath; all conditional branches preserved correctly.
src/presentation/viewer.ts Extracted resolvePlotConfig with typed ResolvedPlotConfig interface — all eight config fields resolved identically to the original inline assignments.

Sequence Diagram

sequenceDiagram
    participant Client as MCP Client
    participant Server as startMCPServer
    participant Factory as createCallToolHandler
    participant Handler as CallToolHandler (closure)
    participant Tools as TOOL_HANDLERS

    Server->>Factory: createCallToolHandler(multiRepo, dbPath, allowedRepos, getQueries)
    Factory-->>Server: async (request) => { ... }
    Server->>Server: server.setRequestHandler(CallToolRequestSchema, handler)

    Client->>Server: tool call request
    Server->>Handler: invoke(request)
    Handler->>Handler: validateMultiRepoAccess(multiRepo, name, args)
    Handler->>Handler: resolveDbPath(customDbPath, args, allowedRepos)
    Handler->>Tools: TOOL_HANDLERS.get(name)
    Tools-->>Handler: toolEntry
    Handler->>Handler: toolEntry.handler(args, ctx)
    Handler-->>Client: { content: [...] }
Loading

Reviews (2): Last reviewed commit: "fix: correct hc parameter type in buildN..." | Re-trigger Greptile

function buildNodeDepsResult(
db: BetterSqlite3Database,
node: NodeRow,
hc: Map<unknown, unknown>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Incorrect type for hc — TypeScript error when passed to normalizeSymbol

normalizeSymbol declares its third parameter as hashCache?: Map<string, string | null> (see src/shared/normalize.ts:64). The newly extracted function types hc as Map<unknown, unknown>, which is not assignable to Map<string, string | null> because unknown does not satisfy the string | null value constraint on the return type of Map.get. TypeScript will emit a type error on the ...normalizeSymbol(node, db, hc) spread.

The original code passed an untyped new Map() (inferred as Map<any, any>) that was silently widened. The correct fix is to use the concrete type that normalizeSymbol actually expects:

Suggested change
hc: Map<unknown, unknown>,
hc: Map<string, string | null>,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — changed hc: Map<unknown, unknown> to hc: Map<string, string | null> to match normalizeSymbol's hashCache parameter type. Commit 50af5d7.

Change Map<unknown, unknown> to Map<string, string | null> to match
normalizeSymbol's hashCache parameter type, fixing a TS2345 build error.
@carlos-alm
Copy link
Copy Markdown
Contributor Author

Addressed Greptile's review: Fixed the hc parameter type in buildNodeDepsResult from Map<unknown, unknown> to Map<string, string | null> to match normalizeSymbol's expected type. This was the only build-breaking issue identified. TypeScript now compiles clean.

@greptileai

@carlos-alm carlos-alm merged commit e7d860f into fix/empty-catch-blocks Apr 3, 2026
14 checks passed
@carlos-alm carlos-alm deleted the fix/remaining-quality-issues branch April 3, 2026 03:43
@github-actions github-actions bot locked and limited conversation to collaborators Apr 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant