Skip to content

feat(taint): consolidate cross-file engine into ast_taint_engine + deprecate semantic_engine (closes #49 phase-1) - #140

Merged
Wolfvin merged 1 commit into
mainfrom
feat/issue-49-taint-engine-consolidation
Jul 3, 2026
Merged

feat(taint): consolidate cross-file engine into ast_taint_engine + deprecate semantic_engine (closes #49 phase-1)#140
Wolfvin merged 1 commit into
mainfrom
feat/issue-49-taint-engine-consolidation

Conversation

@Wolfvin

@Wolfvin Wolfvin commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Closes #49 (Phase 1 only — Consolidation)

What

Implements Phase 1 of issue #49: taint analysis engine consolidation.

  1. Audit & document all 4 taint/dataflow engines in docs/taint-engine-audit.md
  2. Consolidate crossfile_taint_engine.py into ast_taint_engine.py — single unified entry point
  3. Deprecate semantic_engine.py with warning

Changes

ast_taint_engine.py

  • analyze_workspace() now accepts cross_file=True parameter
  • New _analyze_cross_file() method delegates to CrossFileTaintAnalyzer (lazy import avoids circular dep)
  • Module-level analyze_workspace() function also accepts cross_file

crossfile_taint_engine.py

  • Module docstring updated with deprecation notice
  • analyze_cross_file_taint() is now a thin compat wrapper that delegates to ast_taint_engine.analyze_workspace(cross_file=True)
  • Falls back to inline implementation if ast_taint_engine unavailable
  • CrossFileTaintAnalyzer class and CFG/call-graph infrastructure remain as implementation backend

semantic_engine.py

  • Module docstring updated with deprecation notice and migration path
  • _emit_deprecation_warning() prints to stderr once per process
  • TaintAnalyzer.__init__() and analyze_workspace() both emit warning
  • Deprecation path: v8.3 warning → v8.4 regex fallback in ast_taint → v9.0 removal

scripts/commands/taint.py

  • Simplified engine selection: routes through ast_taint_engine.analyze_workspace()
  • --cross-file flag sets cross_file=True (no longer calls crossfile_taint_engine directly)
  • --no-ast flag falls back to semantic_engine (deprecated path)

docs/taint-engine-audit.md (new)

  • Documents all 4 engines: capabilities, status, entry points, used by
  • Consolidation summary table
  • Unified API examples
  • Next phases roadmap (Phase 2-7)

Unified API

from ast_taint_engine import analyze_workspace

# Intra-file analysis (default)
result = analyze_workspace(workspace, language='python')

# Cross-file analysis (replaces crossfile_taint_engine.analyze_cross_file_taint)
result = analyze_workspace(workspace, language='python', cross_file=True)

Verification

  • cross_file=True produces identical results to the old compat wrapper
  • DeprecationWarning emitted on semantic_engine use (verified in test output)
  • Test suite: 1422 passed, 0 failed (no regressions)
  • Existing test_semantic_engine.py (33 tests) and test_dataflow_engine.py (9 tests) all pass

Not in this PR (future phases)

  • Phase 2: Unified cross-file engine reaching 5+ hops (currently 1 hop)
  • Phase 3: Signature extraction for performance (2x speedup)
  • Phase 4: Persistence / stored injection modeling
  • Phase 5: Library method approximation system
  • Phase 6: Debug-trace tool (codelens debug-rule)
  • Phase 7: LLM validator (optional)

Test plan

  • analyze_workspace(cross_file=True) matches analyze_cross_file_taint() output
  • DeprecationWarning emitted on semantic_engine use
  • Full test suite: 1422 passed, 0 failed
  • CI: full test suite passes

…precate semantic_engine (closes #49 phase-1)

Issue #49 Phase 1 — Taint analysis engine consolidation:

1. Audit & document all 4 taint/dataflow engines (docs/taint-engine-audit.md):
   - ast_taint_engine.py (3,755 LOC) — v1, AST-based, primary engine
   - crossfile_taint_engine.py (946 LOC) — v2, cross-file, now compat wrapper
   - dataflow_engine.py (1,097 LOC) — v3, source->sink, independent (not consolidated)
   - semantic_engine.py (428 LOC) — regex-based, deprecated

2. Consolidate crossfile_taint_engine into ast_taint_engine:
   - ast_taint_engine.analyze_workspace() now accepts cross_file=True parameter
   - ast_taint_engine._analyze_cross_file() method delegates to CrossFileTaintAnalyzer
   - crossfile_taint_engine.analyze_cross_file_taint() is now a thin compat wrapper
     that delegates to ast_taint_engine.analyze_workspace(cross_file=True)
   - Single unified entry point: ast_taint_engine.analyze_workspace()

3. Deprecate semantic_engine with warning:
   - DeprecationWarning emitted to stderr on first use (once per process)
   - Module docstring updated with deprecation notice and migration path
   - TaintAnalyzer class and analyze_workspace() both emit warning
   - Deprecation path: v8.3 warning -> v8.4 regex fallback in ast_taint -> v9.0 removal

4. Update taint command (scripts/commands/taint.py):
   - Routes all requests through ast_taint_engine.analyze_workspace()
   - --cross-file flag sets cross_file=True (no longer calls crossfile_taint_engine directly)
   - --no-ast flag falls back to semantic_engine (deprecated path)
   - Simplified engine selection logic

Verified: cross_file=True produces identical results to the old compat wrapper.
Test suite: 1422 passed, 0 failed (no regressions).
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@sonarqubecloud

sonarqubecloud Bot commented Jul 1, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
16.3% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@Wolfvin
Wolfvin merged commit 4cf5b18 into main Jul 3, 2026
4 of 11 checks passed
Wolfvin added a commit that referenced this pull request Jul 3, 2026
Add a new semantic-query CLI command + codelens_semantic_query MCP tool
that ranks symbols by cosine similarity to a natural-language query,
using zero-dependency TF-IDF over symbol names + signatures + kinds +
file paths. Implements Option A from issue #11 (Option B/C remain
future work for embedding-model-based search).

New files:
- scripts/semantic_search_engine.py — TF-IDF engine: tokenize, build
  vocabulary + IDF, compute sparse doc vectors, rank by cosine sim.
  Cached per (db_path, mtime) so re-scans auto-invalidate the index.
  Named semantic_search_engine (not semantic_engine) to avoid colliding
  with the pre-existing deprecated taint-analysis semantic_engine.py
  from PR #140.
- scripts/commands/semantic_query.py — CLI command registered as
  'semantic-query'. Auto-exposed as codelens_semantic_query MCP tool
  via the dynamic tool discovery path. Also added an explicit static
  tool definition in _TOOL_DEFINITIONS so the JSON schema is documented.
- tests/test_semantic_search_engine.py — 31 tests covering tokenizer,
  end-to-end query behavior, cache invalidation, graceful degradation,
  and TF-IDF ranking signal (rare-vs-common terms, multi-term queries).

Modified files (auto-synced by sync_command_count.py --apply):
- README.md, SKILL.md, SKILL-QUICK.md, pyproject.toml, skill.json,
  scripts/graph_model.py, scripts/mcp_server.py — command count 68->70,
  MCP tool count 66->68.

Tests: 1401 passed, 80 skipped, 1 pre-existing failure unrelated
(test_codelensignore::test_actual_target_dir_is_ignored — fails on
clean HEAD too, environmental issue with the 'target' ignore pattern).
@Wolfvin
Wolfvin deleted the feat/issue-49-taint-engine-consolidation branch July 3, 2026 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Taint analysis depth — unified cross-file engine + persistence + library approximation + debug trace

1 participant