Skip to content
Back

Code suggestion

An AI edit for one file: the instruction and model, a file tab with a running +/− count, hunks that stream in after a short Reading shimmer, Accept / Reject under each, and Accept all with ⌘↵.

oxyn add code-suggestion
MCP
Add retry with backoff
Claude Sonnet
TSfetch-invoice.tssrc/billing+0−0
import type { Invoice } from "./types";
export async function fetchInvoice(id: string): Promise<Invoice> {
const res = await fetch(`/api/invoices/${id}`);
if (!res.ok) throw new Error(`Invoice ${id} failed: ${res.status}`);
return res.json();
}
Reading fetch-invoice.ts
Dioxus
let s = Suggestion::new(&file_text, vec![
    SugHunk { id: "retry".into(), start: 3, remove: 3, insert: retry_lines, summary: "Retry 429 and 5xx".into() },
]);

rsx! {
    CodeSuggestion {
        suggestion: s,
        now: clock.now(),
        started: Some(requested_at),
        instruction: "Add retry with backoff",
        on_resolve: move |code| write_file(code),
    }
}

Rendered from Rust at build time · goes live when visible

When to use

  • An AI proposes an edit to one file; the person accepts or rejects each hunk before anything is written.
  • Hunks are {id, start, remove, insert, summary} (zero-based start; overlapping hunks after the first are ignored).
  • Suggestion::play(elapsed) drives Thinking (0.8 s), Streaming (one inserted line every 38 ms) and Ready.
  • Accepted hunks fold into the file (only new lines remain, renumbered); rejected hunks restore the original.

When not to use

  • An agent asks before it acts: use Approval Card instead.
  • Several open requests in one card: use Approval pager instead.
  • An agent's question in its own card above the composer: use Decision Card instead.

Installation

Code suggestion is free and MIT. The oxyn CLI copies its code, and the components it needs, into src/oxyn/ of your Dioxus or GPUI project, so it is yours to change.

Terminal
cargo install --git https://github.com/ismailqureshi72/Oxyn oxyn-cli
oxyn init
oxyn add code-suggestion
Rust
use crate::oxyn::{CodeSuggestion, STATUS_INDICATOR_CSS};

Rather depend on the crate? cargo add oxyn-dioxus oxyn-core --git https://github.com/ismailqureshi72/Oxyn, then use oxyn_dioxus::{CodeSuggestion, STATUS_INDICATOR_CSS};

Usage

Dioxus · rust
let s = Suggestion::new(&file_text, vec![
    SugHunk { id: "retry".into(), start: 3, remove: 3, insert: retry_lines, summary: "Retry 429 and 5xx".into() },
]);

rsx! {
    CodeSuggestion {
        suggestion: s,
        now: clock.now(),
        started: Some(requested_at),
        instruction: "Add retry with backoff",
        on_resolve: move |code| write_file(code),
    }
}

Examples

Stream

Reading shimmer, then hunks stream in and get Accept / Reject.

Add retry with backoff
Claude Sonnet
TSfetch-invoice.tssrc/billing+0−0
import type { Invoice } from "./types";
export async function fetchInvoice(id: string): Promise<Invoice> {
const res = await fetch(`/api/invoices/${id}`);
if (!res.ok) throw new Error(`Invoice ${id} failed: ${res.status}`);
return res.json();
}
Reading fetch-invoice.ts
Code
let s = Suggestion::new(&file_text, vec![
    SugHunk { id: "retry".into(), start: 3, remove: 3, insert: retry_lines, summary: "Retry 429 and 5xx".into() },
]);

rsx! {
    CodeSuggestion {
        suggestion: s,
        now: clock.now(),
        started: Some(requested_at),
        instruction: "Add retry with backoff",
        on_resolve: move |code| write_file(code),
    }
}

Ready

The finished suggestion, ready to review.

Add retry with backoff
Claude Sonnet
TSfetch-invoice.tssrc/billing+8−3
import type { Invoice } from "./types";
Added: import { sleep } from "./time";
Import sleep
export async function fetchInvoice(id: string): Promise<Invoice> {
Removed: const res = await fetch(`/api/invoices/${id}`);
Removed: if (!res.ok) throw new Error(`Invoice ${id} failed: ${res.status}`);
Removed: return res.json();
Added: for (let attempt = 0; attempt < 3; attempt++) {
Added: const res = await fetch(`/api/invoices/${id}`);
Added: if (res.ok) return res.json();
Added: if (res.status < 500 && res.status !== 429) break;
Added: await sleep(2 ** attempt * 250);
Added: }
Retry 429 and 5xx with backoff
Added: throw new Error(`Invoice ${id} kept failing`);
Fail after the last try
}
3 changes to review
Code
let s = Suggestion::new(&file_text, vec![
    SugHunk { id: "retry".into(), start: 3, remove: 3, insert: retry_lines, summary: "Retry 429 and 5xx".into() },
]);

rsx! {
    CodeSuggestion {
        suggestion: s,
        now: clock.now(),
        instruction: "Add retry with backoff",
        on_resolve: move |code| write_file(code),
    }
}

Error

The model stopped; Retry.

