npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@marimo-team/codemirror-ai

v0.3.5

Published

CodeMirror plugin for Model Context Provider

Downloads

5,538

Readme

codemirror-ai

A CodeMirror extension that adds AI-assisted inline code editing capabilities to your editor (like Continue.dev and Cursor)

Features

  • AI-Assisted Editing: Select code and use keyboard shortcuts to get AI suggestions for edits
  • Accept/reject AI suggestions with a clean, modern interface
  • Customizable Keyboard Shortcuts

Installation

npm install @marimo-team/codemirror-ai
# or
pnpm add @marimo-team/codemirror-ai

Usage

AI-Assisted Editing

import { aiExtension } from '@marimo-team/codemirror-ai';
import { EditorView } from '@codemirror/view';

const view = new EditorView({
  extensions: [
    // ... other extensions
    aiExtension({
      // Required: Function to generate completions
      prompt: async ({ prompt, selection, codeBefore, codeAfter }) => {
        // Call your AI service here to generate the new code,
        // given the prompt, selection, and surrounding code
        return newCode;
      },

      // Optional callbacks
      onAcceptEdit: (opts) => {
        console.log('Edit accepted', opts);
      },
      onRejectEdit: (opts) => {
        console.log('Edit rejected', opts);
      },
      onError: (error) => console.error(error),

      // Optional configuration
      inputDebounceTime: 300, // ms
      keymaps: {
        showInput: 'Mod-k',    // Trigger AI edit
        acceptEdit: 'Mod-y', // Accept suggestion
        rejectEdit: 'Mod-u'    // Reject suggestion
      }
    })
  ],
  parent: document.querySelector('#editor')
});

Next Edit Prediction (Autocomplete)

import { nextEditPrediction } from '@marimo-team/codemirror-ai';
import { EditorView } from '@codemirror/view';

const view = new EditorView({
  extensions: [
    nextEditPrediction({
      // Required: Function to predict next edits
      fetchFn: async (state) => {
        // Return diff suggestion based on current editor state
        return { newText: 'suggested code', cursorOffset: 0 };
      },

      // Optional configuration
      delay: 500,              // Debounce delay in ms
      acceptOnClick: true,     // Accept suggestion on click
      defaultKeymap: true,     // Include Tab/Escape keybindings
      showAcceptReject: true,  // Show accept/reject buttons

      // Optional callback for tracking edits
      onEdit: (oldDoc, newDoc, from, to, insert) => {
        console.log('Edit tracked:', { oldDoc, newDoc, from, to, insert });
      }
    })
  ],
  parent: document.querySelector('#editor')
});

Prompt History

import { promptHistory } from '@marimo-team/codemirror-ai';
import { EditorView } from '@codemirror/view';

const view = new EditorView({
  extensions: [
    promptHistory({
      // Optional storage callbacks
      storage: {
        load: () => JSON.parse(localStorage.getItem('prompts') || '[]'),
        save: (prompts) => localStorage.setItem('prompts', JSON.stringify(prompts))
      },
      defaultKeymap: true // Use ArrowUp/ArrowDown for navigation
    })
  ],
  parent: document.querySelector('#editor')
});

Demo

See the demo for a full example.

Example prompt

const template = (opts) => `
Given the following code context, ${opts.prompt}

SELECTED CODE:
${opts.selection}

CODE BEFORE SELECTION:
${opts.codeBefore}

CODE AFTER SELECTION:
${opts.codeAfter}

Instructions:
1. Modify ONLY the selected code
2. Maintain consistent style with surrounding code
3. Ensure the edit is complete and can be inserted directly
4. Return ONLY the replacement code, no explanations

Your task: ${opts.prompt}`;

// ...

aiExtension({
  prompt: async (opts) => {
    const fullPrompt = template(opts);
    return await llm.complete(fullPrompt);
  }
})

Development

# Install dependencies
pnpm install

# Run tests
pnpm test

# Run demo
pnpm dev

License

Apache 2.0