Skip to content

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

Open
Jason-Shen2 wants to merge 3 commits 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 3 commits 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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5ffc2d33-805d-4f44-b8ef-f84f9d059571

📥 Commits

Reviewing files that changed from the base of the PR and between b9e0e68 and 6f0465a.

📒 Files selected for processing (1)
  • cmd/wsh/cmd/wshcmd-tab.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/wsh/cmd/wshcmd-tab.go

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 | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The workspace list stdout fix is unrelated to the linked tab-reordering feature. Split the workspace list bug fix into a separate PR or explicitly include it in the linked issue scope.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the new tab list and move commands for scriptable tab management.
Description check ✅ Passed The description matches the changeset and explains the new tab commands and workspace list fix.
Linked Issues check ✅ Passed The PR delivers tab listing and tab reordering with bounds checks and preserves the tab ID set as requested.
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 Outdated
- Initialize entries slice as non-nil to marshal empty workspaces as [] instead of null
- Use MarkFlagRequired for --index flag instead of manual Changed() check
@Jason-Shen2

Copy link
Copy Markdown
Author

Addressed both CodeRabbit review comments in commit b9e0e68:

  1. Nil slice → null JSON: Changed var entries []tabListEntry to var entries []tabListEntry = make([]tabListEntry, 0) so empty workspaces serialize as [] instead of null.
  2. MarkFlagRequired for --index: Replaced the manual cmd.Flags().Changed("index") check with tabMoveCmd.MarkFlagRequired("index") in init() for standard Cobra enforcement.

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

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

112-112: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Fix the ST1023 lint finding.

The explicit type is redundant because make already determines it. Use inferred declaration syntax while preserving the non-nil empty slice behavior.

Proposed fix
-	var entries []tabListEntry = make([]tabListEntry, 0)
+	entries := make([]tabListEntry, 0)
🤖 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 112, Update the entries declaration in the
tab-list construction to use inferred declaration syntax while retaining make’s
tabListEntry element type and non-nil empty slice behavior.

Source: Linters/SAST tools

🤖 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.

Nitpick comments:
In `@cmd/wsh/cmd/wshcmd-tab.go`:
- Line 112: Update the entries declaration in the tab-list construction to use
inferred declaration syntax while retaining make’s tabListEntry element type and
non-nil empty slice behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6efcdc12-e213-4864-b67b-82d6620c0811

📥 Commits

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

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

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