Draft Workflow (draft & draft_batch)
When an agent is not ready to mutate your live working tree — because a build is running, another agent holds an edit lock, you want a human or quorum reviewer to inspect a diff first, or a subagent is running in read-and-draft mode — Kompile provides a version-controlled draft store backed by a bare JGit repository at <project>/.kompile/drafts.git.
Every draft revision, apply, and revert is attributed to the exact session, agent, and model, checked against live file drift and edit_coordinator locks, and automatically recorded in diff_index.
WARNING
Why draft exists (DraftEnforcerPolicy): Ad-hoc workarounds like copying repo files into ~/.cache/<session>-overlay-vN directories, writing patch hunks into *-draft.md, or keeping custom manifest.txt / diff3 scripts are blocked by the Enforcer (DraftEnforcerPolicy, configurable via draftEnforcerEnabled). Always use draft / draft_batch instead.
Lifecycle at a glance
flowchart LR
C["create\n(files / edits / patches\nagainst live base)"] --> R["revise\n(iterate, add files,\ndrop_paths)"]
R --> S["show / log / list\n(inspect diff vs. base\n& revision trail)"]
S --> CHK{"Live files moved\nsince draft base?"}
CHK -->|Yes| RB["rebase\n(3-way merge onto\ncurrent project files)"]
RB --> APP["apply\n(atomic all-or-nothing;\nrefuses drift & locks)"]
CHK -->|No| APP
APP --> REV["revert\n(undo apply while files\nremain unchanged)"]
R --> SUP["discard / supersede\n(fold into another draft\nvia supersede_with)"]How drafts are stored & audited
- Bare JGit repository:
<project>/.kompile/drafts.git— completely isolated from your project's own.githistory and working tree until you explicitlyapply. - Refs:
- Draft heads:
refs/kompile/drafts/<draft_id> - Apply/revert records:
refs/kompile/applies/<apply_id>
- Draft heads:
- Mandatory model attribution: Every mutating commit carries
Kompile-Session,Kompile-Agent, andKompile-Modeltrailers. If the caller's agent config doesn't already specify a model,draftrequiresmodel=<model-id>explicitly. diff_indexintegration (DraftDiffIndexFeed): Everycreate,revise,rebase,apply, andrevertwrites an indexed entry (source=kompile-draft,diffType=draft|draft-apply|draft-revert) carryingmodel,draftId, andcommitIdso historical draft activity is searchable alongside live edits.
All 11 draft actions
| Action | Mutating? | Key Parameters | What It Does |
|---|---|---|---|
create | Yes | title, files / edits / patches, optional note, model | Creates a new draft based on the current live project files and commits revision 1 |
revise | Yes | draft_id, files / edits / patches / drop_paths, optional expected_revision, note | Appends a new revision on top of the draft's current head (fails if expected_revision drifted) |
show | No | draft_id, optional revision | Renders the unified diff of a revision against its base (bounded to 60k chars) |
log | No | draft_id | Shows the full revision history with timestamps, notes, session, agent, and model |
list | No | optional status (open default, all, applied, reverted, discarded, superseded), session_id | Lists drafts and their current status |
rebase | Yes | draft_id, optional note | Performs a three-way merge of the draft onto the current live project files |
apply | Yes | draft_id, optional revision, note, agent_name | Writes the revision into the project all-or-nothing — refuses if any target file drifted from the draft's base or is locked by another agent via edit_coordinator |
revert | Yes | apply_id, optional note | Cleanly reverses an apply — only allowed while the working-tree files still match the exact applied state |
discard | Yes | draft_id, optional note | Marks an unapplied draft as discarded without touching project files |
supersede | Yes | draft_id, supersede_with, optional note | Closes a draft because another draft's revision now carries its changes |
audit | No | optional session_id | Prints the complete apply / revert audit trail |
How changes are supplied (files, edits, patches)
create and revise accept three familiar input forms (matching write, edit, and edit_patch rules):
files:[{"file_path": "...", "content": "..."}]— whole-file content (ideal for new files).edits:[{"file_path": "...", "old_string": "...", "new_string": "...", "replace_all": false}]— exact replacements applied against the draft's current content (or the live project file the first time that file enters the draft).patches:[{"file_path": "...", "patch": "..."}]— per-file unified hunks located by content.drop_paths:["path/to/file"](onrevise) — removes a file from the draft.
Important invariant: folding instead of stacking drafts
Every draft is anchored to the live project files, never stacked on top of another unapplied draft. If Draft B needs to build on an unapplied Draft A:
- Fold Draft B's edits into a new revision of Draft A (
draft action=revise draft_id=<A>). - Close Draft B with
draft action=supersede draft_id=<B> supersede_with=<A>.
This guarantees that rebase, apply, and revert always operate on a clean, unambiguous base.
Batching multiple draft operations (draft_batch)
When reviewing, revising, or applying a set of drafts, use draft_batch instead of sequential draft calls:
- Runs up to 20 operations (
operations[]) in order through the sameDraftToolengine. - Top-level
modelandagent_nameare automatically inherited by every operation that omits them. - Each
applyinside the batch stays atomic, drift-checked, lock-checked, and audited indiff_index. - By default, one failing operation reports its error while the remaining operations continue (with optional
stop_on_errorto halt on the first failure).
Ask in chat: "Show
draft-a1b2, rebase it onto the latest working-tree files, and apply it atomically if the rebase is clean — stopping on the first error."
The agent bundles show → rebase → apply into one draft_batch call instead of three separate model round-trips.
Standard patterns for using drafts
1. Staging edits during a busy build window
When a long build/test process is running and modifying live files would corrupt the compile, tell the agent:
"While the Maven build finishes, stage the next fix in a
draftso we canrebaseandapplycleanly as soon as the build exits."
2. Read-and-draft subagents + lead review
Dispatch parallel workers to investigate and propose fixes as drafts without ever racing over live files:
- Worker creates a draft (
draft action=create ...) and posts thedraft_idin itsprogressreport. - Lead agent (or you) inspects the diff (
draft action=show), optionally verifies it withlsp action=checkusing overlay buffers, and applies atomically (draft action=apply) once approved.
3. Safe experimentation with guaranteed rollback
Because apply records an apply_id and checks exact content hashes on revert, you can apply a draft, run your test suite, and immediately revert cleanly with draft action=revert apply_id=<id> if anything fails.
Related guides
- Standard Daily Workflow — Where drafts fit in day-to-day agent workflows
- LSP & Edit Verification Gate — Checking touched files and staged overlays with
lsp action=check - Diff Index (
diff_index) — Searching draft revisions, applies, and reverts (source=kompile-draft) alongside live edits - File Context, Notes & Activity — Per-file dossiers, durable notes, and multi-agent read/write notifications
- The Enforcer —
DraftEnforcerPolicyand edit-coordination lock enforcement - Auditing & Provenance — Model/session attribution across every change