Add --name flag to new-workspace CLI command - #2160
Conversation
Allow naming a workspace at creation time instead of requiring a separate rename-workspace call afterward. Threads a title parameter through: - CLI: --name <title> flag parsed and sent as "title" in v2 params - V2 handler: extracts title, passes to TabManager.addWorkspace() - TabManager: uses provided title instead of auto-generated "Terminal N" and calls setCustomTitle() to persist it - V1 handler: accepts optional name argument Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@ueg1990 is attempting to deploy a commit to the Manaflow Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughThis change adds support for custom workspace naming via a Changes
Sequence DiagramsequenceDiagram
actor User
participant CLI as CLI Parser<br/>(cmux.swift)
participant Controller as TerminalController
participant TabMgr as TabManager
participant Workspace as Workspace
User->>CLI: cmux new-workspace --name "My Workspace"
CLI->>CLI: Parse --name flag
CLI->>Controller: Call newWorkspace(args) or v2 request<br/>with params["title"]
Controller->>Controller: Extract & trim title
Controller->>TabMgr: addWorkspace(title: "My Workspace")
TabMgr->>Workspace: Create workspace with<br/>default title
TabMgr->>Workspace: setCustomTitle("My Workspace")
Workspace-->>TabMgr: Custom title applied
TabMgr-->>Controller: Workspace created
Controller-->>CLI: Success
CLI-->>User: New workspace with custom name
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR adds a
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant CLI as cmux CLI
participant Sock as v2 Socket Handler
participant TM as TabManager
participant WS as Workspace
CLI->>Sock: workspace.create {title, cwd, command}
Sock->>Sock: trim + nil-coalesce title
Sock->>TM: addWorkspace(title:, workingDirectory:, ...)
TM->>WS: makeWorkspaceForCreation(title: title ?? "Terminal N", ...)
WS-->>TM: Workspace instance (title set)
TM->>WS: setCustomTitle(title) — locks custom name
TM-->>Sock: Workspace
Sock-->>CLI: {workspace_ref, workspace_id}
Reviews (1): Last reviewed commit: "Add --name flag to new-workspace CLI com..." | Re-trigger Greptile |
| if title != nil { | ||
| newWorkspace.setCustomTitle(title) | ||
| } |
There was a problem hiding this comment.
Use
if let instead of != nil guard
setCustomTitle(_:) accepts String?, so passing the still-wrapped optional compiles fine — but it's non-idiomatic Swift and masks the intent. Prefer unwrapping explicitly so it's obvious you're passing a concrete value:
| if title != nil { | |
| newWorkspace.setCustomTitle(title) | |
| } | |
| if let title { | |
| newWorkspace.setCustomTitle(title) | |
| } |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
Sources/TabManager.swift (1)
1202-1240:⚠️ Potential issue | 🟠 MajorLocalize default title and normalize
titleat this boundary.Line 1230 uses a bare user-facing string, and current creation still trusts upstream normalization. Normalizing in
TabManager.addWorkspaceensures whitespace-only names reliably fall back to default and avoids carrying a blank/whitespace process title intoWorkspaceinitialization.Proposed patch
@@ ) -> Workspace { @@ let insertIndex = newTabInsertIndex(snapshot: snapshot, placementOverride: placementOverride) let ordinal = Self.nextPortOrdinal Self.nextPortOrdinal += 1 + let normalizedTitle = title?.trimmingCharacters(in: .whitespacesAndNewlines) + let customTitle = (normalizedTitle?.isEmpty == false) ? normalizedTitle : nil + let defaultTitle = String( + localized: "workspace.defaultTitle", + defaultValue: "Terminal \(nextTabCount)" + ) let newWorkspace = makeWorkspaceForCreation( - title: title ?? "Terminal \(nextTabCount)", + title: customTitle ?? defaultTitle, workingDirectory: workingDirectory, portOrdinal: ordinal, configTemplate: inheritedConfig, initialTerminalCommand: initialTerminalCommand, initialTerminalEnvironment: initialTerminalEnvironment ) newWorkspace.owningTabManager = self - if title != nil { - newWorkspace.setCustomTitle(title) + if let customTitle { + newWorkspace.setCustomTitle(customTitle) }As per coding guidelines:
**/*.swift: All user-facing strings must be localized usingString(localized: "key.name", defaultValue: "English text").🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@Sources/TabManager.swift` around lines 1202 - 1240, Normalize and localize the default workspace title in TabManager.addWorkspace: trim and treat a title that is nil or only whitespace as absent, then use a localized default like String(localized: "tab.defaultTitle", defaultValue: "Terminal %d") (format with nextTabCount) when constructing the title passed into makeWorkspaceForCreation (and into setCustomTitle only if an actual non-empty custom title remains); ensure you perform this normalization before calling makeWorkspaceForCreation and before sentryBreadcrumb/other uses so no whitespace-only title reaches Workspace initialization.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@CLI/cmux.swift`:
- Around line 1689-1691: The handler for the new-workspace command currently
only rejects unknown flags but ignores stray positional tokens in the remaining
array; update the logic around remaining to also detect any elements that do not
start with "--" (i.e., unexpected positional args) and throw a CLIError with a
clear message (similar to the existing flag error) for new-workspace so inputs
like "cmux new-workspace --name Build Server" fail rather than silently drop
"Server"; reference the existing remaining variable and CLIError to implement
this validation.
---
Outside diff comments:
In `@Sources/TabManager.swift`:
- Around line 1202-1240: Normalize and localize the default workspace title in
TabManager.addWorkspace: trim and treat a title that is nil or only whitespace
as absent, then use a localized default like String(localized:
"tab.defaultTitle", defaultValue: "Terminal %d") (format with nextTabCount) when
constructing the title passed into makeWorkspaceForCreation (and into
setCustomTitle only if an actual non-empty custom title remains); ensure you
perform this normalization before calling makeWorkspaceForCreation and before
sentryBreadcrumb/other uses so no whitespace-only title reaches Workspace
initialization.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a002c5a6-cfe1-4ff7-9827-58ebdb50b836
📒 Files selected for processing (3)
CLI/cmux.swiftSources/TabManager.swiftSources/TerminalController.swift
| if let unknown = remaining.first(where: { $0.hasPrefix("--") }) { | ||
| throw CLIError(message: "new-workspace: unknown flag '\(unknown)'. Known flags: --command <text>, --cwd <path>") | ||
| throw CLIError(message: "new-workspace: unknown flag '\(unknown)'. Known flags: --name <title>, --command <text>, --cwd <path>") | ||
| } |
There was a problem hiding this comment.
Reject unexpected positional arguments for new-workspace.
Line [1689] only rejects unknown flags, so stray positional tokens are silently ignored (e.g., cmux new-workspace --name Build Server drops Server). Please fail fast on unexpected non-flag args.
💡 Suggested fix
- if let unknown = remaining.first(where: { $0.hasPrefix("--") }) {
+ let unexpectedArgs = remaining.filter { $0 != "--" }
+ if let unknown = unexpectedArgs.first(where: { $0.hasPrefix("--") }) {
throw CLIError(message: "new-workspace: unknown flag '\(unknown)'. Known flags: --name <title>, --command <text>, --cwd <path>")
}
+ if let extra = unexpectedArgs.first(where: { !$0.hasPrefix("--") }) {
+ throw CLIError(message: "new-workspace: unexpected argument '\(extra)'")
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if let unknown = remaining.first(where: { $0.hasPrefix("--") }) { | |
| throw CLIError(message: "new-workspace: unknown flag '\(unknown)'. Known flags: --command <text>, --cwd <path>") | |
| throw CLIError(message: "new-workspace: unknown flag '\(unknown)'. Known flags: --name <title>, --command <text>, --cwd <path>") | |
| } | |
| let unexpectedArgs = remaining.filter { $0 != "--" } | |
| if let unknown = unexpectedArgs.first(where: { $0.hasPrefix("--") }) { | |
| throw CLIError(message: "new-workspace: unknown flag '\(unknown)'. Known flags: --name <title>, --command <text>, --cwd <path>") | |
| } | |
| if let extra = unexpectedArgs.first(where: { !$0.hasPrefix("--") }) { | |
| throw CLIError(message: "new-workspace: unexpected argument '\(extra)'") | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@CLI/cmux.swift` around lines 1689 - 1691, The handler for the new-workspace
command currently only rejects unknown flags but ignores stray positional tokens
in the remaining array; update the logic around remaining to also detect any
elements that do not start with "--" (i.e., unexpected positional args) and
throw a CLIError with a clear message (similar to the existing flag error) for
new-workspace so inputs like "cmux new-workspace --name Build Server" fail
rather than silently drop "Server"; reference the existing remaining variable
and CLIError to implement this validation.
There was a problem hiding this comment.
No issues found across 3 files
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Add one-off context when rerunning by tagging
@cubic-dev-aiwith guidance or docs links (includingllms.txt) - Ask questions if you need clarification on any suggestion
|
Thank you for the contribution! |
Allow naming a workspace at creation time instead of requiring a separate rename-workspace call afterward. Threads a title parameter through: - CLI: --name <title> flag parsed and sent as "title" in v2 params - V2 handler: extracts title, passes to TabManager.addWorkspace() - TabManager: uses provided title instead of auto-generated "Terminal N" and calls setCustomTitle() to persist it - V1 handler: accepts optional name argument Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Summary
--name <title>flag to thenew-workspaceCLI command to set a custom workspace name on creationtitleparameter through CLI → v2 socket handler →TabManager.addWorkspace()→makeWorkspaceForCreationsetCustomTitle()to persist the user-set name so it isn't overwritten by automatic title updatesTest plan
cmux new-workspace --name "Build Server"creates workspace with custom namecmux new-workspacewithout--namestill uses default "Terminal N" namingcmux new-workspace --name " "(whitespace only) falls back to default namecmux help new-workspaceshows updated usage with--nameflagworkspace.createwithtitleparam sets custom name🤖 Generated with Claude Code
Summary by cubic
Add a
--nameflag to thenew-workspaceCLI so users can set a custom workspace name at creation. The title is passed through v2/v1 handlers toTabManagerand persisted so auto updates don’t overwrite it.cmux new-workspace --name "<title>"sets a custom name; whitespace-only falls back to default.titlevia v2workspace.createtoTabManager.addWorkspace(title:).setCustomTitle(); default remains "Terminal N" if none provided.--name.new_workspacenow accepts an optional name argument.Written for commit 0f03356. Summary will update on new commits.
Summary by CodeRabbit
New Features
--nameflag.Documentation