Skip to content

feat(wsh): add 'tab list' and 'tab move' commands for scriptable tab management#3426

Open
Jason-Shen2 wants to merge 1 commit into
wavetermdev:mainfrom
Jason-Shen2:feat/wsh-tab-list-move
Open

feat(wsh): add 'tab list' and 'tab move' commands for scriptable tab management#3426
Jason-Shen2 wants to merge 1 commit into
wavetermdev:mainfrom
Jason-Shen2:feat/wsh-tab-list-move

Conversation

@Jason-Shen2

Copy link
Copy Markdown

Summary

This PR adds two new wsh subcommands under wsh tab to make tabs scriptable from the command line, addressing #3425.

New commands

wsh tab list (alias: ls) — lists tabs in the current workspace with their ids, names, and indices.

  • Defaults to the current workspace from WAVETERM_WORKSPACEID, overridable with --workspace <id>
  • Supports --json flag for machine-readable output
  • Example:
    $ wsh tab list
    INDEX  TAB ID                                NAME
    0      550e8400-e29b-41d4-a716-446655440000  Terminal
    1      650e8400-e29b-41d4-a716-446655440001  google.com
    

wsh tab move <tabid> --index <n> — moves a tab to the specified 0-based position within its workspace.

  • Validates that the tab exists in the workspace and that the index is in range
  • Guards against dropping/adding tabs (the set of tab ids is preserved exactly)
  • No-op when the tab is already at the target index
  • Example:
    $ wsh tab move 650e8400-e29b-41d4-a716-446655440001 --index 0
    moved tab 650e8400-... from index 1 to 0
    

Bug fix

  • Fixed a small bug in wsh workspace list where the workspaceId field was being printed to stderr instead of stdout due to a WriteStderr/WriteStdout typo.

Testing

  • Added unit tests for the tab reordering logic (reorderTabIds) covering 8 scenarios: first↔last, left/right moves, adjacent swaps, and two-element arrays
  • All existing tests in cmd/wsh/cmd/ continue to pass
  • go build ./cmd/wsh/... and go vet ./cmd/wsh/... clean
  • gofmt verified

Closes #3425

… stderr bug

- Add 'wsh tab list' command to list tabs with ids and names in current order
- Add 'wsh tab move <tabid> --index N' command to reorder tabs
- Both commands default to WAVETERM_WORKSPACEID, with --workspace override
- Include --json output mode for scripting
- Add unit tests for tab reorder logic (8 test cases covering edge cases)
- Fix bug in 'wsh workspace list' where workspaceId was printed to stderr
  instead of stdout (WriteStderr -> WriteStdout)

Closes wavetermdev#3425
@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds a tab CLI command with list and move subcommands. Listing resolves workspaces, fetches tab details, and supports table or JSON output. Moving validates indexes, reorders tab IDs, and updates workspace ordering through RPC. Tests cover tab movement scenarios. Workspace JSON output now writes workspaceId to stdout.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding scriptable tab list and move commands.
Description check ✅ Passed The description accurately describes the tab commands, bug fix, and testing changes in the PR.
Linked Issues check ✅ Passed The PR implements the requested tab listing and reordering CLI wrappers and preserves tab IDs as required by #3425.
Out of Scope Changes check ✅ Passed The workspace list stdout fix is a small related bug fix and does not introduce unrelated scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
cmd/wsh/cmd/wshcmd-tab.go (1)

56-57: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider using MarkFlagRequired for --index.

The manual cmd.Flags().Changed("index") check works, but tabMoveCmd.MarkFlagRequired("index") in init() would enforce this at the Cobra layer with a standard error message before RunE is called.

Also applies to: 159-161

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/wsh/cmd/wshcmd-tab.go` around lines 56 - 57, Update the tabMoveCmd
initialization to mark the "index" flag required via Cobra's MarkFlagRequired in
init(), and remove the manual cmd.Flags().Changed("index") validation from the
command handler so missing --index is rejected before RunE executes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/wsh/cmd/wshcmd-tab.go`:
- Line 111: Initialize entries in the tab-list construction flow as a non-nil
empty []tabListEntry slice so an empty workspace marshals as [] rather than
null. Preserve the existing append and JSON marshaling behavior for workspaces
containing tabs.

---

Nitpick comments:
In `@cmd/wsh/cmd/wshcmd-tab.go`:
- Around line 56-57: Update the tabMoveCmd initialization to mark the "index"
flag required via Cobra's MarkFlagRequired in init(), and remove the manual
cmd.Flags().Changed("index") validation from the command handler so missing
--index is rejected before RunE executes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2d929a98-9e05-4feb-ab8d-424f55a5060a

📥 Commits

Reviewing files that changed from the base of the PR and between c99022c and 7b5c382.

📒 Files selected for processing (3)
  • cmd/wsh/cmd/wshcmd-tab.go
  • cmd/wsh/cmd/wshcmd-tab_test.go
  • cmd/wsh/cmd/wshcmd-workspace.go

Comment thread cmd/wsh/cmd/wshcmd-tab.go
return err
}

var entries []tabListEntry

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Nil slice marshals to null instead of [] for empty workspaces.

var entries []tabListEntry is nil when the workspace has no tabs. json.MarshalIndent on a nil slice produces null, not [], which will break JSON consumers expecting an array.

🛡️ Proposed fix
-	var entries []tabListEntry
+	entries := make([]tabListEntry, 0, len(ws.TabIds))
 	for i, tabId := range ws.TabIds {
📝 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
var entries []tabListEntry
entries := make([]tabListEntry, 0, len(ws.TabIds))
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/wsh/cmd/wshcmd-tab.go` at line 111, Initialize entries in the tab-list
construction flow as a non-nil empty []tabListEntry slice so an empty workspace
marshals as [] rather than null. Preserve the existing append and JSON
marshaling behavior for workspaces containing tabs.

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.

[Feature]: wsh command to reorder tabs (expose updateworkspacetabids)

1 participant