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.
/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.
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]| Trigger | Condition | Status |
|---|---|---|
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.
/compact 2000.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.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.
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.
| Command | Selection / Enter |
|---|---|
/compact | Compact immediately. The [keep_recent_tokens] argument is optional; execution does not require it. |
/rewind, /branch | Run immediately (arguments optional). |
/context | Open the ring panel. |
/clear, /new | New session. |
/task, /skill, /merge | Fill the prefix and wait for required arguments. |
/help | Set input to /, making the menu appear again. |
/sandbox, /doctor, /memory | Run their respective actions; with a session, doctor sends its report as a user message. |
[…]) execute immediately on selection / Enter./task and similar required-argument commands still fill a prefix first.closing, it does not intercept Enter; execution proceeds to runCommand.compaction_started / finished / failed each have a system message. Nothing-to-compact is a fourth state defined in the occupancy design./help is not a separate page./doctor sends its diagnostic report as chat when a session exists.| Responsibility | Path |
|---|---|
| Command registry | apps/web/components/chat/composer/slash/slash-commands.ts |
| Menu / dispatch | apps/web/components/chat/composer/slash/use-slash-menu.ts |
| Selection | apps/web/components/chat/composer/index.tsx (selectSlashCommand) |
| Keyboard | apps/web/components/chat/composer/input/use-composer-keydown.ts |
| Enter submission | apps/web/components/chat/composer/submit/use-chat-submit.ts |
| Manual compaction over WS | apps/server/openprogram_server/_webui/ws_actions/chat.py → handle_compact |
| Compaction pipeline | openprogram/context/engine.py, summarize.py |
| Automatic compaction | openprogram/agent/dispatcher/loop_runner.py |
| Context-window overflow recovery | openprogram/context/reactive.py |
| Frontend event handling | apps/web/lib/runtime-bridge/chat-handlers.ts |
| Ring / panel | context-badge.tsx, context-breakdown-panel.tsx |
| Occupancy measurement | occupancy-status.html |