Repository navigation
feat: implement session export, fork, and undo (Issues #91, #98) - #112
Merged
Merged
Conversation
Contributor
Author
|
applying Brian's warning from #86 that session data contains private code and secrets, we enforced restrictive 0600 file and 0700 directory permissions on exported transcripts, forked session records, and turn backup snapshots so that exported files and session copies never inherit world-readable permissions. |
winshaurya
added a commit
to winshaurya/brave-bot
that referenced
this pull request
Sep 7, 2026
…, and spec compliance for PR brave#112
`/export` writes the recounted conversation to a markdown file under the working directory, named on the line or defaulting to the session id. The path is confined the way a workspace write is, an existing file is left alone rather than replaced, and the file is written 0600 like the session record it came from. The transcript belongs to the person who had the conversation, and until now the only way to get one out was to read the record's JSON out of the state directory by hand. Part of brave#98
`bravebot --fork <id>` copies a record into one with its own id and opens it, so a second approach starts from the prefix that was worth keeping instead of from nothing. The audit trail is copied with it, since the gates that decided the shared prefix decided the fork's history too. A manifest run is refused, for the reason SESSION-10 refuses to resume one. An incognito session writes no copy, so forking in one opens the conversation and records nothing. Closes brave#98
`/undo` puts the session back where it stood before the most recent turn: the paths that turn wrote go back to what they held, the conversation returns to its pre-turn snapshot, and the turn count, spend, timing, trust map, trusted programs and audit lines go back with it. A rewind past the first turn removes the record rather than leaving an empty one. The workspace keeps what a path held before the turn's first write to it, which is the only moment that is knowable. Nothing reads those bytes: they are carried back to the path they came from. One turn is as far as it goes. `/clear` and a shell-mode command close the window, the latter because the workspace never saw what the command changed. Part of brave#91
Refusing `..`, a root and a drive prefix says nothing about where a directory inside the tree leads. `/export escape/notes.md`, where `escape` is a symlink, wrote outside the working directory with no traversal component anywhere in the path; so did `/export notes.md` where `notes.md` was a symlink whose target did not exist, since `exists` follows a symlink and reports nothing for a broken one, so the path read as free and the write followed it out. Containment is now tested the way the workspace tests it, against the canonical path of the deepest directory that exists, and a path already taken is refused on `symlink_metadata` rather than on `exists`.
Every restore was attempted with its result discarded, so a rewind that put nothing back said "rewound the session by one turn" exactly as one that put everything back did. The case that matters is the one where a file still holds what the turn wrote while the conversation says it never happened, which is the disagreement between disk and transcript a rewind exists to prevent. `restore_backups` now returns the paths that would not go back, and the line reporting the rewind names them. A file the turn created and something else has since deleted is already in the state asked for, so it is not among them.
Every file a turn wrote had its previous contents read whole into memory and held until the turn after it, whether or not anybody rewound. One write of a large file was therefore a large allocation on a code path every turn takes, and nothing bounded how many of them a turn could make. A turn now keeps at most MAX_REWIND_BYTES. Past it the path is still remembered and what it held is not, which is a third state rather than a second: recording it as a file that was never there would have a rewind delete work it merely could not hold. `/undo` names such a path among the ones that did not go back.
A snapshot describes the session as it stood before the last turn, and only a turn was closing the window on it. `/compact`, `/rename`, `/add-dir` and `/cd` all change the session without starting one, so `/undo` afterwards rewound that change as well, under a line saying one turn had been rewound: a compacted conversation came back whole, a renamed session took its old name back, and a directory stayed open with the rule that made it reachable gone from the map. Each of those closes the window now, alongside `/clear` and a shell-mode command, which already did.
bbondy
force-pushed
the
feat/session-export-fork-undo
branch
from
September 8, 2026 02:53
f894bd4 to
ebde4e6
Compare
bbondy
approved these changes
Sep 8, 2026
bbondy
left a comment
Member
There was a problem hiding this comment.
Thanks, nice work. Rebased on main, split one commit per feature, and pushed four follow-ups: export confinement past symlinks, a rewind that names what it could not put back, a memory bound on what a turn keeps, and closing the rewind window on /compact, /rename, /add-dir and /cd. Specs and tests included. Remainder of #91 is #116.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
Three session commands, one per commit.
/export [path]writes the recounted transcript as markdown, into the working directory.The path is confined the way a workspace write is, an existing path is refused rather than
replaced, and the file is written 0600 like the record it came from.
bravebot --fork <id>copies a record into one with its own id and opens it, so a secondapproach starts from a prefix worth keeping. The audit trail comes with it. A manifest run is
refused, and an incognito session writes no copy.
/undoputs the session back where it stood before the last turn: the paths that turn wrotego back to what they held, and the conversation, turn count, spend, timing, trust map, trusted
programs, transcript and audit lines go back with it.
--continue, the third gap in #98, is already onmain.Follow-up commits on top of the original work
..says nothing about where a directory inside the treeleads.
/export escape/notes.mdwithescapea symlink wrote outside the working directorywith no traversal component in the path, and
/export notes.mdwherenotes.mdwas a symlinkto a missing file did too, since
existsfollows a symlink and reports nothing for a brokenone. Containment is now tested against the canonical path of the deepest directory that exists,
and a path already taken is refused on
symlink_metadata.discarded, so a rewind that put nothing back reported the same success as one that put
everything back. That leaves the transcript describing a tree that is not there, which is the
disagreement a rewind exists to prevent.
and held until the turn after it, whether or not anybody rewound. A turn now keeps at most
MAX_REWIND_BYTES; past it the path is remembered and its contents are not, as a third staterather than a second, since recording it as a file that was never there would have a rewind
delete work it merely could not hold.
/compact,/rename,/add-dirand/cdall change the session without starting one, so/undoafterwards undidthat change as well under a line saying one turn had been rewound.
Also in the rebase: the branch was ~16k lines behind
mainand did not compile against it, thethree original commits are now one per feature so each builds and carries its own tests, and five
unrelated French strings the branch had rewritten are left as they were.
Specs
SESSION-17,SESSION-18andSESSION-19in sessions.md, with twoknown costs on what a rewind does not cover: changes a program made rather than a file tool, and
edits the user made themselves between the turn and the rewind.
Closes #98
Closes #91
The rest of #91, the part this does not do, is #116: more than one step back, a list to choose
from, and checkpoints that survive a resume.