/* Rewind (rewind.c): go back to an earlier user message of a conversation * and restore the conversation, the files write and edit changed after it, * or both, as Claude Code's checkpoints do. A bundled component over the * file history core records (filelog.c); see docs/manual/rewind.md. */ #ifndef PIC_REWIND_H #define PIC_REWIND_H #include #include "pic.h" #include "rpc.h" enum { PIC_REWIND_BOTH, PIC_REWIND_CONVERSATION, PIC_REWIND_FILES }; typedef struct { int applied; /* 0: files were refused and nothing was done */ char *text; /* the message rewound to, for the editor (malloc'd) */ int switched; /* the conversation was rewound: now in conversation */ char conversation[64]; /* "" a new, empty one */ pic_restore_result restore; struct pic_rewind_refusal { char *path; const char *why; } *refused; size_t nrefused; } pic_rewind_report; /* SESSION's user messages, newest first, as JSON lines: entry, text, and * files (how many files write and edit changed after it). */ int pic_rewind_points(pic_store *s, const char *session, FILE *out); /* Rewinds SESSION (an id, prefix or "latest") to before its user message * ENTRY in MODE. A file changed since pic last wrote it, or whose earlier * bytes were not kept, is refused; with any refused, nothing is done unless * FORCE_PARTIAL, which restores the rest. 0 (see r->applied), or -1. */ int pic_rewind(pic_store *s, const char *session, sqlite3_int64 entry, int mode, int force_partial, pic_rewind_report *r); /* Undoes the latest file restore of SESSION (an undo's too: a redo). */ int pic_rewind_undo(pic_store *s, const char *session, int force_partial, pic_rewind_report *r); /* The report for a person, paths shown relative to WORKSPACE, or as JSON. */ void pic_rewind_print(const pic_rewind_report *r, const char *workspace, int json, FILE *out); void pic_rewind_report_free(pic_rewind_report *r); /* The RPC command rewind (rpc.h's component commands). */ extern const pic_rpc_command pic_rewind_rpc; #endif