Add retry with backoff
Claude Sonnet
TSfetch-invoice.tssrc/billing+8−3
import type { Invoice } from "./types";
Added: import { sleep } from "./time";
export async function fetchInvoice(id: string): Promise<Invoice> {
Removed: const res = await fetch(`/api/invoices/${id}`);
Removed: if (!res.ok) throw new Error(`Invoice ${id} failed: ${res.status}`);
Removed: return res.json();
Added: for (let attempt = 0; attempt < 3; attempt++) {
Added: const res = await fetch(`/api/invoices/${id}`);
Added: if (res.ok) return res.json();
Added: if (res.status < 500 && res.status !== 429) break;
Added: await sleep(2 ** attempt * 250);
Added: }
Added: throw new Error(`Invoice ${id} kept failing`);
}
The model stopped responding. Nothing was changed.
Code
let s = Suggestion::new(&file_text, vec![
    SugHunk { id: "retry".into(), start: 3, remove: 3, insert: retry_lines, summary: "Retry 429 and 5xx".into() },
]);

rsx! {
    CodeSuggestion {
        suggestion: s,
        now: clock.now(),
        instruction: "Add retry with backoff",
        on_resolve: move |code| write_file(code),
    }
}

Capped

Code area capped at 220 px.

Add retry with backoff
Claude Sonnet
TSfetch-invoice.tssrc/billing+8−3
import type { Invoice } from "./types";
Added: import { sleep } from "./time";
Import sleep
export async function fetchInvoice(id: string): Promise<Invoice> {
Removed: const res = await fetch(`/api/invoices/${id}`);
Removed: if (!res.ok) throw new Error(`Invoice ${id} failed: ${res.status}`);
Removed: return res.json();
Added: for (let attempt = 0; attempt < 3; attempt++) {
Added: const res = await fetch(`/api/invoices/${id}`);
Added: if (res.ok) return res.json();
Added: if (res.status < 500 && res.status !== 429) break;
Added: await sleep(2 ** attempt * 250);
Added: }
Retry 429 and 5xx with backoff
Added: throw new Error(`Invoice ${id} kept failing`);
Fail after the last try
}
3 changes to review
Code
let s = Suggestion::new(&file_text, vec![
    SugHunk { id: "retry".into(), start: 3, remove: 3, insert: retry_lines, summary: "Retry 429 and 5xx".into() },
]);

rsx! {
    CodeSuggestion {
        suggestion: s,
        now: clock.now(),
        instruction: "Add retry with backoff",
        on_resolve: move |code| write_file(code),
    }
}

API reference

CodeSuggestion

PropTypeDefaultDescription
suggestionrequiredSuggestion—The suggestion.
nowrequiredClockMs—Clock (drives the stream).
startedOption<ClockMs>Default::default()When the request started; `None` shows the finished suggestion.
statusOption<SugStatus>Default::default()Force a status (`error` shows the message and Retry).
instructionString"Add retry with backoff"Header title.
modelString"Claude Sonnet"Model line (empty hides it).
file_nameString"fetch-invoice.ts"File name in the tab.
file_pathOption<String>Default::default()Folder after the file name.
errorString"The model stopped responding. Nothing was changed."Error message.
shortcutsbooltrue⌘↵ / ⌘⌫ shortcuts.
max_code_heightu32Default::default()Code area cap, px (0 = none).
summariesbooltrueHunk summaries in the bars.
on_decisionEventHandler<(String, bool, String)>—A hunk was decided: (id, accepted, file as it stands).
on_resolveEventHandler<String>—Every hunk decided: final code.
on_stopOption<EventHandler<()>>Default::default()Stop pressed (shown while thinking or streaming).
on_regenerateOption<EventHandler<()>>Default::default()Regenerate / Retry pressed.

Read from the Rust signature and doc comments.

Keyboard interactions

KeyAction
TabCode area, then each hunk's Reject and Accept, then the footer
EnterorSpacePress the focused button
⌘↵orCtrlEnterAccept every pending hunk
⌘⌫orCtrlBackspaceReject every pending hunk

Accessibility

  • The card is a labelled group; the code is a focusable region named after the file.
  • Removed and added lines start with hidden “Removed:” / “Added:”; Accept and Reject name their hunk.
  • A polite status speaks the state (“3 changes to review”), each decision and the result; streaming is announced once.
From the spec
  • Labelled group "Code suggestion: <instruction>"; the code is a focusable region named after the file.
  • Hidden "Removed:" / "Added:" on every pending line; Accept / Reject name their hunk; Accept all exposes aria-keyshortcuts.
  • A polite status speaks the state, each decision ("Accepted: Import sleep. 2 changes to review") and the result.

Motion & interaction

Timing
  • Thinking 800 ms with a 1.6 s shimmer loop; each new line fades in over 120 ms.
  • Review bars rise in over 240 ms.
  • Status label swaps with a 160 ms rise; the spinner keeps turning between Reading and Writing.
  • Zero counts in the tab turn muted.
  • Reduced motion: opens on the finished suggestion, no shimmer or spinner turn.

Responsive behaviour

  • Fills its container up to 720 px; long lines scroll sideways while line numbers and review bars stay pinned.
  • The folder hides below a 520 px card; below 440 px summaries hide and the footer stacks.
Edge cases (spec)
  • Up to 720 px; long lines scroll sideways with numbers and bars pinned.
  • Folder hides below 520 px; below 440 px the gutter narrows, summaries hide and the footer stacks.

Notes for AI

  • Import CodeSuggestion from oxyn_dioxus and include STATUS_INDICATOR_CSS plus the token stylesheet once.
  • A GPUI version exists: CodeSuggestionEl in oxyn_gpui.
  • Props to set first: suggestion, now.
  • It reads a clock (now) for live timers; pass one clock for the whole page rather than one per component.
  • Keep its states and timings as they ship; restyle it through the CSS variables rather than by hand.

Guides

Oxyn · 74 free components · 264 Pro components · 96 screens · 20 blocks · Dioxus and GPUI