Activity Ledger & Surgical Undo
Every file edit, file creation, deletion, and shell command executed by your coding agents is captured in a bounded ring buffer with SHA-256 state verification and out-of-order surgical rollback.
Bounded Mutation Ring Buffer

50 to 50,000 Turns
Defaults to max_entries = 1000 per namespace. Files larger than max_snapshot_bytes (256 KB default) strip raw content automatically while preserving sha256 and size_bytes.
Files, CLI & MCP
Tracks file_edit, file_write, file_create, file_delete, run_command, and mcp_mutation across all connected harnesses.
Peer Rewind Signals
Executing an undo on the Sulcus API emits rewind.started and rewind.completed on the Agent Bus so peer agents refresh stale file context immediately.
How Surgical & Compensating Undo Works
File Mutation Strategies
- delete_created_file: When
pre_state.existed == false, Sulcus removes the newly created path and verifies removal on disk. - surgical_reverse_patch: When later turns modified the same file (
post_state.sha256 != current_sha) anddiff_hunksare recorded, Sulcus reverses only that turn's exact hunks while preserving non-overlapping edits made afterward. - pre_image_restore: When no subsequent edits occurred (
post_state.sha256 == current_sha), Sulcus restorespre_state.contentand verifies the resulting SHA-256 digest matchespre_state.sha256.
CLI Command 3-Tier Cascade
- procedural_recipe_replay: Checks memory for a verified
[Undo Recipe: ...]procedural node matching the command prefix. - llm_compensating_cli: On cloud deployments when
llm_cli_undo_enabledis active (automatically disabled on air-gapped and connected on-prem appliances), synthesizes a verified compensating command. - compensating_cli: Deterministic fallback reversing
mv,cp, untracked Git artifacts,sqlx migrate run, andgit branch. Successful CLI reversals are stored asproceduralrecipes (heat = 0.92) for instant reuse.
Every compensating CLI command passes is_command_safe, which strictly blocks compound shell operators (;, &&, ||, backticks, $(...)) and destructive patterns (rm -rf /, git reset --hard, git push --force, DROP DATABASE).
On the local sulcus engine, POST /api/v1/agent/ledger/undo supports seq_ids, last_n, substring query filtering, and dry_run. On the remote Sulcus API, undo targets explicit seq_ids or last_n (1 to 100) and persists audit rows in undo_history.
curl -X POST https://api.sulcus.ca/api/v1/agent/ledger/record \
-H "Authorization: Bearer $SULCUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"session_id": "junie-rm-01",
"harness": "rubymine",
"namespace": "payments-rails",
"action_type": "file_edit",
"tool_name": "edit_file",
"target_path": "services/billing/webhook_verifier.rb",
"summary": "Enforce 300s timestamp drift ceiling",
"pre_state": {
"existed": true,
"sha256": "9f4c1a8e...",
"size_bytes": 1842,
"content": "..."
},
"post_state": {
"existed": true,
"sha256": "3b81e044...",
"size_bytes": 1996,
"content": "..."
},
"diff_hunks": [
{
"start_line": 42,
"target_excerpt": "MAX_DRIFT = 86_400",
"replacement_excerpt": "MAX_DRIFT = 300"
}
]
}'# Surgical out-of-order undo of specific sequence IDs (unwound in strict LIFO order)
curl -X POST https://api.sulcus.ca/api/v1/agent/ledger/undo \
-H "Authorization: Bearer $SULCUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"namespace": "payments-rails",
"seq_ids": [840, 842]
}'
# Or rewind the last 3 mutations in the namespace
curl -X POST https://api.sulcus.ca/api/v1/agent/ledger/undo \
-H "Authorization: Bearer $SULCUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"namespace": "payments-rails",
"last_n": 3
}'curl -X POST https://api.sulcus.ca/api/v1/agent/ledger/config \
-H "Authorization: Bearer $SULCUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"namespace": "payments-rails",
"enabled": true,
"max_entries": 2000,
"retain_file_snapshots": true,
"max_snapshot_bytes": 262144,
"llm_cli_undo_enabled": true
}'Activity Ledger Endpoints & MCP Tools
/api/v1/agent/ledger/api/v1/agent/ledger/record/api/v1/agent/ledger/config/api/v1/agent/ledger/undolist_activity_ledgerrecord_activityundo_activity