Metadata-Version: 2.4
Name: jupyterlab_ai_commands
Version: 0.3.1
Summary: A set of commands for AI in JupyterLab
Project-URL: Homepage, https://github.com/jupyter-ai-contrib/jupyterlab-ai-commands
Project-URL: Bug Tracker, https://github.com/jupyter-ai-contrib/jupyterlab-ai-commands/issues
Project-URL: Repository, https://github.com/jupyter-ai-contrib/jupyterlab-ai-commands.git
Author: Project Jupyter
License: BSD 3-Clause License
        
        Copyright (c) 2025, Jeremy Tuloup
        Copyright (c) 2025, Project Jupyter
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this
           list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice,
           this list of conditions and the following disclaimer in the documentation
           and/or other materials provided with the distribution.
        
        3. Neither the name of the copyright holder nor the names of its
           contributors may be used to endorse or promote products derived from
           this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
License-File: LICENSE
Keywords: jupyter,jupyterlab,jupyterlab-extension
Classifier: Framework :: Jupyter
Classifier: Framework :: Jupyter :: JupyterLab
Classifier: Framework :: Jupyter :: JupyterLab :: 4
Classifier: Framework :: Jupyter :: JupyterLab :: Extensions
Classifier: Framework :: Jupyter :: JupyterLab :: Extensions :: Prebuilt
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.9
Requires-Dist: jupyterlab-diff<0.7,>=0.6.0
Description-Content-Type: text/markdown

# jupyterlab-ai-commands

[![Github Actions Status](https://github.com/jupyter-ai-contrib/jupyterlab-ai-commands/workflows/Build/badge.svg)](https://github.com/jupyter-ai-contrib/jupyterlab-ai-commands/actions/workflows/build.yml)

A set of commands for AI in JupyterLab

## Requirements

- JupyterLab >= 4.0.0

## Install

To install the extension, execute:

```bash
pip install jupyterlab-ai-commands
```

## Uninstall

To remove the extension, execute:

```bash
pip uninstall jupyterlab-ai-commands
```

## Available Commands

This extension provides the following commands for AI-assisted interactions with JupyterLab:

### File Commands

- **`jupyterlab-ai-commands:create-file`** - Create a new file of specified type (text, python, markdown, json, etc.)
  - Arguments:
    - `fileName` (string): Name of the file to create
    - `fileType` (string): Registered JupyterLab file type to create (e.g., text, python, markdown, json, javascript, typescript, yaml, julia, r, csv). Unknown file types will raise an error
    - `content` (string, optional): Initial content for the file
    - `cwd` (string, optional): Directory where to create the file

- **`jupyterlab-ai-commands:open-file`** - Open a file in the editor
  - Arguments:
    - `filePath` (string): Path to the file to open

- **`jupyterlab-ai-commands:delete-file`** - Delete a file from the file system
  - Arguments:
    - `filePath` (string): Path to the file to delete

- **`jupyterlab-ai-commands:rename-file`** - Rename a file or move it to a different location
  - Arguments:
    - `oldPath` (string): Current path of the file
    - `newPath` (string): New path/name for the file

- **`jupyterlab-ai-commands:copy-file`** - Copy a file to a new location
  - Arguments:
    - `sourcePath` (string): Path of the file to copy
    - `destinationPath` (string): Exact destination path for the copied file

- **`jupyterlab-ai-commands:navigate-to-directory`** - Navigate to a specific directory in the file browser
  - Arguments:
    - `path` (string): Path to the directory to navigate to

- **`jupyterlab-ai-commands:list-directory`** - List files and directories in a specific directory
  - Arguments:
    - `path` (string, optional): Path to the directory to list. If not provided, lists the root directory
    - `includeHidden` (boolean, optional): Whether to include hidden files (default: false)

- **`jupyterlab-ai-commands:get-file-info`** - Get information about a file including its path, name, extension, and content
  - Arguments:
    - `filePath` (string, optional): Path to the file to read. If not provided, uses the currently active file in the editor

- **`jupyterlab-ai-commands:set-file-content`** - Set or update the content of an existing file
  - Arguments:
    - `filePath` (string): Path to the file to update
    - `content` (string): The new content to set for the file
    - `save` (boolean, optional): Whether to save the file after updating (default: true)
    - `showDiff` (boolean, optional): Whether to show a diff view of the changes (default: true)

### Notebook Commands

- **`jupyterlab-ai-commands:create-notebook`** - Create a new Jupyter notebook with a kernel for the specified programming language
  - Arguments:
    - `language` (string, optional): The programming language for the notebook (e.g., python, r, julia, javascript, etc.). Will use the default kernel if not specified, and raise an error if no matching kernel exists
    - `name` (string): Name for the notebook file (without .ipynb extension)

- **`jupyterlab-ai-commands:add-cell`** - Add a cell to the current notebook with optional content
  - Arguments:
    - `notebookPath` (string, optional): Path to the notebook file. If not provided, uses the currently active notebook
    - `referenceCellId` (string, optional): nbformat cell ID of the reference cell. If not provided, uses the currently active cell
    - `content` (string, optional): Content to add to the cell
    - `cellType` (string, optional): Type of cell to add - "code", "markdown", or "raw" (default: "code")
    - `position` (string, optional): Position relative to the reference or active cell - "above" or "below" (default: "below")

- **`jupyterlab-ai-commands:get-notebook-info`** - Get information about a notebook including number of cells, cell IDs, and the active cell ID
  - Arguments:
    - `notebookPath` (string, optional): Path to the notebook file. If not provided, uses the currently active notebook

- **`jupyterlab-ai-commands:get-cell-info`** - Get information about a specific cell including its type, source content, and outputs
  - Arguments:
    - `notebookPath` (string, optional): Path to the notebook file. If not provided, uses the currently active notebook
    - `cellId` (string, optional): nbformat cell ID of the cell to inspect. If not provided, uses the currently active cell

- **`jupyterlab-ai-commands:set-cell-content`** - Set the content of a specific cell
  - Arguments:
    - `notebookPath` (string, optional): Path to the notebook file. If not provided, uses the currently active notebook
    - `cellId` (string, optional): nbformat cell ID of the cell to modify. If not provided, targets the currently active cell
    - `content` (string): New content for the cell
    - `showDiff` (boolean, optional): Whether to show a diff view of the changes (default: true)
    - `diffMode` (string, optional): Display mode for the diff view - "unified" or "split" (default: "unified")

- **`jupyterlab-ai-commands:run-cell`** - Run a specific cell in the notebook by cell ID
  - Arguments:
    - `notebookPath` (string, optional): Path to the notebook file. If not provided, uses the currently active notebook
    - `cellId` (string): nbformat cell ID of the cell to run
    - `recordTiming` (boolean, optional): Whether to record execution timing (default: true)
  - Returns:
    - `success` (boolean): Whether the execution completed successfully
    - `status` (string): Execution status ("ok", "error", "abort", or "no-op")
    - `executionCount` (number | null): The execution count after the run
    - `outputs` (array): Serialized cell outputs
    - `errorName` (string, optional): Error name if execution failed
    - `errorValue` (string, optional): Error value if execution failed
    - `traceback` (array, optional): Error traceback if execution failed

- **`jupyterlab-ai-commands:delete-cell`** - Delete a specific cell from the notebook by cell ID
  - Arguments:
    - `notebookPath` (string, optional): Path to the notebook file. If not provided, uses the currently active notebook
    - `cellId` (string): nbformat cell ID of the cell to delete

- **`jupyterlab-ai-commands:save-notebook`** - Save a specific notebook to disk
  - Arguments:
    - `notebookPath` (string, optional): Path to the notebook file. If not provided, uses the currently active notebook

### Kernel Commands

- **`jupyterlab-ai-commands:start-kernel`** - Start a new kernel with the specified language or kernel name
  - Arguments:
    - `language` (string, optional): The programming language for the kernel (e.g., python, r, julia). If not provided, uses the default kernel
    - `kernelName` (string, optional): The specific kernel spec name to use (e.g., python3, ir). If provided, takes precedence over language and must exist
  - Returns:
    - `success` (boolean): Whether the kernel was started successfully
    - `message` (string): Status message
    - `kernelId` (string): The unique ID of the started kernel
    - `kernelName` (string): The name of the kernel
    - `status` (string): The current status of the kernel

- **`jupyterlab-ai-commands:execute-in-kernel`** - Execute code in a running kernel and return the outputs
  - Arguments:
    - `kernelId` (string): The ID of the kernel to execute code in
    - `code` (string): The code to execute
    - `silent` (boolean, optional): If true, signals the kernel to execute quietly without broadcasting output (default: false)
    - `storeHistory` (boolean, optional): If true, the code will be stored in the kernel execution history (default: true)
    - `stopOnError` (boolean, optional): If true, abort the execution queue on an error (default: false)
  - Returns:
    - `success` (boolean): Whether the execution completed successfully
    - `status` (string): Execution status ("ok", "error", or "abort")
    - `message` (string): Status message
    - `kernelId` (string): The kernel ID used for execution
    - `executionCount` (number): The execution count
    - `outputCount` (number): Number of outputs returned
    - `outputs` (array): Output objects captured during execution
    - `errorName` (string, optional): Error name if status is "error"
    - `errorValue` (string, optional): Error value if status is "error"
    - `traceback` (array, optional): Error traceback if status is "error"

- **`jupyterlab-ai-commands:shutdown-kernel`** - Shutdown a running kernel by ID
  - Arguments:
    - `kernelId` (string): The ID of the kernel to shutdown
  - Returns:
    - `success` (boolean): Whether the kernel was successfully shut down
    - `message` (string): Status message
    - `kernelId` (string): The ID of the shut down kernel

- **`jupyterlab-ai-commands:list-kernels`** - List all running kernels
  - Arguments: None
  - Returns:
    - `success` (boolean): Whether the operation completed successfully
    - `kernels` (array): Array of kernel objects with the following properties:
      - `id` (string): The unique kernel ID
      - `name` (string): The kernel name
      - `execution_state` (string): Current execution state
      - `last_activity` (string): Timestamp of last activity
      - `connections` (number): Number of active connections
    - `count` (number): Total number of running kernels

- **`jupyterlab-ai-commands:list-kernelspecs`** - List all available kernel specs
  - Arguments: None
  - Returns:
    - `success` (boolean): Whether the operation completed successfully
    - `kernelspecs` (array): Array of kernel spec objects with the following properties:
      - `name` (string): The kernel spec name (e.g., python3, ir, julia-1.10)
      - `display_name` (string): Human-readable display name
      - `language` (string): The programming language of the kernel
    - `count` (number): Total number of available kernel specs
    - `default` (string): The default kernel spec name

## Contributing

### Development install

Note: You will need NodeJS to build the extension package.

The `jlpm` command is JupyterLab's pinned version of
[yarn](https://yarnpkg.com/) that is installed with JupyterLab. You may use
`yarn` or `npm` in lieu of `jlpm` below.

```bash
# Clone the repo to your local environment
# Change directory to the jupyterlab_ai_commands directory
# Install package in development mode
pip install -e "."
# Link your development version of the extension with JupyterLab
jupyter labextension develop . --overwrite
# Rebuild extension Typescript source after making changes
jlpm build
```

You can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in the extension's source and automatically rebuild the extension.

```bash
# Watch the source directory in one terminal, automatically rebuilding when needed
jlpm watch
# Run JupyterLab in another terminal
jupyter lab
```

With the watch command running, every saved change will immediately be built locally and available in your running JupyterLab. Refresh JupyterLab to load the change in your browser (you may need to wait several seconds for the extension to be rebuilt).

By default, the `jlpm build` command generates the source maps for this extension to make it easier to debug using the browser dev tools. To also generate source maps for the JupyterLab core extensions, you can run the following command:

```bash
jupyter lab build --minimize=False
```

### Development uninstall

```bash
pip uninstall jupyterlab_ai_commands
```

In development mode, you will also need to remove the symlink created by `jupyter labextension develop`
command. To find its location, you can run `jupyter labextension list` to figure out where the `labextensions`
folder is located. Then you can remove the symlink named `jupyterlab-ai-commands` within that folder.

### Testing the extension

#### Integration tests

This extension uses [Playwright](https://playwright.dev/docs/intro) for the integration tests (aka user level tests).
More precisely, the JupyterLab helper [Galata](https://github.com/jupyterlab/jupyterlab/tree/master/galata) is used to handle testing the extension in JupyterLab.

More information are provided within the [ui-tests](./ui-tests/README.md) README.

### Packaging the extension

See [RELEASE](RELEASE.md)
