Skip to content

Conversation

joadoumie
Copy link
Contributor

Description

This PR introduces a new TextCommandProvider that allows users to include text content directly into chat messages via @text: commands. This allows users to quickly include active cell content or selected text in their chat messages, providing an alternative to the dropdown menu interface. This is a more ergonomic method of attaching commands for folks that use keyboard over mouse.

Code changes

New File

  • packages/jupyter-ai/src/chat-command-plugins/text-command.tsx
    • Implements TextCommandProvider class, following the same pattern as FileCommandProvider.
    • Provides smart autocomplete with two options:
      • @text:active_cell – inserts the content of the currently active notebook cell.
      • @text:selected_text – inserts any text currently selected in the editor.
    • Autocomplete:
      • Only shows options when relevant content is available.
      • Filters options as the user types (e.g., typing act only shows the active_cell option).
    • On submit, commands are replaced with markdown code blocks, matching the formatting used by the existing "Send message with selection" dropdown.

Modified

  • packages/jupyter-ai/src/chat-command-plugins/index.ts
    • Added textCommandPlugin to the exported plugins array.

User-facing changes

Users can now type @text: in the chat input to trigger autocomplete suggestions:

  • @text:active_cell → Includes the content of the currently active notebook cell.
  • @text:selected_text → Includes any text currently selected in the editor.

23868c03-6550-439a-bb3c-fe7641dfffde

Backwards-incompatible changes

None that I know of.

@dlqqq dlqqq added the enhancement New feature or request label Sep 3, 2025
@dlqqq
Copy link
Member

dlqqq commented Sep 3, 2025

@joadoumie Thank you for contributing this! I just got back from some software conferences, so I appreciate your patience until I'm able to review this.

BTW, we have recently added a feature where users can drag & drop selections into the chat input. That might solve the original issue for this PR, but I'm also open to having these 2 features live together in parallel. Have to test this locally to arrive at a recommendation.

@joadoumie
Copy link
Contributor Author

I think drag and drop is a great feature, and probably solves for a different user flow (folks who prefer interactivity with the keyboard and keyboard shortcuts). I'd probably use both, but it'd be interesting to try them out together.

@ellisonbg
Copy link
Collaborator

I think it would be helpful to be able to attach using keyboard shortcuts, but we should use the new attachment system for the content. This is a more flexible and powerful way of attaching context from different documents to the chat that gives agents/personas for control over what appears in the context/chat history and has a more streamlined UX.

Copy link
Member

@dlqqq dlqqq left a comment

Choose a reason for hiding this comment

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

@joadoumie

Thank you for contributing this! This is a great addition to Jupyter AI & provides a keyboard-only option for adding a selection as context. There are 2 potential improvements that I'd like you to explore before merging:

  1. The added context should be attached as an attachment instead of being injected directly into the prompt. This can be done via inputModel.addAttachment(). A reference for this can be found inside of the @file command provider. The attachments API should now support selection ranges.
  • Thanks to your previous contribution in #1419, this attachment will be read by Jupyternaut. Right now I believe it will read the whole file. There's no need to implement reading only selection ranges in this PR since we will add an agent tool for this (read further).
  1. A user generally only has one selection at any given time, so I recommend just providing a single @selection command instead of two @text commands. If a text selection is available, use that, otherwise use the cell selection.

I totally understand any reservation about using the attachments API. It is more complex and the UX can be improved, but there is a good motivation for this. By v3.0.0 official, Jupyternaut will be made agentic & be provided tools to read files on their own. I have a local branch of this working and will open a PR for this next week.

By having the AI agent load the content itself, we can reduce the time-to-first-response by having a smaller initial prompt, and most importantly, make AI reads/writes to the filesystem traceable for server operators & admins.

(congrats on getting feedback from the co-founder of Project Jupyter BTW! that's Brian.)

@joadoumie
Copy link
Contributor Author

@dlqqq -- I made some changes given your feedback. I don't think the attachment API quite fits the desired UX just yet, but I think this is directionally correct.

I also took a look at #1479 to try to better understand how this flow may fit in with a world of agentic tool calling (which I'm really excited about). I am going to temporarily move this PR into draft status so I can revisit it after better understanding some of the possibilities/limitations with the tools based approach.

@joadoumie joadoumie marked this pull request as draft September 30, 2025 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants