Add multi-language and kernel-aware notebook support#379
Open
moyiliyi wants to merge 4 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends Notebook-Intelligence from a Python-centric notebook workflow to a kernel-aware, multi-language workflow by discovering available Jupyter kernels, preserving the active notebook’s language/kernel context, and creating notebooks against a selected kernel profile.
Changes:
- Added frontend kernel discovery + kernel-selection-aware notebook creation (
create-new-notebook,list-available-notebook-kernels) and propagated kernel metadata through the chat request flow. - Updated backend request/context models and rule scoping from
kerneltolanguage+kernel_name, including validation and rule matching changes. - Expanded/updated integration and end-to-end tests plus rule fixtures to cover the new language/kernel fields.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_websocket_handler_integration.py | Updates websocket integration assertions to include kernel_name on requests/context creation. |
| tests/test_rule_auto_reload.py | Updates RuleContext construction to use language + kernel_name. |
| tests/test_models.py | Reworks RuleScope tests to validate language and kernel-name matching and serialization. |
| tests/test_end_to_end_rule_integration.py | Updates end-to-end rule integration tests to pass language + kernel_name. |
| tests/test_context_factory.py | Updates context factory tests for new kernel_name field. |
| tests/test_base_chat_participant_integration.py | Adds tests for new notebook creation behavior using request language/kernel and kernel listing tool. |
| tests/fixtures/rules/01-test-global.md | Updates rule fixture frontmatter from kernels to languages/kernel_names. |
| tests/conftest.py | Updates test fixtures to construct RuleContext with language + kernel_name. |
| src/tokens.ts | Extends IActiveDocumentInfo with optional kernelName and kernelDisplayName. |
| src/notebook-kernels.ts | Introduces kernel profile types, normalization, discovery, and selection logic. |
| src/markdown-renderer.tsx | Switches UI command to create-new-notebook (multi-language-capable). |
| src/index.ts | Tracks kernel metadata for active notebooks; adds new commands for creating notebooks + listing kernels. |
| src/command-ids.ts | Adds new command IDs and removes the Python-only notebook creation command ID. |
| src/chat-sidebar.tsx | Sends kernelName/kernelDisplayName through to backend request payloads and request-building logic. |
| src/api.ts | Extends API request method signature to include kernel name/display name fields. |
| notebook_intelligence/ruleset.py | Migrates rule scoping/matching from kernels to languages + kernel_names and enforces validation. |
| notebook_intelligence/rule_manager.py | Updates rule evaluation plumbing/logging for language + kernel_name. |
| notebook_intelligence/extension.py | Parses kernel metadata from websocket payload; includes it in ChatRequest and context messages. |
| notebook_intelligence/context_factory.py | Extends RuleContextFactory to accept and store kernel_name. |
| notebook_intelligence/claude.py | Adds MCP tool for listing kernels and updates notebook creation tool to pass language/kernel. |
| notebook_intelligence/built_in_toolsets.py | Adds built-in tool for listing kernels; updates notebook creation tool args and UI command. |
| notebook_intelligence/base_chat_participant.py | Adds kernel-listing tool; updates notebook creation tool + prompts to be language/kernel aware. |
| notebook_intelligence/api.py | Extends ChatRequest model with language and kernel_name. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Collaborator
|
@moyiliyi looks good overall, thanks. can you check the Copilot review comments above? |
…ok kernel is not installed Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
… when kernel specs are present
Contributor
Author
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.
This Pull Request introduces support for multi-language environments and granular kernel management within Notebook-Intelligence. It transitions the system from a Python-centric model to one that can now discover available Jupyter kernels, preserve the active notebook's language/kernel context, and create notebooks against a selected kernel profile.
Motivation
Previously, Notebook-Intelligence was largely hardcoded to assume a Python environment. When creating a new notebook, it would simply iterate through available kernelspecs and pick the first one matching the "python" language. This limitation prevented users from:
By decoupling the language from the kernel name and providing a discovery mechanism, we enable the AI to be truly "polyglot" and aware of its execution environment.
Core Logic Changes
Environment Discovery: Added a new tool
list_available_notebook_kernelsthat allows the AI to query the frontend for all installed kernelspecs. This enables the AI to "know" what languages are supported on the user's machine before attempting to create content.Context Awareness: The ActiveDocumentWatcher now tracks not just the file's language but also the specific kernelName and displayName. This metadata is passed to the AI in requests, providing it with the exact context of the current execution environment.
Prompting and tool instructions were updated accordingly.
Built-in notebook-edit instructions and Claude Jupyter UI prompts now explicitly tell the model to preserve the current language/kernel, and to list available kernels before creating a notebook in a different environment.
New Interfaces & API Updates
Backend
languageandkernel_nametoChatRequestRuleContext: Replaced generic kernel with specificlanguageandkernel_namefields.create_new_notebook: Now accepts optionallanguageandkernel_nameparameters.list_available_notebook_kernels: New tool to fetch kernel profiles from the frontend.Frontend
notebook-intelligence:create-new-notebook: Replaces the Python-onlycreate-new-notebook-from-py.notebook-intelligence:list-available-notebook-kernels: Fetches the list of INotebookKernelProfile.