Documentation
¶
Overview ¶
Package undo records what an import wrote and reverses it on request, backing `cct undo`. Import is cct's only operation that changes files, so a clean, verifiable reversal of the last import is the natural safety net.
A journal is written per import into cct's own config directory (never inside a coding-agent home). Each entry carries the destination path, the SHA-256 of the bytes cct wrote, and — for a replaced or merge-updated file — a backup of the original. Reversal is conservative: it only removes or restores a file whose current contents still match what the import wrote, so edits made after the import are never destroyed.
Index ¶
Constants ¶
const JournalVersion = 1
JournalVersion is the on-disk journal schema version.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Entry ¶
type Entry struct {
// Action mirrors the bundle import action ("import", "import-copy",
// "replace", "update"); it is informational for display.
Action string `json:"action"`
// Dest is the absolute path of the file the import wrote.
Dest string `json:"dest"`
// WroteSHA is the SHA-256 of the bytes the import wrote to Dest. Reversal only
// proceeds when Dest still hashes to this, so later edits are never clobbered.
WroteSHA string `json:"wrote_sha256"`
// Backup, when set, is the absolute path to a copy of the file that existed at
// Dest before the import overwrote it (replace and merge-update). Reversal
// restores it. Empty for a newly created file, which reversal deletes.
Backup string `json:"backup,omitempty"`
// Created is true when the import created a new file (no prior file at Dest),
// so reversal deletes it rather than restoring a backup.
Created bool `json:"created"`
// ThreadID and Preview are carried for a readable undo listing.
ThreadID string `json:"thread_id,omitempty"`
Preview string `json:"preview,omitempty"`
}
Entry is the reversal record for one written file.
type Journal ¶
type Journal struct {
Version int `json:"version"`
Time string `json:"time"` // RFC3339, when the import ran
Tool string `json:"tool"`
Home string `json:"home"` // agent home root the import wrote into
Bundle string `json:"bundle"` // source bundle path (for display)
Entries []Entry `json:"entries"`
// contains filtered or unexported fields
}
Journal is the full record of one import.
type Outcome ¶
type Outcome struct {
Entry Entry
Status string // "removed", "restored", "already-gone", "changed", "backup-missing", "error"
Message string
}
Outcome is what reversal did to one entry.
type Result ¶
Result summarizes a reversal.
func Reverse ¶
Reverse undoes an import journal. It deletes files the import created and restores backups for files it overwrote — but only when the file on disk still matches what the import wrote, so any change made afterward is left untouched and reported as skipped. On a real (non-dry-run) reversal, restored backups are removed and the journal file is deleted afterward by the caller via Remove.