aiellie

Search

Find a component, template or page

GitHub
Components

Compaction Marker

The line in a thread where an agent compacted its context: a sweep while it works, then the tokens before and after, opening to what was kept.

Compacting context
Compacting context48.2k
Open full screen
fig. 01 · open it full screen from the corner

Installation

npx shadcn@latest add "@aiellie/compaction-marker"

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

Compaction Marker is the line across a thread where an agent summarised its context to make room. While it works, a live segment sweeps along the line, or fills it if you pass progress. Once it's done it reads "Context compacted 48.2k → 6.1k", counting down if you watched it finish.

Pressing it opens what the summary kept: decisions, tasks and files, with finished tasks struck through so they don't come back as new work. You can leave items out of the next turn. If compacting fails, it says the full history was kept and can offer a retry.

Getting started

  1. Put it in the thread

    components/compaction.tsx
    import {
      CompactionMarker,
      type CompactionItem,
    } from "@/components/aiellie/compaction-marker"
    
    export function Compaction({
      done,
      before,
      after,
      items,
    }: {
      done: boolean
      before: number
      after: number
      items: CompactionItem[]
    }) {
      return (
        <CompactionMarker
          state={done ? "compacted" : "compacting"}
          tokensBefore={before}
          tokensAfter={after}
          items={items}
        />
      )
    }
  2. Leave items out

    onDroppedChange gives the ids someone left out. Strip them from the summary before the next turn.

    components/compaction.tsx
    <CompactionMarker
      state="compacted"
      tokensBefore={before}
      tokensAfter={after}
      items={items}
      dropped={dropped}
      onDroppedChange={setDropped}
    />

Anatomy

<div data-slot="compaction-marker" data-state="compacted" role="group">
  {/* rule, then the label or the trigger, then a rule */}
  <button data-slot="compaction-marker-trigger" aria-expanded />
  <div data-slot="compaction-marker-panel" data-open>
    {/* kept of total, a bar, then the items by group */}
  </div>
</div>

Each state is read out once as it changes. The panel slides open, and is inert while closed so its buttons can't be reached.

formatTokens is exported too: 48213 becomes 48.2k.

Examples

Failed, with retry

Press Retry to watch it fill with progress and finish.

Couldn't compact. Full history kept.
Couldn't compactfull history kept

API reference

CompactionMarker

PropTypeDefaultDescription
state"compacting" | "compacted" | "failed"required
tokensBeforenumberrequired
tokensAfternumberNeeded once compacted.
itemsCompactionItem[][]What the summary kept.
progressnumberFrom 0 to 1. Left out, the line sweeps.
dropped, defaultDropped, onDroppedChangestring[]The ids left out of the next turn.
open, defaultOpen, onOpenChangebooleanfalse
onRetry() => voidAdds Retry when failed.
readOnlybooleanfalseHides the drop buttons.

All other div props are forwarded.

CompactionItem

FieldTypeDefaultDescription
idstringrequired
kind"decision" | "task" | "file"required
labelstringrequired
donebooleanA finished task, shown struck through.