Skip to content

Codex/wework turn file changes main - #1353

Merged
qdaxb merged 13 commits into
wecode-ai:mainfrom
Micro66:codex/wework-turn-file-changes-main
Jun 11, 2026
Merged

qdaxb merged 13 commits into
wecode-ai:mainfrom
Micro66:codex/wework-turn-file-changes-main

Conversation

@Micro66

@Micro66 Micro66 commented Jun 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added file changes review interface showing modified files, additions/deletions counts, and expandable unified diff viewer
    • Added revert functionality to undo changes from a single turn with automatic conflict detection and idempotent behavior
    • New API endpoints for retrieving and reverting turn file changes
  • Documentation

    • Added user guides for file changes feature in English and Chinese
  • Tests

    • Comprehensive test coverage for file changes endpoints, services, and UI components

@coderabbitai

coderabbitai Bot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR implements a comprehensive per-turn file change capture system spanning executor, backend, and frontend. The executor tracks Git workspace changes during agent turns using temporary index snapshots; the backend exposes diff and revert operations through authenticated API endpoints; and wework provides UI components for reviewing and reverting those changes with idempotent semantics.

Changes

Per-turn file changes across executor, backend, and wework

Layer / File(s) Summary
Shared completion payload extension
shared/models/execution.py, shared/models/responses_api_emitter.py, shared/models/db/subtask.py, shared/tests/test_emitter_factory.py
ExecutionRequest gains optional device_id field. ResponsesAPIEmitter adds set_completion_fields_provider(...) method and consumes optional one-shot provider during done() to merge completion fields into response payload.
Executor Git snapshot tracker and artifacts
executor/services/turn_file_changes.py, executor/tests/services/test_turn_file_changes.py
TurnFileChangeTracker captures workspace changes via temporary git index snapshots before/after turn, generates binary-aware diff patches, persists gzipped artifacts with SHA-256 checksums, tracks per-file additions/deletions/renames, and enforces workspace lock to prevent concurrent trackers. Tests validate snapshots, file categorization, artifact generation, binary detection, reverse-patch application, and lock behavior.
Executor agent lifecycle and completion wiring
executor/agents/base.py, executor/agents/claude_code/claude_code_agent.py, executor/agents/claude_code/response_processor.py, executor/agents/codex/codex_agent.py, executor/agents/codex/event_mapper.py, executor/tests/agents/test_claude_response_processor.py, executor/tests/agents/test_codex_event_mapper.py
Agent base class adds turn_file_change_tracker field and lifecycle methods (start_turn_file_change_tracking, abort_turn_file_change_tracking, collect_turn_file_change_completion_fields). Claude/Codex agents call start before execution, abort on non-completion outcomes, and wire collect_turn_file_change_completion_fields as completion provider. Response processor adds CompletionFieldsProvider callback support and merges provider results into emitter.done() payload. CodeXEventMapper captures native turn diffs for diagnostics.
Backend local device commands for review/revert
backend/app/services/device/command_registry.py, backend/tests/services/test_local_device_command_service.py
New embedded Python script TURN_FILE_CHANGES_SCRIPT validates artifact ID format, loads gzipped patch and metadata, verifies SHA-256 checksum, and either returns decoded patch (review mode) or applies reverse patch via git apply --reverse (revert mode) with conflict detection. Two command registry entries wrap script execution with JSON post-processing. Tests validate registration, path-traversal rejection, diff output, and conflict-safe revert.
Backend schemas, service orchestration, endpoints, and tests
backend/app/schemas/turn_file_changes.py, backend/app/services/turn_file_changes.py, backend/app/api/endpoints/subtasks.py, backend/tests/api/endpoints/test_subtask_file_changes.py, backend/tests/services/test_turn_file_changes_service.py, backend/tests/services/chat/test_trigger_unified.py, backend/tests/services/chat/trigger/test_lifecycle_completed_result.py, backend/tests/services/execution/test_extract_completed_result.py
Pydantic schemas define TurnFileChangeItem, TurnFileChangesSummary, and response models. TurnFileChangesService orchestrates device command execution, validates artifact state, persists status updates, and handles conflict/missing artifact conditions. Two authenticated subtask endpoints (GET /file-changes/diff, POST /file-changes/revert) delegate to service. Service and integration tests verify device matching, offline handling, idempotent revert, conflict handling, and file_changes payload passthrough across completion extraction and request building.
Wework types, API client, normalization, and reducer state
wework/src/types/api.ts, wework/src/types/workbench.ts, wework/src/api/http.ts, wework/src/api/tasks.ts, wework/src/features/workbench/turnFileChanges.ts, wework/src/features/workbench/messageReducer.ts, wework/src/features/workbench/turnFileChanges.test.ts, wework/src/features/workbench/messageReducer.test.ts, wework/src/api/http.test.ts
TypeScript types for turn file changes (status, item, summary, responses). ApiError extended with optional detail field and parseError now extracts nested error code and detail. Task API adds getTurnFileChangesDiff and revertTurnFileChanges methods. normalizeTurnFileChanges validates and type-guards file change payloads. Message reducer adds file_changes_updated action to update file change status on message. Tests validate error parsing, normalization, and status transitions.
Workbench provider actions and page entry wiring
wework/src/features/workbench/WorkbenchProvider.tsx, wework/src/pages/WorkbenchPage.tsx
Provider normalizes and threads file_changes through message creation and assistant completion. Context adds loadTurnFileChangesDiff and revertTurnFileChanges methods; revert method handles success and error-path normalization via ApiError.detail.file_changes. WorkbenchPage destructures and forwards both callbacks to layout.
File changes card/dialog components and chat integration
wework/src/components/chat/parseUnifiedDiff.ts, wework/src/components/chat/FileChangesCard.tsx, wework/src/components/chat/FileChangesReviewDialog.tsx, wework/src/components/chat/FileChangesCard.test.tsx
parseUnifiedDiff parses unified diff into per-file sections. FileChangesCard renders collapsible file list with per-file stats, lazy-loads diffs via callback, shows review modal, handles revert with confirmation, and disables actions when device offline. FileChangesReviewDialog displays diff sections in collapsible form with syntax-like styling. Tests verify expand/collapse, lazy loading, offline disable, confirm-revert flow, and status-driven UI updates.
Message list and scroll area callback passthrough
wework/src/components/chat/MessageList.tsx, wework/src/components/chat/ScrollableMessageArea.tsx
MessageList accepts optional devices and callback props, passes into AssistantMessage. Assistant renderer conditionally renders FileChangesCard when file changes and both callbacks present; computes deviceOnline by device ID and status. Tests verify card renders when data and callbacks present.
Layout callback passthrough and UI style adjustments
wework/src/components/layout/DesktopWorkbenchLayout.tsx, wework/src/components/layout/DesktopWorkbenchMain.tsx, wework/src/components/layout/MobileWorkbenchLayout.tsx, wework/src/components/ui/button.tsx
Desktop/mobile layouts extend props with optional file-changes callback signatures and forward into message area. Desktop main adjusts scroll padding/button offsets and adds new primary button variant.
Chat locale resources for file changes
wework/src/i18n/index.ts, wework/src/i18n/locales/en/chat.json, wework/src/i18n/locales/zh-CN/chat.json
Registers chat namespace alongside common in i18n init. Adds English and Chinese strings for edited file counts, review/revert actions, confirm dialog, loading/error/device offline/conflict/missing artifact states, and binary file labels.
User guides for turn file changes
docs/en/user-guide/coding/turn-file-changes.md, docs/zh/user-guide/coding/turn-file-changes.md
Documents turn file changes card workflow after coding task completion, including how to review full diffs, revert changes with conflict/idempotency guarantees, offline constraints, supported Git workspaces only, and where compressed patches are stored on device and persisted in backend.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • wecode-ai/Wegent#1260: Both PRs modify wework/src/components/chat/ScrollableMessageArea.tsx by extending ScrollableMessageAreaProps; this PR adds file-changes diff/revert callback props while that PR adds scrollButtonClassName, so they overlap at the component API level.

🐰 Captures each turn's workspace dance,
Through snapshots and patches, a Git romance,
Revert with a click, no conflicts in sight,
From executor to UI, file changes done right. 🎯

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

@qdaxb
qdaxb merged commit 5f9dff6 into wecode-ai:main Jun 11, 2026
21 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants