← Back to Pull requests

feat(mcp): let agents run checks on staged files only #1640

Closed
unknown closed this pull request without merging on Oct 04, 2026 01:05 UTC
View on GitHub
unknown unknown commented on Oct 03, 2026 23:25 UTC
Author

<!-- entire-trail-link-start -->
https://entire.io/gh/jdx/hk/trails/216
<!-- entire-trail-link-end -->

Stacked on #1600; this PR will retarget to main when that merges.

What this adds

An agent using hk's MCP tools can now check just the files staged in the index, which is what a pre-commit hook would check, before it commits:

{ "name": "start_check", "arguments": { "scope": "staged" } }

start_check, start_safe_check and start_safe_fix accept staged alongside all (default), changed and unstaged. With files staged.txt (edit staged) and unstaged.txt (edit not staged), scope: "staged" runs steps on staged.txt only. The scope maps to hk --staged.

Details

  • staged runs without stashing, like changed, so a staged file that also has unstaged edits is checked as it is in the working tree.

  • HK_STASH_UNTRACKED=0 only affects changed and unstaged; untracked files are never staged, so staged is unaffected. The docs say so.

  • The scope JSON schema and tool description list the new value, and the rejection message for an unknown scope now lists staged. The dashboard does not show scope, so it needed no change.

  • Docs updated in docs/agents.md and the sea shanty variant docs/pirate/agents.md (restamped).
  • Validation

  • cargo fmt --check, cargo clippy --all-targets -- -D warnings, cargo test mcp (26 passed).

  • New bats file test/mcp_scope.bats drives a real hk mcp over stdio: a staged-only check sees the staged edit and ignores an unstaged edit and an untracked file; unstaged still skips the staged file. Ran 2/2 ok with the default and HK_LIBGIT2=0. The nogit variant and CI were not run locally, and GNU parallel is not installed here, so I ran bats directly rather than through mise run test:bats.

  • aube run pirate check agents.md passes.

  • Not tested: the claim that a partially staged file is checked as it lies in the working tree follows from --staged disabling stashing in src/hook.rs; no test covers it.
  • 🤖 Generated with Claude Code

    AI-assisted — Tool: Claude Code; model: anthropic/claude-sonnet-5-5; version: unavailable.

    <!-- CURSOR_SUMMARY -->
    ---

    [!NOTE]

    Low Risk

    Additive MCP scope wired to existing --staged CLI behavior; unit and integration tests cover parsing and file selection.

    > Overview

    MCP start_check, start_safe_check, and start_safe_fix now accept scope: "staged", alongside all, changed, and unstaged. That scope limits runs to index-staged files (pre-commit style) by passing hk --staged, with no stashing—same idea as changed—so partially staged files are checked from the working tree.

    > RunScope in src/cli/mcp.rs gains the new variant, JSON schema/tool text, and unknown-scope errors now list staged. Agent docs (docs/agents.md and pirate mirror) document the scope table and stash/untracked behavior (HK_STASH_UNTRACKED does not affect staged).

    > Integration coverage adds test/mcp_scope.bats and test/test_helper/mcp_scope.py, driving a real hk mcp session to assert staged only sees staged files (not unstaged or untracked) and unstaged still excludes staged files.

    > <sup>Reviewed by Cursor Bugbot for commit b54cc3396dd6b6e836a81662fe10403f9021ea07. Bugbot is set up for automated code reviews on this repo. Configure here.</sup>

    <!-- /CURSOR_SUMMARY -->

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    Summary by CodeRabbit

    New Features
    MCP checks now support a staged scope to select files that have been added to the index.
    Staged checks inspect each selected file’s current working-tree contents, including any unstaged edits to that file.
    changed and staged checks run without stashing changes.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 499 lines (+374 / -125) across 6 files Reviewer: jdx Review duration: 99m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.47) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 499 lines diff across 6 files
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.372
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1640"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.5% (MEDIUM) · Higher = larger blast radius
    47.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%
    Repository