Skip to content

feat(p2): Context + Contract extractors with tests - #2

Merged
KooshaPari merged 1 commit into
mainfrom
feat/p2-context-contract-extractors
Jun 30, 2026
Merged

feat(p2): Context + Contract extractors with tests#2
KooshaPari merged 1 commit into
mainfrom
feat/p2-context-contract-extractors

Conversation

@KooshaPari

Copy link
Copy Markdown
Owner

P2 SessionLedger: Context bundle + Acceptance Contract extraction, hexagonal, following P1 IntentExtractor pattern. Gate green.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@KooshaPari, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 57 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Free

Run ID: 7632990c-e767-49c9-93a7-aa281c1f3e60

📥 Commits

Reviewing files that changed from the base of the PR and between d12210a and 3361097.

📒 Files selected for processing (9)
  • src/distill/context_extractor.rs
  • src/distill/contract_extractor.rs
  • src/distill/mod.rs
  • src/domain/context.rs
  • src/domain/contract.rs
  • src/domain/mod.rs
  • src/lib.rs
  • src/ports/mod.rs
  • tests/skeleton.rs

Note

🎁 Summarized by CodeRabbit Free

The PR author is not assigned a seat. To perform a comprehensive line-by-line review, please assign a seat to the pull request author through the subscription management page by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces heuristic context and contract extraction adapters along with their corresponding domain models, traits, and integration into the compilation bundle. The feedback highlights several areas for improvement in the heuristic parsing logic: ensuring that decisions and contract criteria are not overly deduplicated by generic keyword matches (which discards actual message content), refining token cleaning to handle trailing punctuation for file paths and symbols, and preventing URLs from being falsely classified as file paths.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +136 to +145
// --- Decisions ---
for pat in DECISION_PATTERNS {
if lower.contains(pat) {
let summary = format!("Session contains '{pat}' language");
let decision = Decision { summary, rationale: Some(content.to_string()) };
if !key_decisions.iter().any(|d| d.summary == decision.summary) {
key_decisions.push(decision);
}
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Deduplicating decisions solely by the generic summary (e.g., Session contains 'decided' language) means that only the first decision matching a given keyword is ever recorded. Any subsequent decisions in different messages using the same keyword are silently discarded. Deduplicating by the message content (rationale) instead allows capturing multiple distinct decisions across the session.

Suggested change
// --- Decisions ---
for pat in DECISION_PATTERNS {
if lower.contains(pat) {
let summary = format!("Session contains '{pat}' language");
let decision = Decision { summary, rationale: Some(content.to_string()) };
if !key_decisions.iter().any(|d| d.summary == decision.summary) {
key_decisions.push(decision);
}
}
}
// --- Decisions ---
for pat in DECISION_PATTERNS {
if lower.contains(pat) {
let summary = format!("Session contains '{pat}' language");
let decision = Decision { summary, rationale: Some(content.to_string()) };
if !key_decisions.iter().any(|d| d.rationale.as_deref() == Some(content)) {
key_decisions.push(decision);
break;
}
}
}

Comment on lines +128 to +166
// --- Success criteria ---
for pat in CRITERIA_PATTERNS {
if lower.contains(pat) {
let crit = format!("Goal/requirement: '{pat}'");
if !success_criteria.contains(&crit) {
success_criteria.push(crit);
}
}
}

// --- Tests / verifications ---
for pat in TEST_PATTERNS {
if lower.contains(pat) {
let test = format!("Verification: '{pat}'");
if !tests_or_verifications.contains(&test) {
tests_or_verifications.push(test);
}
}
}

// --- Constraints ---
for pat in CONSTRAINT_PATTERNS {
if lower.contains(pat) {
let constraint = format!("Constraint: '{pat}'");
if !constraints.contains(&constraint) {
constraints.push(constraint);
}
}
}

// --- Do-not-touch ---
for pat in DO_NOT_TOUCH_PATTERNS {
if lower.contains(pat) {
let dnt = format!("Do-not-touch: '{pat}'");
if !do_not_touch.contains(&dnt) {
do_not_touch.push(dnt);
}
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The contract extractor currently formats extracted criteria using only the matched pattern (e.g., Goal/requirement: 'goal') and deduplicates based on this generic string. This completely discards the actual message content containing the specific requirement or constraint, and prevents extracting multiple distinct criteria that happen to match the same keyword. Including the message content in the formatted string preserves the actual criteria and allows proper deduplication.

            // --- Success criteria ---
            for pat in CRITERIA_PATTERNS {
                if lower.contains(pat) {
                    let crit = format!("Goal/requirement: '{pat}' ({})", msg.content.trim());
                    if !success_criteria.contains(&crit) {
                        success_criteria.push(crit);
                    }
                }
            }

            // --- Tests / verifications ---
            for pat in TEST_PATTERNS {
                if lower.contains(pat) {
                    let test = format!("Verification: '{pat}' ({})", msg.content.trim());
                    if !tests_or_verifications.contains(&test) {
                        tests_or_verifications.push(test);
                    }
                }
            }

            // --- Constraints ---
            for pat in CONSTRAINT_PATTERNS {
                if lower.contains(pat) {
                    let constraint = format!("Constraint: '{pat}' ({})", msg.content.trim());
                    if !constraints.contains(&constraint) {
                        constraints.push(constraint);
                    }
                }
            }

            // --- Do-not-touch ---
            for pat in DO_NOT_TOUCH_PATTERNS {
                if lower.contains(pat) {
                    let dnt = format!("Do-not-touch: '{pat}' ({})", msg.content.trim());
                    if !do_not_touch.contains(&dnt) {
                        do_not_touch.push(dnt);
                    }
                }
            }

Comment on lines +101 to +112
// --- Files ---
for token in &tokens {
let clean = token.trim_matches(|c: char| {
!c.is_alphanumeric() && c != '/' && c != '.' && c != '-' && c != '_'
});
if is_file_path(clean) {
let fp = clean.to_string();
if !files_mentioned.contains(&fp) {
files_mentioned.push(fp);
}
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

If a file path is mentioned at the end of a sentence (e.g., src/auth/mod.rs.), the trailing period is not trimmed because . is excluded from the trimmed characters. This causes the extractor to capture the path with the trailing period, or fail to match the extension entirely. Trimming trailing periods from the cleaned token resolves this issue.

Suggested change
// --- Files ---
for token in &tokens {
let clean = token.trim_matches(|c: char| {
!c.is_alphanumeric() && c != '/' && c != '.' && c != '-' && c != '_'
});
if is_file_path(clean) {
let fp = clean.to_string();
if !files_mentioned.contains(&fp) {
files_mentioned.push(fp);
}
}
}
// --- Files ---
for token in &tokens {
let mut clean = token.trim_matches(|c: char| {
!c.is_alphanumeric() && c != '/' && c != '.' && c != '-' && c != '_'
});
if clean.ends_with('.') {
clean = clean.trim_end_matches('.');
}
if is_file_path(clean) {
let fp = clean.to_string();
if !files_mentioned.contains(&fp) {
files_mentioned.push(fp);
}
}
}

Comment on lines +114 to +134
// --- Symbols (identifiers with :: or () pattern) ---
// Look for token-like patterns (CamelCase, snake_case with parens or ::)
for token in &tokens {
let clean = token.trim_matches(|c: char| {
c == '('
|| c == ')'
|| c == ','
|| c == ';'
|| c == '{'
|| c == '}'
|| c == '['
|| c == ']'
});
let is_func_call = token.contains("()");
if clean.contains("::") || is_func_call {
let sym = clean.to_string();
if !key_symbols.contains(&sym) {
key_symbols.push(sym);
}
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The current symbol extraction logic uses a hardcoded list of characters to trim, which leaves trailing periods, question marks, or other punctuation intact (e.g., verify_token(). becomes verify_token().). We can make this much more robust by trimming all non-alphanumeric characters except _ and : from the boundaries of the token.

            // --- Symbols (identifiers with :: or () pattern) ---
            // Look for token-like patterns (CamelCase, snake_case with parens or ::)
            for token in &tokens {
                let clean = token.trim_matches(|c: char| {
                    !c.is_alphanumeric() && c != '_' && c != ':'
                });
                let is_func_call = token.contains("()");
                if (clean.contains("::") || is_func_call) && !clean.is_empty() {
                    let sym = clean.to_string();
                    if !key_symbols.contains(&sym) {
                        key_symbols.push(sym);
                    }
                }
            }

Comment on lines +183 to +194
fn is_file_path(token: &str) -> bool {
if token.is_empty() || token.len() < 3 {
return false;
}
// Must contain a `/` or start like a relative path (e.g. `src/`).
if token.contains('/') {
return true;
}
// Match common file extensions.
let lower = token.to_lowercase();
FILE_EXTENSIONS.iter().any(|ext| lower.ends_with(ext) && lower.len() > ext.len())
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The is_file_path function checks if a token contains /. This causes it to incorrectly classify HTTP/HTTPS URLs (e.g., https://github.com) as file paths. Adding a simple prefix check to ignore URLs prevents this false positive.

fn is_file_path(token: &str) -> bool {
    if token.is_empty() || token.len() < 3 {
        return false;
    }
    if token.starts_with("http://") || token.starts_with("https://") {
        return false;
    }
    // Must contain a `/` or start like a relative path (e.g. `src/`).
    if token.contains('/') {
        return true;
    }
    // Match common file extensions.
    let lower = token.to_lowercase();
    FILE_EXTENSIONS.iter().any(|ext| lower.ends_with(ext) && lower.len() > ext.len())
}

@KooshaPari
KooshaPari merged commit 937e7e9 into main Jun 30, 2026
7 of 11 checks passed
@KooshaPari
KooshaPari deleted the feat/p2-context-contract-extractors branch June 30, 2026 08:18
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.

1 participant