Skip to content

[diffs/edit] Add edit prediction support#1024

Open
ije wants to merge 1 commit into
mainfrom
ije/tab-tab-tab
Open

[diffs/edit] Add edit prediction support#1024
ije wants to merge 1 commit into
mainfrom
ije/tab-tab-tab

Conversation

@ije

@ije ije commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator
Screen.Recording.2026-07-25.at.02.18.26.mov

Usage:

import type {
  EditorOptions,
  EditPredictProvider,
  EditPredictResponse,
} from '@pierre/diffs/edit';
import { File } from '@pierre/diffs/react';

const provider: EditPredictProvider = {
  async predict(request, { signal }) {
    const response = await fetch('/api/edit-prediction', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(request),
      signal,
    });

    if (!response.ok) {
      throw new Error('Prediction failed');
    }

    return (await response.json()) as EditPredictResponse;
  },
};

const editorOptions: EditorOptions<undefined> = {
  editPrediction: {
    provider,
    mode: 'eager',
    include: ['**/*.ts', '**/*.tsx'],
    exclude: ['**/*.test.ts'],
  },
};

export function EditableFile() {
  return (
    <File
      file={{
        name: 'cart.ts',
        contents: 'const total = items.',
      }}
      edit
      editorOptions={editorOptions}
    />
  );
}

@vercel

vercel Bot commented Jul 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pierre-docs-diffs Ready Ready Preview Jul 24, 2026 6:36pm
pierre-docs-diffshub Ready Ready Preview Jul 24, 2026 6:36pm
pierre-docs-trees Ready Ready Preview Jul 24, 2026 6:36pm
pierrejs-diff-demo Ready Ready Preview Jul 24, 2026 6:36pm

Request Review

@ije ije changed the title [diffs/edit] add inline edit prediction support [diffs/edit] Add edit prediction support Jul 24, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 303ba7f574

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".


let upstream: Response;
try {
upstream = await fetch(CODESTRAL_FIM_URL, {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add abuse protection before proxying Codestral

When MISTRAL_API_KEY is configured, this public app route accepts any valid JSON POST and immediately forwards it to Mistral with the server-side bearer token; I found no apps/docs middleware or rate-limit wiring guarding /api/edit-prediction. A third party can script requests directly to this endpoint and burn the paid quota even though the UI only exposes it behind the demo button, so add server-side abuse protection such as per-IP/session rate limiting before the upstream fetch.

Useful? React with 👍 / 👎.

return;
}
if (isPromise(result)) {
if (result instanceof Promise) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Detect promise-like storage results

If a custom persistStateStorage returns a thenable or a Promise created in another realm, this instanceof Promise check now treats the async read as a synchronous state object; the old isPromise helper accepted those values by checking for .then. In that case persisted selections/views are never restored correctly, and the matching write path also stops tracking pending async writes, so please keep the duck-typed promise detection or normalize with Promise.resolve.

Useful? React with 👍 / 👎.

prediction.rendered ||= renderCtx.elements.size > elementCount;
}

if (isDeletion || !this.#isLineVisible(start.line)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Render newline-only deletion predictions

For deletion predictions that remove only a line break or an empty line, such as a range from end-of-line to the next line's character 0 with newText: '', #renderSelection produces no overlay because both slices are zero-width, and this branch skips rendering any ghost marker. Since Tab acceptance also requires prediction.rendered, join-line or empty-line deletion suggestions are silently impossible to accept; render a visible marker for these deletion ranges or mark them rendered when the affected newline is visible.

Useful? React with 👍 / 👎.

@ije

ije commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator Author

still working on it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant