Skip to content

Add --name flag to new-workspace CLI command - #2160

Merged
lawrencecchen merged 1 commit into
manaflow-ai:mainfrom
ueg1990:feat/new-workspace-name
Mar 26, 2026
Merged

lawrencecchen merged 1 commit into
manaflow-ai:mainfrom
ueg1990:feat/new-workspace-name

Conversation

@ueg1990

@ueg1990 ueg1990 commented Mar 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds --name <title> flag to the new-workspace CLI command to set a custom workspace name on creation
  • Threads the title parameter through CLI → v2 socket handler → TabManager.addWorkspace() → makeWorkspaceForCreation
  • Uses setCustomTitle() to persist the user-set name so it isn't overwritten by automatic title updates

Test plan

  • cmux new-workspace --name "Build Server" creates workspace with custom name
  • cmux new-workspace without --name still uses default "Terminal N" naming
  • cmux new-workspace --name " " (whitespace only) falls back to default name
  • cmux help new-workspace shows updated usage with --name flag
  • v2 socket workspace.create with title param sets custom name

🤖 Generated with Claude Code


Summary by cubic

Add a --name flag to the new-workspace CLI so users can set a custom workspace name at creation. The title is passed through v2/v1 handlers to TabManager and persisted so auto updates don’t overwrite it.

  • New Features
    • cmux new-workspace --name "<title>" sets a custom name; whitespace-only falls back to default.
    • Threads title via v2 workspace.create to TabManager.addWorkspace(title:).
    • Persists user-set titles with setCustomTitle(); default remains "Terminal N" if none provided.
    • Updates CLI help and unknown-flag error to include --name.
    • v1 new_workspace now accepts an optional name argument.

Written for commit 0f03356. Summary will update on new commits.

Summary by CodeRabbit

  • New Features

    • Users can now specify a custom name when creating a new workspace using the --name flag.
  • Documentation

    • Updated help text and usage information to document the new workspace naming option and example invocations.

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>
@vercel

vercel Bot commented Mar 25, 2026

Copy link
Copy Markdown

@ueg1990 is attempting to deploy a commit to the Manaflow Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Mar 25, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This change adds support for custom workspace naming via a --name flag in the CLI. The flag is parsed and threaded through TerminalController and TabManager to set a custom title on newly created workspaces, with fallback to default naming when not provided.

Changes

Cohort / File(s) Summary
CLI Argument Parsing
CLI/cmux.swift
Added --name flag extraction in the option parser for new-workspace command. Updated help text and known flags error message to document the new --name option.
Workspace Creation & Titling
Sources/TabManager.swift
Extended addWorkspace() method signature with optional title: String? = nil parameter. Conditionally applies custom title via setCustomTitle(title) when provided; otherwise defaults to auto-generated title.
Command Dispatching
Sources/TerminalController.swift
Updated v1 newWorkspace() helper to accept optional args parameter for title. Added v2 request handling to extract and trim params["title"], mapping empty strings to nil, then passing to tabManager.addWorkspace(title:...).

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 A workspace with a name so grand,
No more "Terminal 7" bland!
Through the CLI, the title flows,
From parser down to where it goes—
Custom naming brings delight, 🎉
Each workspace shines just right!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description includes a comprehensive summary and test plan, but is missing key required sections: Testing (how validated), Demo Video, Review Trigger comment block, and completion of the Checklist. Add Testing section documenting validation approach, include Demo Video section (mark N/A if not applicable), copy Review Trigger block, and complete the Checklist items to indicate which steps were performed.
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and clearly summarizes the main change: adding a --name flag to the new-workspace CLI command, which is the primary focus of the entire changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

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

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps

greptile-apps Bot commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a --name <title> flag to the new-workspace CLI command, threading the optional title through the v2 socket handler → TabManager.addWorkspace() → makeWorkspaceForCreation, and then calling setCustomTitle() to mark it as user-defined so automatic title updates don't overwrite it.

  • The CLI flag parsing, error message, usage string, and global help text are all updated consistently in CLI/cmux.swift.
  • The v2 socket path in TerminalController.swift trims and nil-coalesces the title param before forwarding, correctly matching the test plan's whitespace-only fallback requirement.
  • The legacy v1 new_workspace socket handler is also updated to accept the raw args string as a title (with the same trim/nil guard), though this path is not covered by the stated test plan.
  • One minor style issue: newWorkspace.setCustomTitle(title) is called inside if title != nil rather than the idiomatic if let title unwrap, passing a String? to a String?-accepting function — harmless but non-idiomatic.

Confidence Score: 4/5

  • PR is safe to merge; the feature is correctly implemented end-to-end with one minor idiomatic cleanup remaining.
  • All three user paths (custom name, no name, whitespace-only name) are handled correctly. The title is set before and locked via setCustomTitle preventing future auto-overwrite. The only gap is a non-idiomatic if title != nil guard instead of if let — no correctness impact.
  • Sources/TabManager.swift — minor if let cleanup at the setCustomTitle call site.

Important Files Changed

Filename Overview
CLI/cmux.swift Adds --name flag parsing for new-workspace, threads it into params["title"], and updates the error message, usage string, and global help text — all consistent with the existing flag pattern.
Sources/TabManager.swift Adds optional title to addWorkspace, passes it (or the "Terminal N" default) to makeWorkspaceForCreation, then calls setCustomTitle to lock in the user-provided name. Minor style issue: setCustomTitle(title) is called inside if title != nil rather than using if let to unwrap first.
Sources/TerminalController.swift v2 handler correctly trims and nil-coalesces the title param before forwarding to addWorkspace. The legacy v1 newWorkspace helper is updated to accept raw args as a title with the same trim/nil guard, with no apparent regressions.

Sequence Diagram

sequenceDiagram
    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}
Loading

Reviews (1): Last reviewed commit: "Add --name flag to new-workspace CLI com..." | Re-trigger Greptile

Comment thread Sources/TabManager.swift
Comment on lines +1238 to +1240
if title != nil {
newWorkspace.setCustomTitle(title)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 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:

Suggested change
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!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 | 🟠 Major

Localize default title and normalize title at this boundary.

Line 1230 uses a bare user-facing string, and current creation still trusts upstream normalization. Normalizing in TabManager.addWorkspace ensures whitespace-only names reliably fall back to default and avoids carrying a blank/whitespace process title into Workspace initialization.

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 using String(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

📥 Commits

Reviewing files that changed from the base of the PR and between 99ca3c9 and 0f03356.

📒 Files selected for processing (3)
  • CLI/cmux.swift
  • Sources/TabManager.swift
  • Sources/TerminalController.swift

Comment thread CLI/cmux.swift
Comment on lines 1689 to 1691
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>")
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
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.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

@lawrencecchen
lawrencecchen merged commit 66b0260 into manaflow-ai:main Mar 26, 2026
4 of 5 checks passed
@lawrencecchen

Copy link
Copy Markdown
Contributor

Thank you for the contribution!

bn-l pushed a commit to bn-l/cmux that referenced this pull request Apr 3, 2026
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>
@coderabbitai coderabbitai Bot mentioned this pull request Apr 25, 2026
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