# Editable live context (experimental) Prime Agent can let a model edit its own working conversation. This is an opt-in implementation of context-as-a-file from [Context Language Models](https://arxiv.org/html/2609.37725v1). Without an edit, new messages append normally. CLM does **not** discard every previous turn or require the model to write a summary after each step. ## Enable Add this setting to the existing settings JSON, preserving its other keys: ```json { "clm": { "enabled": true } } ``` Use `/.prime/agent/settings.json` for a project or `~/.prime/agent/settings.json` for the default agent directory. A project setting can override the global default. Start a new session/runtime after changing it. Existing CLM sessions retain their saved mode when resumed; changing the default does not silently replace an edited context with the full audit history. This is an experimental Rust extension. Disabled sessions keep the existing behavior. CLM requires a durable session artifact directory; in-memory-only sessions are not supported. Do not enable it for a workflow that needs the unsupported operations listed below. ## Two separate histories - **Full audit log:** the original session messages and tool results. Editing live context does not rewrite this log. - **Model context:** the accepted working conversation used to construct model requests, plus fixed instructions and tool definitions. For a CLM session, Ctrl+O cycles through the existing full-log overview, details, and all-details views, then the model-context view. The model view is read-only and labeled with its revision. Images use placeholders rather than base64. Loading and fetch errors do not fall back to displaying the audit as model context. Provider-specific formatting can differ from this semantic view. For a session without CLM, the existing three-view cycle is unchanged. ## Edit the live file The session prompt identifies the absolute path to its own `clm/context.txt` under the session artifacts. Read and edit that file with the existing Python, Bash, or edit tools. Other agents have separate files. The file uses readable turn headers: ```text [[CTX_TURN 1 role=user]] Keep the public API unchanged. [[CTX_TURN 2 role=assistant]] The parser fix is complete. Next: run the regression tests. ``` Headers are optional organization, not a required memory schema. The model can rewrite passages, remove old outputs, add notes, or replace the whole document. It can keep large evidence files outside context and retain their paths. Complete an edit in one awaited tool call. Write a temporary file in the same directory and atomically replace the live file. Detached/background context writers and simultaneous writes from other agents are not supported. A completed edit is imported at the next settled-message or request boundary. New output then appends normally. The model-context view shows accepted state; opening it does not apply pending file edits. Before the first request it says that no model request has occurred. The fixed platform instructions and tool schemas are not writable through this file. A role header cannot create a new system instruction. Historical tool-call text is data; editing it does not execute a tool. ### Native messages and attachments When the file is unchanged, native messages retain their original structure. An edit converts historical text into ordinary user/assistant messages. Native tool-call structure and opaque reasoning signatures are not reconstructed from editable text. A newly completed result whose call was removed becomes a plain observation, rather than bringing the deleted call back. Images use whole-line `[[CTX_IMAGE <64-lowercase-hex-id>]]` references. Keep a reference to retain that image; removing it removes the image from the live view. These references belong to the session and must not be invented or copied from another session. Unknown IDs produce an error. Inline examples are ordinary text. Literal reference lines in message text are escaped with a leading backslash and remain text, not attachments. The original images remain in the audit history. ## Budget feedback and recovery Context-fill feedback describes the projected request, not the full audit log. Counts are estimates and include fixed instructions/tool definitions. Output headroom is reserved for planning; it is not an exact provider token count. Near the budget, a transient reminder asks the model to edit its context. These reminders do not accumulate in the editable history. An oversized request or invalid/unreadable context produces an actionable error. Prime Agent does not silently restore deleted history or replay tools to recover space. Repair a bad context edit, then continue. An interrupted or uncertain storage write stops further writes in that runtime; reopen the session to attempt recovery. If recovery reports corruption or a conflict, preserve the files for explicit repair. The revision ledger is recovery data, not another file to edit. Deleting text from live context is **not secure erasure**. The audit, revision ledger, external files, and provider retention may still contain it. ## Initial limitations CLM does not add model training, Suffix Cache Reuse, or a remote execution system. It does not guarantee better quality or lower API cost; edits can reduce prefix cache reuse. Historical branch navigation and CLM-parent forks are guarded in this first version. Automatic compaction and overflow compact-and-retry are disabled. Compaction, side questions, and other helper paths that cannot yet honor the edited-context boundary return a clear CLM-specific error. They must not secretly send the full audit to another model or restore it to live context. Refinement uses the healthy accepted semantic CLM context captured at invocation, not pending file edits or forgotten audit messages. Send a normal prompt first if no context has been accepted yet. Manual, self-requested, and automatic refinement keep the original session harness and refinement history. CLM automatic reviews use the settled-turn interval and cooldown; compaction remains disabled. Local, global, and rollback operations keep their usual refinement rules. Model-facing result rows append durably to CLM as well as the audit. Harness changes and these stores are not one atomic transaction: a delivery failure is reported explicitly and can require reopening or repairing CLM even when harness edits already saved. Use a normal session when the guarded operations are required. Goal state is not reconstructed from the editable file. Failed-turn cleanup removes a known failed assistant entry, but ordinary goal observations and edited notes can remain in the model context. Current-session resume retains the accepted live context. A corrupt or missing CLM recovery record is an error, not permission to rebuild from the audit. A process crash can still leave an external tool's outcome uncertain; this feature does not promise exactly-once external side effects across crashes. ## Ownership and compatibility The session engine owns parsing, synchronization, budget policy and recovery. The daemon transports optional metadata and on-demand snapshots. The terminal UI renders shared wire types; it does not read engine internals or watch files. The existing audit protocol and disabled-mode behavior remain the compatibility baseline. CLM-specific wire fields and UI behavior are an intentional opt-in extension, not a claim that the TypeScript baseline already implements CLM.