feat(actions): add undo replay phase one#171
Closed
Ridanshi wants to merge 3 commits into
Closed
Conversation
4b54fd8 to
c0c398a
Compare
Add in-memory action history, safe undo handling, and simple replay endpoints without introducing persistence or runtime hooks.
c0c398a to
ad91b42
Compare
…esign - Add clear_session(session_id) async method to ActionLogger so the DELETE /context endpoint can filter by session rather than clearing all - Fix integration tests to use action_logger.clear() / record_action() instead of the removed _stack deque attribute - Add is_undoable=True to the undo test fixture so undo_last() can find it - Remove datetime object from ActionRecord constructor (let default str run) - Rename test_delete_context_clears_deque -> test_delete_context_clears_session_actions to match the actual behaviour being verified - Fix 409 assertion to match the actual detail "Nothing in the undo stack"
ad91b42 to
40fc371
Compare
Owner
|
After reviewing the PR, it does not currently meet the required project standards and therefore cannot be accepted at this stage. You may either work on improving the implementation and retry with the necessary changes, or choose another available issue to contribute to. Please ensure that future submissions follow the project guidelines, coding standards, and required implementation quality before raising a PR for review |
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.
Summary
Completes the full undo/replay system as specified in the issue.
ActionRecordextended withis_undoable,undo_instruction,undone, andintervalfields; SQLite schema updated to match.Undoablemixin andGuidanceDispatcherstub added toaction_logger.py— dispatcher logs instructions and is designed forextension (UI/notifications).
undo_last()walks backward through the in-memory stack to findthe last undoable action, marks its ID in
_undone_ids(safedouble-undo, idempotent), and optionally dispatches the undo
instruction via an injected
GuidanceDispatcher.replay_session()is an async generator that streamsActionRecordobjects in chronological order from SQLite, sleepinginterval / speedbetween actions. RaisesValueErrorforspeed ≤ 0.POST /api/v1/actions/replayaccepts{"session_id", "speed"}and returns the ordered action list immediately (no timing delays);
returns
400for invalid speed.POST /api/v1/actions/undoreturns409when no undoableaction remains (including after a double-undo).
/ws/replay/{session_id}?speed=<float>streamsreplay_actionevents one per action with timing, then
replay_complete. Reportserroron invalid speed or exception. Reuses FastAPI's nativeWebSocket— no new framework introduced.KeyboardListenerincore/hybrid/keyboard_listener.pybindsCtrl+Z via
pynput.keyboard.GlobalHotKeysin a daemon thread,fires only when
mode_manager.current_mode == "passive", andsilently disables itself if
pynputis unavailable (e.g. CI).Test plan
pytest tests/unit/test_action_logger.py tests/integration/test_actions_context.py)None/ HTTP 409 on second callis_undoable=Trueactions are reversedreplay_sessionyields actions in chronological order with correct intervalsreplay_sessionraisesValueErrorforspeed ≤ 0_undone_idsreplay_completeimmediately{"event": "error"}messageclear_sessionclears both_stackand_undone_ids