Skip to content

fix(pipeline): enforce staged-file scope in implement step — prevent git add -A #1626

@nextlevelshit

Description

@nextlevelshit

Problem

The implement step's craftsman persona ran git add -A (or equivalent), staging 3280 files — the entire worktree — instead of only the files it modified for the issue. The prompt explicitly says "Do NOT use git add -A or git add . — stage specific files only" but the model ignored this instruction.

Observed with opencode adapter on impl-issue run for #1622. The implement prompt has this constraint but no enforcement.

Impact

  • PRs contain entire repo diff instead of targeted changes
  • test_diff and test_count_baseline contracts can't detect test deletions (baseline is polluted by unrelated files)
  • Review quality degrades — 3280-file diff is unreviewable
  • Wastes git storage and CI time

Proposal: staged-file scope enforcement

Add a post-implement contract that validates the commit scope:

  1. New contract type: commit_scope — after implement step commits, check that the diff contains only files related to the issue. Implementation options:

    • Option A (cheap): Check file count threshold (e.g., max_files: 50). If exceeded → rework. Catches the git add -A case.
    • Option B (smart): Compare committed files against the impl-plan.json files_to_modify list. Any file not in the plan → warning or rework.
    • Option C (hybrid): Threshold check first (Option A), then plan-aware check if threshold passes (Option B).
  2. Prompt hardening: Add a stronger constraint in implement.md and fix-implement.md:

    CRITICAL: After committing, run `git diff --name-only HEAD~1`. If more than 10 files
    appear, you staged too much. Run `git reset HEAD`, re-stage only your changes,
    and re-commit.
    
  3. Rework loop integration: commit_scope contract with on_failure: rework feeds into the existing fix-implement step.

Recommended: Option A (threshold) + prompt hardening

Option A is cheap, catches the common case, and doesn't require plan-schema changes. Prompt hardening adds a self-check. Option B/C can be added later if threshold false-positives occur.

# impl-issue.yaml implement step handover:
- type: commit_scope
  max_files: 50
  on_failure: rework

Files to touch

  • internal/contract/commit_scope.go — new contract type
  • internal/contract/registry.go — register commit_scope
  • internal/defaults/embedfs/pipelines/impl-issue.yaml — add to implement handover
  • .agents/pipelines/impl-issue.yaml — same
  • internal/defaults/embedfs/prompts/implement/implement.md — add self-check instruction

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions