Skip to content

feat(app): make commit history depth configurable via max_commit_count#2762

Open
tusharmath wants to merge 3 commits intomainfrom
commit-token-limit
Open

feat(app): make commit history depth configurable via max_commit_count#2762
tusharmath wants to merge 3 commits intomainfrom
commit-token-limit

Conversation

@tusharmath
Copy link
Copy Markdown
Collaborator

@tusharmath tusharmath commented Apr 1, 2026

Summary

Make the number of recent commits included as git context configurable via max_commit_count, replacing a hardcoded limit of 20.

Context

Git context (recent commits + branch name) is fetched and passed to the AI when generating commit messages and performing other git-aware operations. Previously, the commit history was always capped at 20 entries with no way for users to adjust this. In large repositories or workflows where more context improves AI output quality, this limit is too restrictive. Conversely, users in token-sensitive environments may want to reduce it.

Changes

  • Added max_commit_count field to ForgeConfig and Environment domain types
  • Updated git_app.rs to read max_commit_count from the environment instead of using a hardcoded 20
  • Infrastructure layer maps the optional config value to the environment, defaulting to 20 when unset (preserving existing behavior)
  • Updated forge.schema.json to expose the new field in the configuration schema
  • Set the default value in TestContext to maintain consistent test behavior

Key Implementation Details

The default value of 20 is preserved at the infrastructure boundary (forge_infra/src/env.rs), ensuring full backwards compatibility — existing configs without max_commit_count behave identically to before. The git log command is dynamically constructed with the configured limit before being executed.

Use Cases

  • Users working in repos with long, noisy commit histories can reduce the count to keep token usage lean
  • Users who need richer context for complex multi-step commits can increase it beyond 20
  • Teams with custom token budgets can tune this alongside other model parameters

Testing

Add the following to your forge.yaml (or forge.default.yaml) and verify that git context reflects the configured limit:

max_commit_count: 5

Then trigger a commit message generation or any workflow that reads git context, and confirm only the last 5 commits appear in the context.

To verify the default (no config key set) still works as before, remove the field and confirm behaviour is unchanged.

cargo insta test --accept -p forge_app
cargo insta test --accept -p forge_infra
cargo insta test --accept -p forge_config

@tusharmath tusharmath changed the title feat(app): add max_commit_count support for git context fetch feat(app): make commit history depth configurable via max_commit_count Apr 1, 2026
@github-actions github-actions bot added the type: feature Brand new functionality, features, pages, workflows, endpoints, etc. label Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feature Brand new functionality, features, pages, workflows, endpoints, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant