Repository navigation
Send a token-budgeted staged context to the model - #43
Merged
Merged
Conversation
- Add `src/domain/context/` to parse the staged diff, fold identical edits, and lower per-file detail (full, changes, outline, stat) until the text fits `CONTEXT_BUDGET_TOKENS`. - Keep the exact staged diff when it fits the budget, so small commits get the same prompt as before. - Replace `getStagedDiff` with `getStagedSnapshot`, which pins the diff format against user git config and adds best-effort `git grep --cached` imports and `git log --full-diff` history. - Build the context once in `Commit.run` and pass it through split, regenerate, and adjust. - Add ranked file-pair grouping hints (tests, imports, co-change history) to the split prompt. - Send only the staged-file manifest to the refine prompt instead of the full diff. - Cover parsing, compression, hints, context building, the snapshot, and the adjust path with tests.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit bb439bb. Configure here.
- Drop paths the model lists in more than one commit in `dropRepeatedPaths` instead of failing with "Split plan: duplicate path". - Remove commits left empty after the dedupe. - Tell the split prompt never to list a path in two commits. - Cover the dedupe and the new prompt rule with unit tests.
- Print the reduction and both token counts via `compressionNote` in `src/cli/commit.ts`. - Cover the wording with unit tests.
- Let the doctor table's Info column fit its widest cell so PR URLs are no longer cut with an ellipsis. - Add `hyperlink` in `src/infra/ui/hyperlink.ts` to wrap URLs in OSC-8 links on a TTY. - Link the PR and remote URLs in the push note and the device verification URL in setup. - Cover the helper and the full doctor PR URL with unit tests.
- Add `quietLoading` in `src/infra/ui/spinner.ts`, which clears the spinner on success and still shows "Failed." on error. - Use it for the "Analyzing staged changes..." step in `src/cli/commit.ts`. - Mock `quietLoading` in the commit CLI tests.
- Run `stagedImportLines` with `-c core.quotepath=off` and `--no-color` so `color.ui=always` and non-ASCII paths still match staged files. - Assert on `importLines` in the color and non-ASCII snapshot integration test.
Owner
Author
|
cursor on
|
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
Large staged changes sent the full diff to the model on every generate, split, regenerate and adjust. On a 44-file change that came to about 49k estimated tokens per call. This PR caps it near a 12k budget.
What's New
Staged Context Pipeline
src/domain/context/module turns the staged diff into aStagedContextthat is built once percommitrun: a per-file manifest, grouping hints, and the text the model sees.CONTEXT_BUDGET_TOKENS(12k estimated tokens, chars / 4), the model gets exactly the textgetStagedDiffproduced before, so small commits are unchanged.# Filesmanifest list every staged path (A,M,D,R<similarity>,B) with line counts.Git Snapshot
getStagedSnapshotreplacesgetStagedDiff. It returns the same diff body and generated-files note, plusgit grep --cachedimport lines andgit log --full-diff --name-onlyhistory from the last 200 commits.core.quotepath=off,--no-color,--no-ext-diff,a/andb/prefixes), so accented paths,diff.noprefixandcolor.ui=alwaysparse correctly.""and the command still runs.Prompts and Calls
<grouping_hints>block: up to 25 file pairs ranked by reason (test, imports, history). The pairs are not merged, so a chain of imports cannot pull every file into one group.react,@scope/pkg,node:path) never match a staged file.refineCommitMessage) sends the ~400-token manifest instead of the diff.generateSplitPlannow takes the context and validates the plan againstcontext.files.quietLoading). "Failed." still shows on error.compressionNote), replacing "sending a compressed summary (~X of ~Y tokens)".Split Plan Repair
src/app/model-options.tsin more than one commit, andcommit generateaborted with "Split plan: duplicate path".dropRepeatedPathsnow keeps each path in the first commit that lists it and drops commits left empty, the same way left-out paths were already repaired.Clickable URLs
commit doctorcut the PR URL at the 40-column Info cell with cli-table3's "…", and the terminal linked the visible text, so a click opened…/c%E2%80%A6. The cell stays truncated but now carries an OSC-8hrefto the full URL (prCell), so clicking the cut text opens the PR. Off a TTY it stays plain text.hyperlinkhelper (src/infra/ui/hyperlink.ts) wraps http(s) URLs in OSC-8 links whenhyperlinksEnabled()(stdout is a TTY). It is used for the PR and remote lines of the push note and the device verification URL insetup, so the full URL opens even where clack hard-wraps the line.Measurement
pnpm measure(scripts/measure-context.ts) prints the estimated tokens per prompt section, whole vs compressed against the budget, the number of hints, and the heaviest files. It makes no model call.Staged Context Flow
flowchart TB A["Commit.run"] --> B["getStagedSnapshot + listStagedPaths"] B --> C["buildStagedContext"] C --> D{"Fits CONTEXT_BUDGET_TOKENS?"} D -->|Yes| E["Whole staged diff, as before"] D -->|No| F["Dedupe identical edits"] F --> G["fitToBudget: tests and largest files lose detail first"] G --> H["Legend + manifest + changes"] E --> I{"Route"} H --> I I -->|split| J["Split prompt: diff + grouping hints"] I -->|single| K["Commit prompt: diff"] K -.->|adjust| L["Refine prompt: manifest only"]Changed Files
src/domain/context/diff.tsgit diff --stagedinto per-file records (added, deleted, modified, renamed, binary)src/domain/context/compress.tssrc/domain/context/hints.tssrc/domain/context/context.tsbuildStagedContext,StagedSnapshot,StagedContext, budget constantsrc/infra/git/repo.tsgetStagedSnapshotreplacesgetStagedDiff; pinned diff formatsrc/domain/commit/prompts.ts<grouping_hints>in the split prompt; refine takes the manifestsrc/domain/llm/router.tsgenerateSplitPlantakes the context; refine takesstagedFilessrc/cli/commit.tsdiff()src/domain/split/plan.tsdropRepeatedPathsrepairs paths listed in several commitssrc/cli/doctor.tshrefsrc/infra/ui/hyperlink.tshyperlinkandhyperlinksEnabled, plain text off a TTYsrc/infra/ui/spinner.tsquietLoadingclears the spinner on successsrc/infra/ui/push-note.ts,src/cli/setup.tssrc/cli/split.tsrunPlanandregeneratetake the contextscripts/measure-context.tspnpm measuretoken estimatorpackage.json,tsconfig.json,eslint.config.jsmeasurescript and typecheck and lintscripts/test/domain/context/*test/infra/git/repo.integration.test.ts,test/cli/*,test/domain/commit/prompts.test.ts,test/domain/llm/router.test.ts,test/domain/split/plan.test.tstest/infra/ui/hyperlink.test.tsTesting & Feedback
lintandpnpm test(385 tests) pass locally on the latest commit. Prettier and build were last run before the split-plan, notice and URL commits.d3f2178~1..31bd8b6staged together (44 files, +3329 −363), the sent diff drops from ~49,254 to ~10,991 estimated tokens. Runpnpm measureon a large staged change to compare.git diff --staged, a repo with no commits still works, and nothing staged still fails with "No staged changes found".<staged_files>list.git grepandgit logrun on everycommit, including runs that don't use hints. Their cost in very large repos has not been timed.If you find any bugs or have recommendations for improvements, please open an issue and assign it to me.