Repository navigation
fix(placement): show short branch names for worktrees - #2504
Conversation
ListWorktrees and placement metadata blanked branch and label for every named branch: git reports refs/heads/<name>, and the display path guard drops any value containing "/". Fixes #2420: - The local provider trims refs/heads/ for display; selector matching still compares the raw porcelain ref. - The server keeps a branch only when it is a well-formed git branch name, so "feat/x" survives while paths, "..", backslashes, and drive letters stay blank. A label is relaxed only when it is the branch. - Document the branch and label field semantics in the proto. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Addresses review feedback on #2420: - The worktree picker and confirm view skip the branch suffix when it equals the label, which is now the common case. - Cover ForkSession and the gRPC GetSession placement in the namespaced branch contract test. - Document PlacementMetadata.label in the proto. - TUI fixtures use short branch names, matching what the server sends. Co-Authored-By: Claude Opus 5.5 <[email protected]>
tgrunnagle
left a comment
There was a problem hiding this comment.
Multi-Agent Consensus Review
Agents consulted: security, api-compat, tests, general, comment-hygiene, scope
Consensus Summary
| # | Finding | Consensus | Severity | Action |
|---|---|---|---|---|
| 1 | Proto field comments state values the server doesn't guarantee | 8/10 | LOW | Fix |
| 2 | validBranchName comment claims full check-ref-format --branch parity |
9/10 | LOW | Fix |
| 3 | Branch sanitizer accepts any well-formed ref-shaped string | 8/10 | LOW | Fix |
| 4 | Truncating before validation blanks or misleads long branch names | 8/10 | LOW | Fix |
| 5 | renderConfirm branch suppression has no test |
9/10 | LOW | Fix |
| 6 | Planned contract assertion for a blanked non-branch label is missing | 7/10 | LOW | Fix |
| 7 | Real-git test creates its worktree outside its own TempDir | 7/10 | LOW | Fix |
| 8 | Compatibility notes leave out older-client and rollback effects | 7/10 | INFO | Discuss |
Overall
The PR fixes #2420 by trimming refs/heads/ in the local provider and adding a server-side branch sanitizer that allows / only inside a well-formed git branch name. The label relaxes its path guard only when it is the branch. The layering is right: selector identity still uses the raw porcelain ref, both server paths share one helper, and the tests guard the fix. Reverting displayBranch, either call site, or the label guard each makes a test fail.
Every finding is polish. The proto, seam-type and validator comments promise more than the server enforces: "short branch name", full git parity, a closed set of label values. Today only the local provider's porcelain input makes those claims true. Two test gaps remain: the confirm-view change and the contract-level negative label case. Separately, the compatibility section should add one line: older mecatui builds show the branch twice until upgraded, and a rolled-back server keeps serving stored short names. Both are cosmetic.
Documentation
contracts/proto/mecatl/v1/harness.proto:968-972, 3161-3164: reword, thentask generate.internal/adapter/server/placement.go:942-944, 978-979: narrow the doc comments.
Generated with Claude Code
Addresses #2504 review comments: - LOW contracts/proto/mecatl/v1/harness.proto (4368229963): describe label and branch without promising values the server does not guarantee - LOW internal/adapter/server/placement.go (4368229968): narrow the validBranchName comment to the rules it applies - LOW internal/adapter/server/placement.go (4368229971): document the short-name obligation and test ref- and path-shaped names as accepted - LOW internal/adapter/server/placement.go (4368229974): validate the full branch name before capping its length - LOW internal/adapter/server/placement_public_contract_test.go (4368229980): assert a path-shaped label that is not the branch stays blank through ListWorktrees and ClearSession Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ee dir Addresses #2504 review comments: - LOW cmd/mecatui/ui/worktrees.go (4368229977): assert the confirm view omits the branch line when it equals the label and shows it otherwise - LOW internal/app/worktree_lister_test.go (4368229982): keep the repository and its linked worktree under one test-owned TempDir Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Re #8 (compatibility notes): I added an Upgrade implications line to the PR description's API compatibility section. Until upgraded, an older |
rdimitrov
left a comment
There was a problem hiding this comment.
Reviewed the branch-display fix against #2420, including real-git normalization, selector identity preservation, shared server sanitization, Clear/Fork/GetSession metadata, and TUI deduplication. No substantive correctness or security issues found. Focused server, app, UI, and client regression tests pass locally. Full CI gates are still pending; this approval does not replace them.
Closes #2420
Summary
ListWorktrees,ClearSession/ForkSessionplacement metadata, andSession.placementreturned an emptybranchandlabelfor every worktree on a named branch. The local provider passed the raw porcelain ref (refs/heads/feat) to a display sanitizer whose path-leak guard blanks any value containing/. Clients could only tell worktrees apart by response order andrevision, which is ambiguous when two worktrees share a HEAD (for example, right aftergit worktree add -b). These fields now carry the short branch name (feat,feat/x), and the path-leak guard still applies to everything else.Changes Made
Local placement provider (
internal/app/placement.go)displayBranchhelper trimsrefs/heads/.ListWorktreesandbindWorktreeuse it forLabelandBranch.server.Worktree.Branch, so selector matching and the stale-choice check still compare exact values.Server sanitization (
internal/adapter/server/placement.go,placement_discovery.go)sanitizePlacementBranchapplies the same UTF-8, control/format-rune, and length handling assanitizePlacementDisplay. It allows/only in a name that is well formed under thegit check-ref-format --branchrules. Those rules reject leading or trailing/,//,..,\,:, a component that starts with.,.lock,@{, a leading-, a bare@, and the other forbidden characters. That still blocks absolute paths,..traversal, backslashes, and drive letters.sanitizePlacementLabelrelaxes the guard only when the label equals the branch. Free-form labels from other providers keep the strict guard, so a slash-bearing label that is not the branch is still blanked.canonicalPlacementMetadataandListWorktreesForSessionshare both helpers, so the two paths cannot drift apart. The common text cleaning moved intocleanPlacementText.Contract docs (
harness.protoand regenerated outputs)Worktree.label/branchandPlacementMetadata.label/branch:branchis the short branch name, empty for a detached or unknown HEAD. Only comments changed. The Go, TypeScript, anduser-docs/reference/grpc-schema.mdoutputs were regenerated withtask generate.TUI (
cmd/mecatui/ui/worktrees.go)feat/xworktree now showsfeat/x (abcdef12)instead offeat/x (feat/x). A label that differs from the branch, such asPrimary repository, still shows the branch.Implementation Details
refs/heads/feat. This PR returns the short name instead. Both fields are display-only (PlacementMetadatais "safe display data"), and clients select worktrees by the opaqueselector, never by ref, so the full ref adds nothing. The short name is also whatgit statusand the TUI picker show. Linked worktrees are always onrefs/heads/*or detached, so no other ref namespace needs handling.refs/heads/alone is not enough. Namespaced short names such asfeat/xstill contain/, andsanitizePlacementDisplaywould still blank them. That is why the server needs a branch-specific rule and not just a prefix trim.API compatibility
Follows the wire API compatibility assessment.
.protochange adds comments only.Worktree.branch/labelandPlacementMetadata.branch/labelused to be empty for every named branch. They now carry the short branch name (for examplefeat/x). This restores what the provider already intended. Clients treat these fields as opaque display strings (cmd/mecatui/client/worktrees.go,client/placement.go), and no client can depend on the value being empty, because empty never told a client anything.branch/labelin their storedSession.Placementuntil they are next cleared or forked. No migration is needed, because the values are display-only and are recomputed on each new placement.mecatuishows a namespaced branch twice in the worktree picker and confirm view, once as the label and once as the branch.Testing
Sanitizer unit tests (
canonical_seams_repair_test.go):feat,feat/x,user/a.b-c,release/1.2/hotfix./etc/passwd,../x,a/../b,C:\x,C:foo,a//b,.hidden/x,x.lock,-x,@, anda@{1}.refs/heads/feat/xandsrv/private/x. Providers must supply short names./or.no longer blanks the branch;Public contract test (
placement_public_contract_test.go): a fake provider returns a namespacedfeat/xworktree. The test asserts thatfeat/xcomes throughListWorktrees, theClearSessionplacement,GetSession().placement, and theForkSessionplacement, and that no private path escapes. A second test gives a worktree a path-shaped label that isn't its branch and asserts the label stays blank, while the branch is kept, throughListWorktreesandClearSession.Real-git regression test (
internal/app/worktree_lister_test.go): runsgit worktree add -b feat/xint.TempDir(). It asserts that the two worktrees share a HEAD but can be told apart by shortbranch/label, and that binding the selector givesfeat/xmetadata. This is the scenario from the issue.TUI tests:
branch:line appears only when the branch differs from the label.Local checks:
internal/adapter/server(placement, worktree, discovery),internal/app(worktree, placement),cmd/mecatui/ui, andcmd/mecatui/client.task lintreports one finding, a darwin-only gosec issue inenvironment/microvm/launch_ownership_darwin.gothat already exists onmainand is not touched here.task docspasses (Node 22).task generatewas run with buf 1.73.0, the version CI pins.go run ./cmd/mecademo) shows a tool call, a permission ask and approval, and the result.Race suite:
task test:racehas local failures. The same failures happen on a cleanmaincheckout on the same machine, so they come from the local environment (git and temp-directory behavior) and not from this change. They include:TestReadOnlyMemberRunsGitInWorktreeEndToEndTestSubagentRunsGitInWorktreeEndToEndTestACPUsesHostGovernanceRootAndClosesRejectedBindingTestStartupCompatibilityEmbeddedRejectedTestMecatedCLICompositionValidatesMicroVMDefaultAfterReadinessenvironment/microvmtestCI is the clean race gate for this PR.
Additional Notes
🤖 Generated with Claude Code