Skip to content

[diffs/edit] Add edit prediction support - #1024

Open
ije wants to merge 11 commits into
mainfrom
ije/tab-tab-tab
Open

[diffs/edit] Add edit prediction support#1024
ije wants to merge 11 commits 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 27, 2026 12:28pm
pierre-docs-diffshub Ready Ready Preview Jul 27, 2026 12:28pm
pierre-docs-trees Ready Ready Preview Jul 27, 2026 12:28pm
pierrejs-diff-demo Ready Ready Preview Jul 27, 2026 12:28pm

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".

Comment thread apps/docs/app/(diffs)/edit/predict/route.ts
Comment thread packages/diffs/src/editor/editor.ts Outdated
Comment thread packages/diffs/src/editor/editor.ts
@ije

ije commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator Author

still working on it

@ije

ije commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@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: 0a4640848f

ℹ️ 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".

Comment on lines +59 to +60
if (!isGithubAuthenticated(request)) {
return createErrorResponse('GitHub sign-in required.', 401);

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 Rate-limit authenticated prediction requests

Any GitHub account that obtains this session cookie can issue unlimited concurrent POST requests, and every accepted request is forwarded using the site's shared Mistral API key. A caller can therefore exhaust the upstream quota or incur substantial usage before Mistral's account-wide 429 response intervenes; enforce a per-user/session and concurrency limit before calling Codestral.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

added vercel rate limit

Comment thread packages/diffs/src/editor/editor.ts Outdated
Comment on lines +4689 to +4692
prediction.response.edits[editIndex - 1]?.range.end.line !==
start.line &&
prediction.response.edits[editIndex + 1]?.range.start.line !==
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 Compose multiple same-line edits before previewing

When a valid response contains two non-overlapping insertions on the same source line, these neighbor checks suppress suffix reconstruction for both overlays, while the earlier #renderSelection calls mask the in-flow suffix from each insertion point. The preview consequently drops unchanged source text even though accepting the prediction preserves it; compose the edits into one post-edit line for rendering or reject same-line edit combinations.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed in dae253f

Comment thread packages/diffs/src/editor/editor.ts Outdated
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 asynchronous storage results across realms

If a custom persistStateStorage returns a Promise created in another window or iframe, result instanceof Promise is false even though the value satisfies the public Promise return type. The restore path then treats that Promise as an EditorState and applies an empty state, while the analogous write check also stops tracking write ordering; retain a realm-independent thenable check or normalize with Promise.resolve.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed in dae253f

@ije

ije commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review again

@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: dae253f656

ℹ️ 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".

Comment thread packages/diffs/src/editor/editor.ts Outdated
Comment on lines +4510 to +4513
// Cross-line edits cannot share their boundary line with another
// preview overlay.
if (renderEdits.at(-1)?.range.end.line === line) {
return;

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 Support valid edits that share a boundary line

When one non-overlapping edit crosses into a line and the next edit starts later on that same line—for example, {0,2}->{1,0} followed by {1,1}->{1,2}—the previous render edit ends on line, so this branch returns from the response handler. The public provider contract permits non-overlapping edit batches, but this valid response is silently discarded: no preview appears and Tab cannot accept it. Compose the boundary-line overlays or otherwise render the batch without rejecting it.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed in 0b00db6

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