Skip to content

Refactoring of context and request entry into a single thing prompt#131

Merged
ThePrimeagen merged 1 commit intomasterfrom
prompt
Feb 21, 2026
Merged

Refactoring of context and request entry into a single thing prompt#131
ThePrimeagen merged 1 commit intomasterfrom
prompt

Conversation

@ThePrimeagen
Copy link
Owner

@codegirl-007 just FYI i have made a big change. Its still partially done

@cursor
Copy link

cursor bot commented Feb 21, 2026

You have run out of free Bugbot PR reviews for this billing cycle. This will reset on March 8.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Comment on lines +392 to +400
local ok, visual_data = pcall(self.visual_data, self)
if ok then
local f_loc =
self._99.prompts.get_file_location(self.full_path, visual_data.range)
table.insert(self.agent_context, f_loc)
table.insert(
self.agent_context,
self._99.prompts.get_range_text(visual_data.range)
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Calling finalize() on a visual context without an updated range uses a default Range.zero(), leading to incorrect context data being generated.
Severity: MEDIUM

Suggested Fix

Add a validation check inside the finalize() function. Before processing visual_data, verify that visual_data.range is not the default Range.zero(). If the range is invalid, either log an error and abort or throw an error to prevent the generation of incorrect context.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: lua/99/prompt.lua#L392-L400

Potential issue: The `Prompt.visual()` function initializes a context with a default
`range` set to `Range.zero()`. If `finalize()` is called on this visual context without
the range being updated by `over_range()`, the `get_range_text()` function proceeds with
this zero-range. This causes an empty or incorrect text selection to be extracted and
sent to the AI provider. While the main production path appears to correctly update the
range, the lack of validation in `finalize()` allows for code paths to exist that can
generate incorrect context for visual prompts.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not real, on overrange line 24 we set the range, but i think a better version would be to require range to be passed into the prompt creation. will do that to prevent this type of really sharp edge from accidentally appearing

@ThePrimeagen ThePrimeagen merged commit 3787c3d into master Feb 21, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant