Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

Summary

Adds model selection flag to /new command and improves workspace modal UX by consolidating state management and conditionally showing the start message textarea.

Changes

1. Add -m flag for model selection

  • /new command now supports -m <model> to specify initial model (like /compact does)
  • Model abbreviations work: -m sonnetanthropic:claude-sonnet-4-5
  • Flag is parsed and forwarded to modal on errors

2. Forward start message to modal on errors

  • When /new fails or opens modal, preserves start message and model
  • Modal displays textarea for start message (when provided)
  • Start message is sent after workspace creation

3. Consolidate workspace modal state

  • Replaced 8 separate useState declarations with single workspaceModalState object
  • Reduces setState calls from 8→1 when opening/closing modal
  • Extracted INITIAL_WORKSPACE_MODAL_STATE constant for DRY

4. Conditional textarea display

  • Start message textarea only appears when initialStartMessage is provided
  • Reduces visual clutter for manual workspace creation flow
  • Users can send messages after creation instead

5. DRY improvements

  • Extracted resetForm() helper in NewWorkspaceModal
  • Consistent state resets across all code paths

Testing

✅ All 16 /new command tests pass
✅ All 70 slash command tests pass
✅ Type checking passes (main + renderer)
✅ Code formatted

Example Usage

/new feature-branch -m sonnet -t main
This is a start message that will be sent after workspace creation

Generated with cmux

- Support /new -m <model> to set initial model (like /compact)
- Forward start message and model to modal when errors occur
- Add textarea in NewWorkspaceModal for start message display
- Model selector defaults to provided model or workspace default
- Send start message with specified model after workspace creation

Fixes three bugs:
1. Missing -m flag support for model selection
2. Lost start message on errors (now preserved in modal)
3. No way to see/edit start message in error modal

All tests pass (16 /new command tests + 54 other slash command tests).
Replaced 8 separate useState declarations with a single workspaceModalState
object. This reduces setState calls from 8 to 1 when opening/closing the
modal, making updates atomic and improving code organization.

Changes:
- Consolidated state: isOpen, projectPath, projectName, branches,
  defaultTrunk, loadError, startMessage, model
- Updated handleAddWorkspace to use single setState
- Updated modal onClose to use single setState
- Updated handleCreateWorkspace and modal render to reference new state

Generated with `cmux`
The start message textarea now only appears when initialStartMessage is
provided (i.e., from /new command flow). In the normal modal flow where
users manually create workspaces, the field is hidden since users can
just send a message after workspace creation.

This reduces visual clutter and makes the modal more focused for the
common case.

Generated with `cmux`
Extracted duplicated state to constants/helpers:
- INITIAL_WORKSPACE_MODAL_STATE in App.tsx (used in useState + onClose)
- resetForm() in NewWorkspaceModal.tsx (used in handleCancel + handleSubmit)

Reduces duplication and ensures consistent state resets across all paths.

Generated with `cmux`
…acks

Simplifications in App.tsx for net negative LoC:
- Moved INITIAL_WORKSPACE_MODAL_STATE to module scope (prevents recreation)
- Removed thin wrapper callbacks (handleAddProjectCallback, etc.)
- Directly pass functions to LeftSidebar (addProject, handleAddWorkspace, handleRemoveProject)

Net impact: 774 → 757 lines (-17 LoC)

Generated with `cmux`
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Moved all workspace modal management out of App.tsx into a dedicated
custom hook for better separation of concerns:

- Created src/hooks/useWorkspaceModal.ts (181 lines)
- Removed 126 lines of modal logic from App.tsx
- App.tsx reduced from 755 → 629 lines (net -126 LOC in App.tsx)
- Overall project net +55 LOC (181 new - 126 removed)

Benefits:
- App.tsx is now more minimal and focused on layout/routing
- Modal logic is self-contained and reusable
- Easier to test modal behavior in isolation
- Clearer separation between UI structure and modal state management

Generated with `cmux`
The parsed model value was not being forwarded to createNewWorkspace,
so successful '/new -m <model>' commands still sent the start message
with whatever model was previously active. Only the error path and
modal reused the flag.

Fixed by:
- Added model?: string to CreateWorkspaceOptions interface
- Applied model override to sendMessageOptions before sending message
- Forwarded parsed.model from handleNewCommand to createNewWorkspace

Now -m flag works correctly for both successful and failed /new attempts.

Generated with `cmux`
- Removed unused useState import
- Removed unused RuntimeConfig and getRuntimeKey imports
- Fixed workspaceModal dependency warnings by including whole object
- Fixed promise-returning function warnings with explicit void wrappers
- Fixed unsafe any types in useWorkspaceModal with WorkspaceSelection type
- Fixed registerParamsRef type issues with explicit BuildSourcesParams type

Generated with `cmux`
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.

1 participant