-
Notifications
You must be signed in to change notification settings - Fork 749
feat: add absolute line numbers for improved AI agent communication #6678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
- Display line numbers from source Python file instead of relative cell numbers
- Add keyboard shortcut (Cmd+Shift+A) to toggle absolute line numbers
- Add UI toggle in Settings → Display → "Absolute line numbers"
- Add visual indicator ("A" badge) in cell corner when enabled
- Persist configuration in user config
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
94b1818 to
6c3a60d
Compare
| # Store line numbers in cell data after registering | ||
| self._register_cell(cell, app=app) | ||
| # Update with line numbers | ||
| if cell._cell.cell_id in self._cell_data: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this will work when you first load the notebook. But updating the notebook (adding/deleting cells, adding new lines etc etc) and this won't work anymore.
It's a nice idea, but there's more to keep the back end in sync with the frontend
|
Does this work if you move cells around? Does this work for multi-column? As you add new lines, do they get updated? |
|
hey guys, thanks for the feedback, indeed in those scenarios it's not currently working, I added those as test cases to the PR description. It does work when adding new lines but indeed when you move cells around or add a new cell it doesn't work, I'll keep working on it |
|
@lucharo it's a pretty hairy, I considered going down this path for adding debugging capabilities- but instead settled for https://github.com/marimo-team/marimo/pull/6311/files#diff-26c1c93dacf92c199621cd07b116adc86d6d6fc66e5447d5a94a6c51c51f05b5R1404 which just re-parses the notebook on execution every single time. But if you're up for it, would be awesome |
|
re-parsing on execution sounds not ideal for performance. i understand this would be behind a config flag, but just something to consider both if you still plan to implement this and something worth showing in the UI |
which bit do you consider hairy? is it the keeping track of line count without reparsing the source script? |
Yes, namely because what is in memory is not bound to be what's on disk (esp with autosave off). Toggling could send a request to save and then get line offsets. This would be a simplification over attempting to carry around line number and do constant accounting (which is the more complex, edge-case filled "hairy" issue) |
yeah I thought so! I am thinking that this could be a feature that's only really available when and clear on the keeping track of line number, that'd be indeed hairy, I understood correctly! I'll keep cracking on this feature working "on save" (if you guys like the feature enough) |
|
@lucharo - i think even with on-save, the line numbers will be outdated. personally, i think the complexity is not worth effort. taking a large step back, is there another way you can give Claude context of where is should focus that is not based on line numbers (e.g. cell name, cell contents) |
Fair enough! I won't pursue it then. I think cell name would work but by default cells are not named. It'd be great to have something that works out of the box. It could be cell number (again, toggleable) so that the human and the agent both have something to share perspectives over. I think agents would probably need to "count" the number of cells and might get it wrong sometimes. Cell content works fine but again might lose precision in longer periods, can copy and paste the exact function/snippet of code but that also makes for worse UX I think. I think the reason I suggested line count was because I see agents often use grep or sed or similar tools to scan files so line count works out of the box for referencing files. What are your thoughts? |
|
im not sure how large your notebooks are, but i find agents pretty good at consuming the whole file. not sure i have other thoughts on other ways give exact context, but open to explore |
|
@lucharo we did have a feature request/ idea for auto-naming cells with an agent. I can't find the exact issue- but maybe that would help with your issue? |
|
This line of work is too thorny and with how marimo is currently set up would be very expensive to set up (parsing source script at every save) so will abandone for other simpler ways of referencing code cells, thanks @dmadisetti and @mscolnick for the discussion! |
Summary / Use case
When working with AI coding assistants on marimo notebooks, it's much clearer to reference code by its actual line number in the source file (e.g., "modify line 42") rather than using relative cell references. This is particularly valuable in notebooks with many cells where cell-based references become difficult to track.
Features Implemented
Cmd+Shift+A(Ctrl+Shift+A on Windows/Linux) to toggle absolute line numbersScreen.Recording.2025-10-04.at.19.13.53.mov
Note I also added editable marimo install in the
pixisection ofpyproject.tomlas performed in the #6679 PRtest cases
caveat
doesn't work in a temporary notebook when a file hasn't been assigned yet (e.g. when creating notebook via
marimo editrather thanmarimo edit nb.py)🤖 Generated with Claude Code