Slash commands and compaction · Current design

Slash commands dispatch; compaction produces system messages

The entry for context compaction is /compact. The composer executes optional-argument commands immediately; compaction start, success and failure each produce a system message. Measurement, nothing-to-compact behavior and ring lifecycle belong in the occupancy design.

Backend compaction pipeline available Optional-argument commands execute on selection or Enter System messages for started / finished / failed See occupancy design for ring suggestions and panel actions

Summary

/compact asks the model to summarize old conversation turns, records the summary in the DAG, and supplies “summary + recent turns” afterward.

Optional arguments ([…]) execute immediately on selection or Enter. Menu closing animations no longer intercept Enter. Without a session, the UI asks the user to send a message first instead of claiming success.

What compaction does

Models have finite context windows. As conversation grows, older turns must be reduced. OpenProgram uses a rolling summary: only one summary is active at a time. Further compaction combines the old summary and additional turns into a new summary instead of stacking summaries.

The next model request actually contains:

[System prompt] [Current summary] [Recent uncompacted turns] [New user message]

Three trigger paths

TriggerConditionStatus
Manual /compact Execute in the composer; optionally keep the latest N tokens Emits action: compact. Without a session, show an alert instead of running an empty operation.
Automatic pre-turn compaction Turn budget ≥ 80% of the window. Compact first, then fall back to snip Dispatcher handles this in loop_runner.py. System messages use the same wording.
Context-window overflow recovery Model returns 413 / prompt_too_long; at most once per turn reactive.py; uses the same compaction events.

The ring color reflects occupancy, and the panel offers one-click compaction; see Occupancy and compaction.

Compaction steps

Read
Read rendered history from SessionDB: the existing summary and turns remaining on the branch. Recompaction does not reread original text already covered by a summary.
Threshold
Stop if fewer than four messages remain; the manual path emits a system explanation. If rendered history is already summary plus tail with no valid cut, emit nothing-to-compact without invoking the summarization LLM.
Summarize
Make a separate LLM call. By default, retain a recent tail of 10% of the window, clamped to 8k–40k tokens and at least five nonempty messages. This can be overridden by /compact 2000.
Persist
Write a summary_* node (role=llm, name=context/summary); covers_ids marks the replaced range. Session metadata records the summary for subsequent compaction. Old turns are not deleted and HEAD does not move.
Graph
The DAG displays a capsule. The old summary becomes superseded and stops participating in rendering. Covered original conversation text remains in storage.

Ring and /context panel

The lower-right ring shows current occupancy divided by window size; opening it reveals token categories. Occupancy uses the compacted rendered view, matching the compaction report. Colors: green below 50%, yellow at 50–80%, red at ≥80%.

The occupancy design defines running-compaction state and the Compact now panel interaction; this page does not create separate behavior.

Slash commands

When input starts with / and contains no space, the menu expands upward from the composer. After a space appears, it closes over 380ms. Enter checks whether the first word is a registered command: execute if registered, otherwise send ordinary chat.

The built-in registry is in slash-commands.ts. It also fetches /api/commands to include skills, plugins and user commands. Built-ins have dispatch precedence.

CommandSelection / Enter
/compactCompact immediately. The [keep_recent_tokens] argument is optional; execution does not require it.
/rewind, /branchRun immediately (arguments optional).
/contextOpen the ring panel.
/clear, /newNew session.
/task, /skill, /mergeFill the prefix and wait for required arguments.
/helpSet input to /, making the menu appear again.
/sandbox, /doctor, /memoryRun their respective actions; with a session, doctor sends its report as a user message.

Implemented slash-command fixes

Minor unfinished items

Key files

ResponsibilityPath
Command registryapps/web/components/chat/composer/slash/slash-commands.ts
Menu / dispatchapps/web/components/chat/composer/slash/use-slash-menu.ts
Selectionapps/web/components/chat/composer/index.tsx (selectSlashCommand)
Keyboardapps/web/components/chat/composer/input/use-composer-keydown.ts
Enter submissionapps/web/components/chat/composer/submit/use-chat-submit.ts
Manual compaction over WSapps/server/openprogram_server/_webui/ws_actions/chat.py → handle_compact
Compaction pipelineopenprogram/context/engine.py, summarize.py
Automatic compactionopenprogram/agent/dispatcher/loop_runner.py
Context-window overflow recoveryopenprogram/context/reactive.py
Frontend event handlingapps/web/lib/runtime-bridge/chat-handlers.ts
Ring / panelcontext-badge.tsx, context-breakdown-panel.tsx
Occupancy measurementoccupancy-status.html