feat: add --score-command metric gate with keep/discard and non-improving stop - #186
Open
caretak3r wants to merge 1 commit into
Open
feat: add --score-command metric gate with keep/discard and non-improving stop#186caretak3r wants to merge 1 commit into
caretak3r wants to merge 1 commit into
Conversation
…ving stop Score each successful iteration with an external command before commit. A score strictly better than best (per --score-direction min|max) commits and persists best-metric under .gnhf/runs/<id>/ (resume-safe). A worse or unparseable score resets the worktree via the existing failure path and never crashes the run. The run stops after --stop-after-non-improving consecutive non-improving iterations (default 3) with a distinct stop reason. Default behavior is unchanged when --score-command is unset.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
gnhf currently commits every iteration the agent reports as successful. The agent's self-report is the only gate, so a run can accumulate commits that make the actual target worse. This PR adds an optional, externally measured keep/discard gate: score the workspace after each successful iteration and keep the commit only if the score strictly improved.
What it does
New flags (all optional; default behavior is unchanged when --score-command is unset):
--score-command <cmd>: shell command run in the workspace after a successful iteration; its last non-empty stdout line is parsed as a number.--score-direction <min|max>: required with --score-command; defines improvement.--stop-after-non-improving <N>: stop the run after N consecutive non-improving iterations (default 3), with a distinct stop reason.Behavior:
.gnhf/runs/<id>/best-metric(only after the commit lands, so a commit failure cannot advance the best). Resume reads it back, following the stop-when file pattern.Tests
e2e/e2e-metric-gate.test.ts) against dist/cli.mjs + the mock server: improving scores commit and persist best-metric; non-improving scores leave no commit and a clean worktree; unparseable scores stop the run via the metric gate without crashing.Naming and UX are negotiable: happy to rename the flags (e.g. --verify-command) or feed the measured score back into iteration prompts if you'd prefer that direction.