Files
vibe-kanban/crates
Alex Netsch 20b99300fe Add session-level review endpoint with StartReviewDialog (Vibe Kanban) (#1849)
* All checks pass. Let me provide a summary of what was implemented:

I've implemented the review endpoint as planned. Here's what was created:

1. **`crates/executors/src/actions/review.rs`** - New action type with:
   - `RepoReviewContext` struct (repo_id + commit_hashes)
   - `ReviewRequest` struct (executor_profile_id, context, additional_prompt, working_dir)
   - `Executable` trait impl that calls `executor.spawn_review()`

2. **`crates/server/src/routes/task_attempts/review.rs`** - Endpoint handler with:
   - `StartReviewRequest` for the API
   - `RepoReviewContext` (endpoint-specific copy)
   - `ReviewError::ProcessAlreadyRunning`
   - `start_review` handler that:
     - Verifies no running processes on workspace
     - Creates fresh session
     - Builds ReviewRequest action
     - Starts execution with `ExecutionProcessRunReason::CodingAgent`

1. **`crates/executors/src/executors/mod.rs`**:
   - Added `spawn_review()` to `StandardCodingAgentExecutor` trait with default prompt-based implementation
   - Added `build_review_prompt()` helper function

2. **`crates/executors/src/actions/mod.rs`**:
   - Added `pub mod review;`
   - Added `ReviewRequest` to `ExecutorActionType` enum
   - Updated `base_executor()` match

3. **`crates/services/src/services/container.rs`**:
   - Updated match in `try_start_next_action` to handle `ReviewRequest`

4. **`crates/server/src/routes/task_attempts.rs`**:
   - Added `pub mod review;`
   - Added `.route("/review", post(review::start_review))`

5. **`crates/server/src/bin/generate_types.rs`**:
   - Added new types to export list

**`POST /task-attempts/{id}/review`**

Request:
```json
{
  "executor_profile_id": { "executor": "CLAUDE_CODE", "variant": null },
  "context": [{ "repo_id": "uuid", "commit_hashes": ["abc123"] }],
  "additional_prompt": "Focus on security issues"
}
```

Response: `ExecutionProcess` on success, `ReviewError` on failure.

To add native review for an executor (e.g., Codex), just override `spawn_review()` in that executor's `StandardCodingAgentExecutor` impl. No changes needed to action or endpoint.

Cleanup script changes for workspace 38f8b607-9fdc-43dc-afa3-16e8f5e9cbd3

All checks pass now. The duplicate type issue is fixed - we're using a single `RepoReviewContext` type from the executors crate.

All checks pass now. Both frontend lint (ESLint) and backend lint (Clippy) are passing.

Found and fixed the real issue. The problem was in `crates/services/src/services/container.rs` - the log normalization was only set up for `CodingAgentInitialRequest` and `CodingAgentFollowUpRequest`. `ReviewRequest` was falling through to the default case and returning `None`, so no normalizer was started for review processes.

Fixed in two places:
1. **Line 787-791**: Added `ReviewRequest` handling in `stream_normalized_logs` (for historic logs)
2. **Line 1149-1151**: Added `ReviewRequest` handling in `start_execution` (for live logs)

Cleanup script changes for workspace 38f8b607-9fdc-43dc-afa3-16e8f5e9cbd3

* Backend changes for the `use_all_workspace_commits` flag are complete. Here's what was implemented:

Added `use_all_workspace_commits` flag to `StartReviewRequest` for automatically populating review context.

1. **`crates/db/src/models/execution_process_repo_state.rs`**
   - Added `find_initial_commits_for_workspace()` - query to get the earliest `before_head_commit` for each repo in a workspace

2. **`crates/server/src/routes/task_attempts/review.rs`**
   - Added `use_all_workspace_commits: bool` field to `StartReviewRequest` (defaults to `false`)
   - When flag is `true` and `context` is `None`, auto-populates context with initial commits from workspace execution processes

3. **`crates/executors/src/executors/mod.rs`**
   - Updated `build_review_prompt()` to detect single-commit context (indicating initial commit)
   - When single commit per repo, prompts agent to "Review all changes made since the following base commit(s)" with git diff hint

4. **`crates/services/src/services/git.rs`**
   - Added `get_commits_since_branch()` method (may be useful for future use)

5. **`shared/types.ts`**
   - Generated TypeScript type includes `use_all_workspace_commits: boolean`

When frontend calls `POST /task-attempts/{id}/review` with:
```json
{
  "executor_profile_id": { "executor": "CLAUDE_CODE", "variant": null },
  "use_all_workspace_commits": true
}
```

The backend will:
1. Find the earliest execution process for the workspace
2. Get the `before_head_commit` for each repo (the commit before agents started making changes)
3. Pass that to the prompt builder which tells the agent to review all changes since that commit

Cleanup script changes for workspace 38f8b607-9fdc-43dc-afa3-16e8f5e9cbd3

* Frontend UI implementation is complete. Here's a summary of what was added:

Added simple frontend UI to test the review endpoint.

1. **`frontend/src/lib/api.ts`**
   - Added `startReview` method to `attemptsApi`
   - Imports `StartReviewRequest`, `ReviewError` types

2. **`frontend/src/hooks/useStartReview.ts`** (NEW)
   - Hook that calls `attemptsApi.startReview` with `use_all_workspace_commits: true`
   - Invalidates `processes` and `branchStatus` queries on success

3. **`frontend/src/hooks/index.ts`**
   - Exports `useStartReview`

4. **`frontend/src/components/ui/actions-dropdown.tsx`**
   - Added "Start Review" menu item in the attempt actions section
   - Uses the user's default executor profile from config
   - Shows loading state while starting review

5. **`frontend/src/i18n/locales/en/tasks.json`**
   - Added translation keys: `startReview`, `startingReview`

From the workspace actions dropdown (three dots menu), click "Start Review" to start a code review session using all workspace commits as context.

Done! The fix has been implemented. The review endpoint now uses `Session::find_latest_by_workspace_id` to find an existing session for the workspace, and only creates a new session if none exists. This means review logs will now appear in the same conversation view as other coding agent runs.

**Change summary:**
- Modified `crates/server/src/routes/task_attempts/review.rs` (lines 79-93)
- Instead of always creating a new session, it now checks for an existing session first using `Session::find_latest_by_workspace_id`
- This matches the pattern used by dev server, setup scripts, and other similar endpoints

Done! The fix is now in place. The change adds `ReviewRequest` to the action type filter in `useConversationHistory.ts` so review processes are included in the conversation view, and handles the content extraction appropriately (using `additional_prompt` for reviews instead of `prompt`).

**Change summary:**
- Modified `frontend/src/hooks/useConversationHistory.ts` (lines 226-244)
- Added `ReviewRequest` to the action type filter
- Used conditional to extract content from `additional_prompt` for reviews (with fallback "Review the code changes") vs `prompt` for coding agent requests

Cleanup script changes for workspace 38f8b607-9fdc-43dc-afa3-16e8f5e9cbd3

Done! All fixes are now in place:

1. **`useConversationHistory.ts` - `flattenEntries()`** (line 177-184): Added `ReviewRequest` to the filter so review processes are included in the flattened entries
2. **`useConversationHistory.ts` - `flattenEntriesForEmit()`** (line 226-244): Already fixed earlier - handles `ReviewRequest` and extracts `additional_prompt` for user message content
3. **`ProcessesTab.tsx`** (line 223-228): Added `ReviewRequest` to the ProfileVariantBadge conditional so the agent badge shows for review processes

* Done. Changes made:

1. **`crates/executors/src/actions/review.rs`**: Added `prompt: String` field to `ReviewRequest`

2. **`crates/server/src/routes/task_attempts/review.rs`**:
   - Import `build_review_prompt`
   - Build the full prompt from context and additional_prompt before creating the action

3. **`frontend/src/hooks/useConversationHistory.ts`**: Simplified content extraction to just use `actionType.prompt` for all action types (since `ReviewRequest` now has a prompt field too)

4. **Regenerated TypeScript types** - `ReviewRequest` in `shared/types.ts` now includes the `prompt` field

Cleanup script changes for workspace 38f8b607-9fdc-43dc-afa3-16e8f5e9cbd3

* Done. Here's a summary of the changes:

**Backend:**
1. **`crates/executors/src/actions/review.rs`**:
   - Added `CommitRange` enum with three variants: `FromBase`, `Specific`, and `Range`
   - Updated `RepoReviewContext` to use `repo_name: String` and `commits: CommitRange` instead of `commit_hashes`

2. **`crates/executors/src/executors/mod.rs`**:
   - Updated `build_review_prompt` to format output with repo names and handle all `CommitRange` variants

3. **`crates/server/src/routes/task_attempts/review.rs`**:
   - Simplified `StartReviewRequest` (removed `context` field, kept `use_all_workspace_commits`)
   - Updated handler to look up repo names via `Repo::find_by_ids` and use `CommitRange::FromBase`

4. **`crates/server/src/bin/generate_types.rs`**: Added `CommitRange` to exported types

**Frontend:**
- **`frontend/src/hooks/useStartReview.ts`**: Removed `context: null` since that field no longer exists

The prompt will now look like:
```
Please review the code changes.

Repository: vibe-kanban
Review all changes from base commit abc123 to HEAD.
Use `git diff abc123..HEAD` to see the changes.
```

Cleanup script changes for workspace 38f8b607-9fdc-43dc-afa3-16e8f5e9cbd3

* Codex review support (vibe-kanban e7996a18)

## Context

We've added a review endpoint (\`POST /task-attempts/{id}/review\`) that starts a code review session. Currently it uses a default prompt-based implementation via \`spawn\_review()\` on \`StandardCodingAgentExecutor\`, which builds a prompt and delegates to \`spawn()\`.

## Goal

Implement native Codex review support by overriding \`spawn\_review()\` in the Codex executor to use Codex's native review mechanism instead of the prompt-based approach.

## Current Implementation

### Backend Types

\*\*\`CommitRange\` enum\*\* (\`crates/executors/src/actions/review.rs\`):

\`\`\`rust

pub enum CommitRange {

    FromBase { commit: String },

    Specific { commits: Vec<String> },

    Range { from: String, to: String },

}

\`\`\`

\*\*\`RepoReviewContext\`\*\*:

\`\`\`rust

pub struct RepoReviewContext {

    pub repo\_id: Uuid,

    pub repo\_name: String,

    pub commits: CommitRange,

}

\`\`\`

### Trait Method

\*\*\`spawn\_review()\`\*\* in \`StandardCodingAgentExecutor\` trait (\`crates/executors/src/executors/mod.rs\`):

\`\`\`rust

async fn spawn\_review(

    &self,

    current\_dir: &Path,

    context: Option<&[RepoReviewContext]>,

    additional\_prompt: Option<&str>,

    env: &ExecutionEnv,

) -> Result<SpawnedChild, ExecutorError> {

    // Default: build prompt and delegate to spawn()

    let prompt = build\_review\_prompt(context, additional\_prompt);

    self.spawn(current\_dir, &prompt, env).await

}

\`\`\`

## Tasks

1. Research Codex's native review API/mechanism (if it has one)
2. Override \`spawn\_review()\` in \`CodexExecutor\` to use native review if available
3. Fall back to prompt-based approach if native review isn't supported

* Done. Here's a summary of the changes:

1. **Removed dead code** from `crates/executors/src/executors/codex/review.rs`:
   - Deleted the `map_to_review_target()` function (was ~120 lines)
   - Removed unused imports (`CommitRange`, `RepoReviewContext`)

2. **Codex now uses `ReviewTarget::Custom`** with the pre-built prompt, which ensures the displayed prompt matches what Codex actually receives.

The build passes and TypeScript types have been regenerated.

* Use custom review target for codex

* Done. Here's a summary of the changes:

## Summary

Moved the review endpoint from workspace-level to session-level:

### Changes

1. **Created `crates/server/src/routes/sessions/review.rs`**
   - New review endpoint at `POST /sessions/{id}/review`
   - Takes `Extension<Session>` instead of `Extension<Workspace>`
   - Looks up `agent_session_id` from previous executions using `find_latest_coding_agent_turn_session_id()`
   - Passes `agent_session_id` to `ReviewAction` for session resumption

2. **Updated `crates/server/src/routes/sessions/mod.rs`**
   - Added `pub mod review;`
   - Added route `.route("/review", post(review::start_review))`

3. **Updated `crates/server/src/routes/task_attempts.rs`**
   - Removed `pub mod review;`
   - Removed `.route("/review", post(review::start_review))`

4. **Deleted `crates/server/src/routes/task_attempts/review.rs`**

5. **Updated `crates/server/src/bin/generate_types.rs`**
   - Changed path from `task_attempts::review` to `sessions::review`

### API Change

- **Old**: `POST /api/task-attempts/{workspace_id}/review`
- **New**: `POST /api/sessions/{session_id}/review`

This ensures vk sessions and agent sessions are 1:1:
- Existing session → resumes agent session if available
- New session → fresh agent session

* Done! Here's a summary of all the frontend changes:

- Added `startReview` to `sessionsApi` using new endpoint `POST /api/sessions/${sessionId}/review`
- Removed `startReview` from `attemptsApi`

- Changed parameter from `attemptId` to `sessionId` and added optional `workspaceId` for query invalidation
- Changed API call from `attemptsApi.startReview` to `sessionsApi.startReview`

- Added `MagnifyingGlassIcon` import
- Added `onStartReview` and `isReviewStarting` to `SessionProps` interface
- Added "Start Review" menu item in the session dropdown

- Added `useStartReview` hook import and usage
- Added `handleStartReview` callback function
- Passed `onStartReview` and `isReviewStarting` to `SessionChatBox`

- Removed `useStartReview` import
- Removed `useUserSystem` import (now unused)
- Removed `startReview` hook usage
- Removed `handleStartReview` function
- Removed "Start Review" menu item from the dropdown

* Done. The fix adds the `ReviewRequest` case to `latest_executor_profile_for_session()` in `crates/db/src/models/execution_process.rs:688-690`.

The backend check passes. Follow-ups after reviews should now work correctly since the executor profile can be extracted from `ReviewRequest` just like from the other request types.

* Done. Removed `CommitRange` enum entirely. Changes:

1. **`crates/executors/src/actions/review.rs`** - Deleted `CommitRange` enum, changed `RepoReviewContext.commits` to `RepoReviewContext.base_commit: String`

2. **`crates/server/src/routes/sessions/review.rs`** - Updated construction to use `base_commit: initial_commit` instead of `commits: CommitRange::FromBase { commit: initial_commit }`

3. **`crates/executors/src/executors/mod.rs`** - Simplified `build_review_prompt()` to directly use `repo.base_commit` instead of matching on the enum

4. **`crates/server/src/bin/generate_types.rs`** - Removed `CommitRange::decl()` from type exports

5. **`shared/types.ts`** - Regenerated, `CommitRange` type is now gone

Cleanup script changes for workspace 38f8b607-9fdc-43dc-afa3-16e8f5e9cbd3

* Done. Simplified the review context building:

**Changes:**

1. **`crates/db/src/models/execution_process_repo_state.rs`** - Replaced `find_initial_commits_for_workspace` with `find_initial_commit_for_repo` that takes a specific repo_id and uses ORDER BY + LIMIT 1 instead of GROUP BY/HAVING.

2. **`crates/server/src/routes/sessions/review.rs`** - Simplified the context building:
   - Get workspace repos first (has repo names via `display_name`)
   - For each repo, get initial commit
   - Build context directly - no more HashMap joining, no more separate `Repo::find_by_ids` call

The new code is much easier to follow: get repos → for each, get initial commit → build context.

* Done. Addressed all 23 review comments:

1. Removed comment from `SessionChatBoxContainer.tsx` (line 161)
2. Removed doc comments from `RepoReviewContext` and `ReviewRequest` structs in `review.rs`
3. Removed module doc comment from `codex/review.rs`
4. Removed comment from `codex.rs` about Custom review target
5. Removed doc comments from `spawn_review` trait method in `mod.rs`
6. Removed doc comment from `build_review_prompt` function
7. Removed all comments from `sessions/review.rs` (doc comments and inline comments)
8. Removed unused `get_commits_since_branch` function from `git.rs` (~45 lines of dead code)

* Done. Added the review toggle button:

**Changes:**

1. **`SessionChatBox.tsx`**
   - Added `ReviewModeProps` interface with `isActive`, `onToggle`, `isSubmitting`
   - Added `reviewMode` prop to `SessionChatBoxProps`
   - Added toggle button next to attach button (MagnifyingGlassIcon) - highlighted when active
   - Updated placeholder to show "Enter review instructions..." when in review mode
   - Removed old `onStartReview` and `isReviewStarting` from SessionProps
   - Removed "Start Review" dropdown menu item

2. **`SessionChatBoxContainer.tsx`**
   - Added `useState` for `isReviewMode`
   - Updated `handleSend` to call `startReviewMutation` with `additionalPrompt` when in review mode
   - Reset review mode after successful review start
   - Pass `reviewMode` props to SessionChatBox
   - Removed old `handleStartReview` callback

Now the user can:
1. Click the magnifying glass toggle next to attach
2. Enter review instructions in the text area
3. Click send → starts review with the prompt

Cleanup script changes for workspace 38f8b607-9fdc-43dc-afa3-16e8f5e9cbd3

TypeScript and Rust both compile. The changes are:
1. Button shows "Review" when review mode is active
2. Toggle icon uses `!text-accent-foreground` to force override the `text-low` class from the base component, along with `bg-accent rounded-sm` for the background highlight

Done. Changed `!text-accent-foreground` to `!text-normal` which uses the design system's proper text color for active/selected states. The `!` prefix forces the override of the base `text-low` class. Both TypeScript and Rust compile successfully.

Cleanup script changes for workspace 38f8b607-9fdc-43dc-afa3-16e8f5e9cbd3

All done. TypeScript and Rust compile successfully. Here's a summary of the changes:

**Created:**
- `frontend/src/components/dialogs/tasks/StartReviewDialog.tsx` - New dialog with:
  - Agent/variant selection (using ExecutorProfileSelector)
  - Review comments preview (if any)
  - Additional instructions textarea
  - Start Review / Cancel buttons

**Modified:**
- `frontend/src/components/dialogs/index.ts` - Added export for StartReviewDialog
- `frontend/src/components/ui-new/primitives/SessionChatBox.tsx`:
  - Changed `ReviewModeProps` from toggle state to simple callback (`onReviewClick`, `isDisabled`)
  - Removed toggle styling and review mode button text
  - Button now just opens the dialog
- `frontend/src/components/ui-new/containers/SessionChatBoxContainer.tsx`:
  - Removed `isReviewMode` state and `startReviewMutation`
  - Added `handleReviewClick` callback that opens `StartReviewDialog`
  - Disabled review button when in new session mode or no session exists

Cleanup script changes for workspace 38f8b607-9fdc-43dc-afa3-16e8f5e9cbd3

Done. TypeScript and Rust compile successfully. Summary of changes:

**`StartReviewDialog.tsx`:**
- Added "New Session" toggle (defaults ON when no session exists, disabled when no session to toggle from)
- Added conditional `AgentSelector` - only shown when creating a new session
- Always shows `ConfigSelector` for variant selection
- Handles session creation inline when toggle is on or no session exists
- Updated `onSuccess` callback to return new session ID when created

**`SessionChatBox.tsx`:**
- Removed `isDisabled` from `ReviewModeProps` interface
- Removed `reviewMode.isDisabled` from button disabled logic

**`SessionChatBoxContainer.tsx`:**
- Updated `handleReviewClick` to allow opening dialog without sessionId
- Updated `onSuccess` callback to select the new session if one was created
- Removed `isDisabled` from reviewMode prop

Cleanup script changes for workspace 38f8b607-9fdc-43dc-afa3-16e8f5e9cbd3

Done. Made `reviewMode` required and removed the conditional - the review button is now always shown.

Done. Now the StartReviewDialog:
- Shows `ExecutorProfileSelector` (Agent + Configuration side by side, like CreateAttemptDialog) when "New Session" toggle is ON
- Shows just `ConfigSelector` (variant only) when "New Session" toggle is OFF

TypeScript and Rust compile successfully. The Switch layout has been fixed to match the TaskFormDialog pattern:
- Switch is now on the LEFT of the label
- Uses `gap-2` instead of `justify-between`
- Has proper dark mode styling with `data-[state=checked]:bg-gray-900 dark:data-[state=checked]:bg-gray-100`
- Label has `cursor-pointer` for better UX

Cleanup script changes for workspace 38f8b607-9fdc-43dc-afa3-16e8f5e9cbd3

Done. The Switch is now moved to the footer (bottom of the dialog), matching the TaskFormDialog pattern:
- Switch on the left side of the footer
- Cancel and Start Review buttons on the right side
- Added `disabled:opacity-50` for better visibility when disabled in dark mode

Done. All changes complete:

1. **Removed header** - No more "Start Review" title or description
2. **Removed labels from selectors** - `showLabel={false}` for both `ExecutorProfileSelector` and `ConfigSelector`
3. **Fixed footer layout** - Cancel button on left, Switch + "New Session" + "Start Review" button grouped on right (matching TaskFormDialog)
4. **TypeScript compiles** - Both frontend and backend checks pass

Done. Changes made:

1. **Moved selector to bottom** - Now the order is: Additional Instructions textarea → Review comments preview → Error → Profile/Config selector → Footer

2. **Fixed Switch visibility** - Changed from `data-[state=checked]:bg-gray-900 dark:data-[state=checked]:bg-gray-100` to `bg-muted-foreground/30 data-[state=checked]:bg-foreground` using semantic colors

3. **TypeScript compiles** - Both frontend and backend checks pass

Done. The Switch className now uses `!` important modifiers to override the component's hardcoded background colors:
- `!bg-muted-foreground/30` - visible gray background when unchecked (overrides `bg-input`)
- `data-[state=checked]:!bg-foreground` - foreground color when checked (overrides `bg-foreground`)

Done. Changed the Switch className to use `!bg-muted` which should provide better contrast against the dialog's `bg-primary` background.

Done. Changed the Switch className to use `!bg-border` which should provide some contrast against the dialog's `bg-primary` background (25% lightness vs 18% lightness).

* Fix duplicate routes

* I've analyzed the problem. Here's my understanding:

**The issue:** After rebasing, stored commit SHAs (`after_head_commit`) become invalid because rebasing rewrites history with new SHAs.

**Your suggestion (`git diff A^..B`):** This still has the same problem - after rebase, commit `A` doesn't exist with that SHA anymore. `A^` requires resolving commit `A` first.

**My recommended fix:** Instead of using stored commit SHAs, use the **branch name** as the base:
- `git diff {target_branch}..HEAD` instead of `git diff {commit_sha}..HEAD`
- This is always valid regardless of rebasing
- Matches user intent: "show all changes on this workspace branch vs base"

This would require changes to:
1. `review.rs` - use `workspace.target_branch` instead of querying `find_first_commit_for_repo`
2. `build_review_prompt` - update to use branch name
3. `RepoReviewContext` - change `base_commit` to `base_branch`

**Questions:**
1. Is using `target_branch` the right base? Or do you need something more granular like "changes since session X"?
2. Should we keep `before_head_commit`/`after_head_commit` for per-execution tracking, or simplify?

* Done. Here's a summary of the changes:

## Changes Made

### 1. `crates/services/src/services/git/cli.rs`
- Made `merge_base` method public (was `fn`, now `pub fn`)

### 2. `crates/services/src/services/git.rs`
- Added new public method `get_fork_point()` that wraps the CLI `merge_base` function
- This method uses `git merge-base --fork-point` which survives rebasing by consulting the reflog

### 3. `crates/server/src/routes/sessions/review.rs`
- Removed import of `ExecutionProcessRepoState` (no longer needed)
- Added `PathBuf` import
- Changed from querying stored `after_head_commit` SHAs to computing fork-point dynamically
- Now uses `WorkspaceRepo::find_repos_with_target_branch_for_workspace` to get per-repo target branches
- Computes `get_fork_point(repo_path, target_branch, workspace.branch)` for each repo

## How It Works Now

Instead of storing commit SHAs that become invalid after rebasing:
```rust
// Old (broken after rebase):
let base_commit = ExecutionProcessRepoState::find_first_commit_for_repo(...)
```

We now compute the fork-point dynamically:
```rust
// New (survives rebasing):
let base_commit = deployment.git().get_fork_point(
    &repo_path,
    &repo.target_branch,  // e.g., "main"
    &workspace.branch,     // e.g., "vk/task-123"
)
```

This uses `git merge-base --fork-point` which consults the reflog to find where the branch originally diverged, regardless of subsequent rebases.

* Cleanup script changes for workspace 38f8b607-9fdc-43dc-afa3-16e8f5e9cbd3

* Removed the unused `find_first_commit_for_repo` function. Everything still compiles.

* All comments removed and code still compiles.

* Fixed. The changes:

1. Added `effective_dir` method to `ReviewRequest` in `crates/executors/src/actions/review.rs`
2. Updated `container.rs` to use `request.effective_dir(&workspace_root)` instead of `workspace_root.clone()` for `ReviewRequest`

Now the log normalization for reviews will use the correct working directory, matching how the agent is actually spawned.

* Fixed. Now the workspace is re-fetched after `ensure_container_exists` to get the updated `container_ref`.

* Fixed. Now using the `container_ref` returned directly from `ensure_container_exists` instead of re-fetching the workspace.

* Fixed the naming:
- `workspace_path` - the container_ref path containing all repos
- `worktree_path` - the path to a specific repo's worktree within the workspace

* Cleanup script changes for workspace 38f8b607-9fdc-43dc-afa3-16e8f5e9cbd3

* Done. I've added an "Include git context" checkbox to the StartReviewDialog:

- Added state `includeGitContext` defaulting to `true`
- Added a checkbox UI with label "Include git context"
- The checkbox value is passed to the API as `use_all_workspace_commits`

The checkbox appears after the error message area and before the executor profile selector. Users will see it checked by default, making it clear that git context is being included without needing to add it themselves in the prompt.

* I've completed the i18n task. Here's a summary of what was done:

1. **Added i18n support to `StartReviewDialog.tsx`**:
   - Imported `useTranslation` from `react-i18next`
   - Replaced all hardcoded strings with translation keys:
     - "Additional Instructions (optional)" → `t('startReviewDialog.additionalInstructions')`
     - "Review Comments (...)" → `t('startReviewDialog.reviewComments', { count: ... })`
     - "Include git context" → `t('startReviewDialog.includeGitContext')`
     - "New Session" → `t('startReviewDialog.newSession')`
     - "Cancel" → `t('common:buttons.cancel')`
     - "Starting..." / "Start Review" → `t('actionsMenu.startingReview')` / `t('actionsMenu.startReview')`

2. **Added translations to all locale files** (`en`, `es`, `ja`, `ko`, `zh-Hans`, `zh-Hant`):
   - Added `startReviewDialog` object with `additionalInstructions`, `reviewComments`, `includeGitContext`, and `newSession` keys
   - Added `actionsMenu.startReview` and `actionsMenu.startingReview` to all non-English locales

3. **Verified with i18n check script**: All checks pass - no new literal strings introduced, no duplicate keys, and translation keys are consistent across all locales.

* Cleanup script changes for workspace 38f8b607-9fdc-43dc-afa3-16e8f5e9cbd3

* All checks pass. I've added a description below the "Include git context" checkbox:

**English:** "Tells the agent how to view all changes made on this branch"

The description appears as smaller muted text below the checkbox, explaining to users what the option does - it instructs the agent how to see all the changes on this branch (via the git diff command we inject). This helps users understand they don't need to manually ask the agent about branch changes.

* Done. Here's a summary of the changes:

1. **Replaced conditional rendering** with always showing both `AgentSelector` and `ConfigSelector`

2. **Agent selector is disabled** when `createNewSession` is false (locked to the session's executor)

3. **Fixed the variant retention bug** by adding `handleNewSessionChange` that resets `selectedProfile` to `defaultProfile` when toggling "New Session" off - this ensures the variant matches the locked executor

* Types

* Removed the unused `useStartReview` hook and its export from `hooks/index.ts`.

* All checks pass. Here's a summary of the changes made:

**`frontend/src/components/ui-new/actions/index.ts`:**
1. Added `HighlighterIcon` to the Phosphor icons import (line 33)
2. Added `StartReviewDialog` import (line 49)
3. Added `StartReview` action definition (lines 293-304) with:
   - `id: 'start-review'`
   - `label: 'Start Review'`
   - `icon: HighlighterIcon`
   - `requiresTarget: true`
   - Visibility when workspace exists
   - Execute function that opens `StartReviewDialog`

**`frontend/src/components/ui-new/actions/pages.ts`:**
1. Added `{ type: 'action', action: Actions.StartReview }` as the first item in the `workspaceActions` page group (line 105)

The "Start Review" action with the highlighter icon will now appear in the workspace actions menu (accessed via CMD+K or the three-dots menu on a workspace).

* All checks pass. Done. Here's a summary of the additional change:

**`frontend/src/components/ui-new/primitives/SessionChatBox.tsx`:**
- Changed `MagnifyingGlassIcon` to `HighlighterIcon` in the import (line 12)
- Updated the `ToolbarIconButton` to use `HighlighterIcon` instead of `MagnifyingGlassIcon` (line 635)

The review button in the text input now shows the highlighter icon instead of the magnifying glass.

* All checks pass. Here's a summary of the changes:

**`frontend/src/components/ui-new/primitives/Toolbar.tsx`:**
- Added proper disabled styling to `ToolbarIconButton` (`opacity-40 cursor-not-allowed`)

**`frontend/src/components/ui-new/primitives/SessionChatBox.tsx`:**
- Removed `HighlighterIcon` import (no longer hardcoded)
- Added `Icon` type import
- Replaced `ReviewModeProps` with generic `ToolbarActionProps` interface (`icon`, `label`, `onClick`)
- Changed `reviewMode` prop to `toolbarActions?: ToolbarActionProps[]`
- Updated footer to render toolbar actions dynamically from the array

**`frontend/src/components/ui-new/containers/SessionChatBoxContainer.tsx`:**
- Added `HighlighterIcon` import
- Changed `reviewMode` prop to `toolbarActions` array with the review action

The button is now:
1. Generic - accepts any action with icon/label/onClick
2. Shows proper disabled state (opacity + cursor)
3. Extensible - you can add more toolbar actions by adding to the array

* All checks pass. Now toolbar actions work identically to navbar actions:

**Summary of changes:**

1. **`SessionChatBox.tsx`**:
   - Changed `toolbarActions` prop from simple `{icon, label, onClick}[]` to `{actions, context, onExecuteAction}` structure
   - Uses `ActionDefinition[]` from the actions system
   - Uses `isActionEnabled()` to derive disabled state from action context
   - Uses `isSpecialIcon()` to filter out non-standard icons
   - Handles `label` being either a string or function

2. **`SessionChatBoxContainer.tsx`**:
   - Added `useActions()` and `useActionVisibilityContext()` hooks
   - Created `handleToolbarAction` callback that routes actions through `executeAction`
   - Created `toolbarActionsList` array containing `Actions.StartReview`
   - Passes the full action context to `SessionChatBox`

Now adding a new action to the conversation input works the same as navbar:

```typescript
// Just add to the array
const toolbarActionsList = useMemo(
  () => [Actions.StartReview, Actions.SomeOtherAction],
  []
);
```

The action's `isVisible`, `isEnabled`, icon, label, and execute logic all come from the central `Actions` definition in `index.ts`.

* Cleanup script changes for workspace 38f8b607-9fdc-43dc-afa3-16e8f5e9cbd3

* Done. The "Start Review" action with the highlighter icon now appears in both the navbar (left side) and the chat input toolbar.

* Cleanup script changes for workspace 38f8b607-9fdc-43dc-afa3-16e8f5e9cbd3

* Done. Removed `StartReview` from the navbar and added `ToggleChangesMode` to the conversation input toolbar alongside `StartReview`.

* Done.

* Removed the review-specific branch so the handler is generic, matching other containers. The toolbar action now just respects `requiresTarget`.

Details and context:
- Simplified the action handler in `frontend/src/components/ui-new/containers/SessionChatBoxContainer.tsx:444` to rely solely on the generic `action.requiresTarget` path.
- This aligns with `frontend/src/components/ui-new/containers/NavbarContainer.tsx:66`, where all actions flow through the same generic logic.

Next steps:
1) If you want, I can run a quick lint/typecheck on the frontend (`pnpm run check`) to confirm.

* Aligned the chatbox to use the shared visibility system, like the navbar, so action availability is handled by the same logic and execution stays generic.

Details and context:
- Filtered `toolbarActionsList` through `isActionVisible` with the shared `actionCtx` so Start Review only appears when it’s supposed to.
- Kept the execution handler generic so it just respects `requiresTarget`.

Files:
- `frontend/src/components/ui-new/containers/SessionChatBoxContainer.tsx`

Next steps:
1) If you want me to run a quick frontend typecheck (`pnpm run check`), say the word.

* Cleanup script changes for workspace 38f8b607-9fdc-43dc-afa3-16e8f5e9cbd3

* Updated the Start Review dialog so it derives the active session and a default executor profile from workspace context + config, which restores preselection and enables the “new session” toggle when a session exists. This keeps the chatbox action generic while fixing the dialog behavior.

Details and context:
- Added workspace context awareness and default profile derivation (mirrors Create Attempt’s logic).
- Uses the resolved session id to enable/disable the toggle and to decide whether a new session is required.
- Keeps user selection override behavior intact.

File:
- `frontend/src/components/dialogs/tasks/StartReviewDialog.tsx`

If you want, I can also add a quick regression check or walk through the UI flow with you.

* Fixed the lint issue and clippy qa-mode compile warning, then reran the requested commands. The Start Review dialog now uses `resolvedSessionId` consistently in its callback, and review log normalization handles qa-mode without unused vars.

Files updated:
- `frontend/src/components/dialogs/tasks/StartReviewDialog.tsx`
- `crates/services/src/services/container.rs`

Commands run:
- `npm run lint`
- `npm run format`
- `npm run check`

* Renamed the match binding to `_request` so we don’t need the no-op line, and removed the comment you flagged.

Notes:
- The `let _ = request;` was only there to silence an unused-var warning under the `qa-mode` cfg. Using `_request` is the standard way to mark it intentionally unused.

Files:
- `crates/services/src/services/container.rs`
- `frontend/src/components/ui-new/containers/SessionChatBoxContainer.tsx`

Want me to rerun `npm run lint` since this touched the linted files?

* Split the `ReviewRequest` arm by cfg so qa-mode uses `_request` and non-qa uses `request` normally—no dummy line needed.

File:
- `crates/services/src/services/container.rs`

* Done. The fix adds `ReviewRequest` to the match statement that creates `CodingAgentTurn` records. Now when a review is started, a `coding_agent_turn` row will be created with the review prompt, and the `agent_session_id` will be stored when Codex reports it. Subsequent follow-ups will find this session ID and correctly use `CodingAgentFollowUpRequest` instead of starting a fresh session.

* Done. Now if a new `ExecutorActionType` variant is added, the compiler will error on this match and force the developer to decide whether it should create a `CodingAgentTurn` record.

* Adjusted `sessionsApi.startReview` to return the unwrapped payload like other session calls, and aligned the `handleApiResponse` generic so callers get an `ExecutionProcess` instead of a misleading `ApiResponse`. This fixes the runtime mismatch and keeps the API consistent.

Updated `frontend/src/lib/api.ts`.

If you want, I can:
1) run `pnpm run check` to validate types, or
2) scan for any other session APIs with inconsistent `handleApiResponse` generics.

* All checks pass. Summary of changes:

1. **Removed tooltip from dialog button** - Dialog buttons don't use tooltips in this codebase
2. **Added `getTooltip` to the `StartReview` action definition** in `actions/index.ts` - This is the pattern used for action tooltips ("Ask the agent to review your changes")
3. **Removed `submitTooltip` from all locale files** since it's no longer used
4. **Added missing `title` and `description` to zh-Hant locale**

* Done. Now when a new session is created, the dialog will call `selectSession(targetSessionId)` to switch to the newly created session before closing.
2026-01-12 19:28:55 +00:00
..
2026-01-12 16:57:54 +00:00
2026-01-12 16:57:54 +00:00
2026-01-12 16:57:54 +00:00
2026-01-12 16:57:54 +00:00