Extend copy context past shared-UI wrappers and add maxContextLines option#478
Merged
Merged
Conversation
…ption Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
commit: |
Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
…ace cap Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
A bare `/ui/` segment also matched Next's `app/ui/` feature convention, demoting real feature code to budget-free and inflating the trace. Narrow to the actual shared-UI conventions, document the maxContextLines budget edge cases, and add an e2e test covering the option end-to-end.
…opy-context-depth-2ad6
The skill source path and removal dirs are built with node:path.join / fileURLToPath, which emit backslashes on Windows. Assert against join() output instead of hardcoded forward-slash paths so the test passes on windows-latest.
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.
Problem
Closes #471.
In large apps (especially shadcn/Next), grabbing a wrapper/layout-ish element produces a trace that points at a UI wrapper instead of the meaningful surface — "the useful context is a few levels around it." The context-extension introduced in #446 only helps when the wrapper chain is in
node_modules: those frames are surfaced "for free" and don't spend the compact 3-line budget. But shadcn-style apps render through app-owned wrappers (components/ui/sidebar.tsx, a monorepopackages/ui, headless primitives), which do spend the budget, so the trace caps out before reaching the actual feature source.There was also a broken contract: the CLI (
init/configure/transform) already writesgrab({ maxContextLines: N })into users' code, but the library hadmaxContextLinesremoved as dead code (commitsedb969ce/87e71cd0). So the option was silently ignored — and would fail typecheck in typed configs. This PR re-wires it.Fix
Two parts — a better default, plus the (now actually functional) opt-in.
Better default: treat shared-UI frames as low-signal
The budget logic now distinguishes "is app source" (for selector-hint suppression) from "consumes budget" (high-signal feature source). App-owned shared-UI / design-system frames — files under a
ui/,design-system(s)/, orprimitives/segment — are detected by a newis-shared-ui-source-pathutil and treated likenode_modulesframes: still shown with their path, but exempt from the compact budget.Because low-signal frames are still shown, the only effect of marking more frames as free is that the trace reaches deeper (bounded by the existing hard cap of 20). A plain leaf element stays compact; a wrapper-heavy element automatically digs through its UI primitives to the real surface — no config required.
Restored opt-in:
maxContextLinesmaxContextLinesis re-added toOptionsand threaded fromOptions→ plugin registry → copy flow and thegetStackContextAPI, and parsed from the scriptdata-optionsattribute. This makes the CLI's existinggrab({ maxContextLines: N })output actually take effect.Changes
utils/is-shared-ui-source-path.ts(+SHARED_UI_SOURCE_PATH_SEGMENTS): segment-based detection of reusable UI directories.core/context.ts:StackFrameLineexposesisAppSource/consumesBudget; shared-UI app frames (and a shared-UI leading source) are free.core/copy.ts,core/index.tsx,core/plugin-registry.ts,types.ts,utils/get-script-options.ts: threadmaxContextLinesthrough.cli/commands/configure.ts: align the option description with its restored semantics.docs/architecture.md.Testing
isSharedUiSourcePathand budget behavior.build,typecheck,lint, react-grab unit tests (29), CLI tests (211), andelement-context+selectionPlaywright suites (51) all pass.Known follow-up (not in this PR)
Edit/CSS prompts (
format-edit-prompt.ts) still emit onlyfilePath:line+ CSS, with no component/stack context — the issue'seditPromptContext: "detailed"ask. Adding element context there could reduce "agent edits the wrong item," but it changes the carefully-tuned style prompt (#452), so it warrants a separate, deliberate change.Summary by cubic
Extends copied stack context to dig past app-owned shared-UI/design-system wrappers and restores a hardened
maxContextLinesfor deeper traces. Collapses consecutive duplicate lines and excludes Next’sapp/uifrom shared-UI detection; addresses #471.New Features
components/ui/,packages/ui/,design-system(s)/, andprimitives/; excludes bareui/so Next’sapp/ui/*feature code isn’t misclassified.maxContextLinesto raise the soft budget; threaded throughOptions, plugin registry, copy flow, andgetStackContext; settable via scriptdata-optionsand at runtime viasetOptions. Input is hardened (NaN/Infinity → default, negatives clamp to 0, fractions floor).Migration
maxContextLines(e.g., 8–12) ininit,setOptions, or scriptdata-optionsto include more app-source lines in the copied context.Written for commit 0e3f5b6. Summary will update on new commits.