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-suggestionlet 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.
cargo install --git https://github.com/ismailqureshi72/Oxyn oxyn-cli
oxyn init
oxyn add code-suggestionuse 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
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.
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.
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.
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.
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
| Prop | Type | Default | Description |
|---|---|---|---|
suggestionrequired | Suggestion | — | The suggestion. |
nowrequired | ClockMs | — | Clock (drives the stream). |
started | Option<ClockMs> | Default::default() | When the request started; `None` shows the finished suggestion. |
status | Option<SugStatus> | Default::default() | Force a status (`error` shows the message and Retry). |
instruction | String | "Add retry with backoff" | Header title. |
model | String | "Claude Sonnet" | Model line (empty hides it). |
file_name | String | "fetch-invoice.ts" | File name in the tab. |
file_path | Option<String> | Default::default() | Folder after the file name. |
error | String | "The model stopped responding. Nothing was changed." | Error message. |
shortcuts | bool | true | ⌘↵ / ⌘⌫ shortcuts. |
max_code_height | u32 | Default::default() | Code area cap, px (0 = none). |
summaries | bool | true | Hunk summaries in the bars. |
on_decision | EventHandler<(String, bool, String)> | — | A hunk was decided: (id, accepted, file as it stands). |
on_resolve | EventHandler<String> | — | Every hunk decided: final code. |
on_stop | Option<EventHandler<()>> | Default::default() | Stop pressed (shown while thinking or streaming). |
on_regenerate | Option<EventHandler<()>> | Default::default() | Regenerate / Retry pressed. |
Read from the Rust signature and doc comments.
Keyboard interactions
| Key | Action |
|---|---|
| Tab | Code area, then each hunk's Reject and Accept, then the footer |
| EnterorSpace | Press the focused button |
| ⌘↵orCtrlEnter | Accept every pending hunk |
| ⌘⌫orCtrlBackspace | Reject 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
CodeSuggestionfromoxyn_dioxusand includeSTATUS_INDICATOR_CSSplus the token stylesheet once. - A GPUI version exists:
CodeSuggestionElinoxyn_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.