aiellie

Search

Find a component, template or page

GitHub
Components

Agent Cursor

A document you and an agent edit together. The paragraph it's rewriting is marked while the draft streams in beside it, to replace or discard, and editing that paragraph meanwhile offers to keep yours, take the agent's or merge.

Assistant is rewriting paragraph 2

Team update

Assistant editing

Assistant is rewriting this

Edit the highlighted paragraph while it writes to see a clash.

Open full screen
fig. 01 · open it full screen from the corner

Installation

npx shadcn@latest add "@aiellie/agent-cursor"

shadcn needs the @aiellie registry in components.json first. npx aiellie add agent-cursor adds it on its first run, then installs the same way.

Agent Cursor is a document you and an agent edit at the same time. The paragraph the agent is rewriting gets a live edge, and its draft streams in underneath with a caret. Once it's done you replace the paragraph or discard the draft. Nothing changes until you choose.

If you edit that paragraph while the agent works on it, the two versions clash. It says so, tells your app once so it can pause the agent, and offers Keep yours, Use the agent's, or Merge, which asks the agent to start again from your text.

Getting started

  1. Hold the document and the rewrite

    Pass the paragraphs, the id the agent is rewriting, and its draft as it streams.

    components/doc.tsx
    import { AgentCursor, type DocBlock } from "@/components/aiellie/agent-cursor"
    
    export function Doc({ rewrite }: { rewrite: Rewrite }) {
      const [blocks, setBlocks] = useState<DocBlock[]>(initial)
    
      return (
        <AgentCursor
          title="Team update"
          blocks={blocks}
          onBlocksChange={setBlocks}
          target={rewrite.blockId}
          draft={rewrite.text}
          writing={rewrite.streaming}
          onConflict={() => rewrite.pause()}
          onKeepYours={rewrite.cancel}
          onUseAgent={(text) => apply(rewrite.blockId, text)}
          onMerge={(yours) => rewrite.restartFrom(yours)}
        />
      )
    }

Anatomy

<div data-slot="agent-cursor" data-state="writing">
  <div data-slot="agent-cursor-header" />
  <textarea data-slot="agent-cursor-block" />   {/* one per paragraph */}
  <div data-slot="agent-cursor-rewrite">
    <span data-slot="agent-cursor-caret" />     {/* while writing */}
  </div>
</div>

The state comes from the props: writing while it streams, ready once a draft is there, and conflict once the held paragraph no longer matches what the agent started from. Leave out base and it reads that text as each rewrite starts, so setting draft back to "" for a merge starts from your edit.

Each state is read out once, and the held paragraph points at that message.

Examples

A draft to review

Without writing, a draft shows straight away with Replace and Discard.

Assistant's rewrite of paragraph 1 is ready

Release note

Assistant done

Assistant's rewrite

Ship on Friday, once the last two fixes are in.

API reference

AgentCursor

PropTypeDefaultDescription
titlestring"Untitled"
blocks{ id: string; text: string }[]requiredOne per paragraph.
onBlocksChange(blocks: DocBlock[]) => voidLeft out, the document is read-only.
agentNamestring"Assistant"
targetstringThe id of the block being rewritten.
basestringThe text the agent was given. Left out, it's read as each rewrite starts.
draftstring""The rewrite so far.
writingbooleanfalseWhether it's still streaming.
onConflict(yourText: string) => voidFires once a rewrite, on the clash.
onKeepYours() => voidAdds Discard, or Keep yours.
onUseAgent(draft: string) => voidAdds Replace, or Use the agent's.
onMerge(yourText: string) => voidAdds Merge on a clash.

All other div props are forwarded.