const outcome = await agent.rewind(2);
// {
// n: 2,
// removed: { messages: 11, turns: 5 },
// files: { restored: [...], recreated: [...], deleted: [...], skipped: [...] },
// kept: ["send_mail", "deploy"],
// credits: { spent: 24, refunded: 0 }
// }outcome = agent.rewind(2)
# {
# "n": 2,
# "files": {"restored": [...], "recreated": [...], "deleted": [...], "skipped": [...]},
# "kept": [],
# "credits": {"spent": 0, "refunded": 0}
# }The workspace first
Files are restored before anything else, because that is the part that can fail. Then the conversation is cut, then the device journal, then the account's copy.
What it reports
nintegerThe message gone back to.
removedobject{ messages, turns } — what left the conversation.
filesobjectrestored, recreated, deleted, and skipped with a reason each.
keptstring[]What left the machine and stays done.
creditsobject{ spent, refunded: 0 }. The removed turns were billed and are not given back.
A message that was sent is sent, a site that was published is online, credits that were spent are spent. The answer names them rather than letting « rewind » suggest the world was put back.
What files.skipped means
| Reason | Means |
|---|---|
| too large to have been copied | Over 25 MB — recorded, never copied, cannot be restored |
| saved content is gone | The stored content was collected |
| could not be written | Locked, in use, or refused by the file system |
| more than 5 000 files: the checkpoint is partial | The snapshot never held everything |
Refusals
| Code | Status | When |
|---|---|---|
| session_required | 400 | No session — memory: true is needed. |
| agent_running | 409 | It is answering. stop() first. |
| invalid_checkpoint | 400 | n is not a whole number of at least 1. |
| checkpoints_disabled | 400 | checkpoints: false. |
| checkpoint_compacted | 404 | That message was summarised away. The message names what is left. |
| checkpoint_not_found | 404 | No such message. The message lists the available numbers. |
Rewinding and running in one call
await agent.run({ edit: 2, message: "Actually, rename them to kebab-case." });agent.run(edit=2, message="Actually, rename them to kebab-case.")The same rewind, then the run — with a rewound event carrying this outcome.