← Back to Documentation

The Tangent Scoring Engine

How TraceFlow knows you're off-track before you do.

The Problem with Simple Keyword Matching

A naive approach to tangent detection would compare the words in your AI prompt against the words in your project goal. But that breaks immediately. "Refactoring the auth middleware" and "Adding OAuth2 support" share almost no keywords, yet they're closely related work. Meanwhile, "Cleaning up the CSS in the login page" shares the word "login" with your goal but is a completely different task.

TraceFlow uses a dual-tier analysis that combines semantic understanding with structural awareness to produce an accurate divergence score.

Tier 1: Semantic Comparison

TraceFlow generates vector embeddings for both your Session.Summary (a rolling summary of your current AI conversation) and the Session.Baseline (the intent extracted from your session's early prompts and file activity, or an explicit goal if you've set one).

It then calculates the cosine similarity between these two vectors. This captures meaning, not just word overlap. "Refactoring auth middleware" and "Implement OAuth2 flow" score high similarity because they occupy the same semantic space, even though they share zero keywords.

# Simplified scoring logic
semantic_score = cosine_similarity(
embed(session.summary),
embed(session.baseline) # auto-extracted or manual override
)

Tier 2: Structural Comparison

Semantic similarity alone isn't enough. A developer might be discussing something conceptually related to the project goal but working in a completely unrelated part of the codebase. TraceFlow also compares the files being touched in the current session against the project's ArchitectureMap to detect structural drift.

If your goal is "Implement OAuth2 flow" and you're editing CSS files in the marketing site, the structural score drops even if the semantic score is reasonable.

# Structural overlap
structural_score = overlap(
session.files_touched,
project.architecture_map
)

Combined Score and Threshold

The two scores are combined into a single divergence metric. When the combined score falls below 0.65, TraceFlow emits a "Tangent Event" to the desktop agent and the Hub dashboard.

# Tangent detection
combined = (semantic_score * 0.6) + (structural_score * 0.4)
if combined < 0.65:
emit("tangent_event", session_id, combined)

The 60/40 weighting gives more influence to semantic meaning (what you're trying to do) than file structure (where you're doing it). This prevents false positives when developers legitimately need to touch unexpected files to accomplish their goal.

What Happens When a Tangent is Detected

1

Desktop Nudge

The TraceFlow tray icon shifts from green to amber. A notification appears with the divergence score and a one-line explanation of the drift.

2

Dashboard Highlight

The session turns red on the Mission Control dashboard, visible to team leads. The divergence score and drift direction are shown in real time.

3

Weekly Digest

The tangent is logged and included in the leader's weekly intelligence report, with time spent and estimated cost of the drift.

Tuning the Threshold

The default threshold of 0.65 works well for most teams. If you find you're getting too many false positives (common in exploratory research phases), you can lower it in your project config. If you want tighter control during a critical sprint, raise it.

# .traceflow/config.yaml
tangent:
threshold: 0.65
semantic_weight: 0.6
structural_weight: 0.4

Stop drifting. Start shipping.

Start Free Trial