Skip to content

feat(worktrees): import a single hidden worktree from the visibility dialog - #11275

Closed
5hseok wants to merge 16 commits into
stablyai:mainfrom
5hseok:feat/import-hidden-worktrees
Closed

5hseok wants to merge 16 commits into
stablyai:mainfrom
5hseok:feat/import-hidden-worktrees

Conversation

@5hseok

@5hseok 5hseok commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #11274.

Adds a per-worktree import list to the "Non-Orca worktrees" dialog, so you can pull in one hidden worktree without flipping the whole repo — and so agent scratch worktrees become reachable at all.

shouldShowWorktree already treats a path in importedExternalWorktreePaths as an override that beats the agent-scratch rule; the comment above it says "only an explicit import or selected checkout reveals it". Nothing could write a scratch path there, though. The only writer is the discovery inbox, whose candidates pass through isUserFacingExternalWorktree, which filters agent-scratch out. So a worktree under .claude/worktrees couldn't be opened in Orca short of editing orca-data.json.

That also kept AI Vault's Resume disabled for every session that ran in one of those worktrees, since Resume needs the session cwd to resolve to a known worktree.

The new section sits under the existing toggle and lists every hidden worktree — external, unknown-legacy, agent-scratch — with Import per row and "Import all N" for bulk. Scratch rows carry a badge so an unfamiliar worktree doesn't read as a sidebar bug.

Two things worth flagging for review:

Hide is only offered when the explicit import is the sole reason a worktree shows. A worktree revealed twice over — imported individually and covered by the repo-wide show toggle — would stay on screen after its path is dropped, so the button would silently do nothing. Rather than re-derive that condition, the selector asks shouldShowWorktree with the import list withheld and keeps the row only if the answer is no.

The write is optimistic with a rollback: set the path list, force an authoritative refresh, and if the refresh fails put the old list back and surface the error in the dialog rather than leaving the repo record ahead of the sidebar. Same shape as new-external-worktrees-inbox-actions.ts.

No defaults move. Scratch stays hidden until imported, which is what #9535 asked for. The section is also ownership-agnostic, so entries added to AGENT_SCRATCH_PATH_PREFIXES later need no UI work.

Screenshots

Repo parked on the default hide, with one external worktree and two scratch ones. The scratch worktree at the bottom was imported from this dialog.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test (see note)
  • pnpm build
  • Added or updated high-quality tests that would catch regressions

39,676 passing. One suite fails on my machine for a reason that predates this branch: automation-schedules.test.ts expects 'Sundays at ...' and Intl on a ko-KR host returns '일요일s at ...'. It passes under LANG=en_US.UTF-8. A few others (transcript-watch-liveness, project-view-wrapper-source-context-boundary, windows-port-scan) failed intermittently under full-suite parallelism across runs and pass in isolation. None are in the import graph of anything this PR touches.

27 new unit cases plus one E2E spec:

  • Selectors: which ownerships are offered and which aren't, non-authoritative listings returning nothing rather than a list built from stale metadata, an imported worktree that the show toggle also reveals being dropped from the hide list while an imported scratch one is kept, and path add/remove being idempotent and separator-tolerant.
  • Actions: single and bulk import, hide dropping only the requested path, rollback when the refresh fails, the ambiguous-state message when the rollback write fails too, error without a refresh when the repo update fails, and an empty selection touching nothing.
  • Component: short branch names, the branch line collapsing when a worktree is named after its branch, the badge only on scratch rows, bulk import only above one candidate, pending disabling actions.
  • E2E (tests/e2e/hidden-worktree-import.spec.ts): real git worktrees, one external and one under .claude/worktrees. Neither is in the sidebar with the repo on hide; importing the scratch one puts it there and leaves the external one hidden; Hide takes it back out.

Also exercised by hand against a repo with 7 real scratch worktrees, 4 of which were unreachable before this.

AI Review Report

Reviewed with an AI coding agent.

  • Cross-platform: no new path building or platform branching. Comparison reuses normalizeRuntimePathForComparison through the existing inbox helpers, which already cover Windows drive-letter casing, separator folding and WSL UNC aliases. The scratch matcher is untouched, and its anchoring to a registered checkout means nothing here assumes a POSIX-shaped path. No new shortcuts or shortcut labels.
  • SSH and remote: importedExternalWorktreePaths is already accepted by the runtime repo-update schema, so the action works unchanged on SSH and runtime hosts. Selectors require authoritative === true, so a disconnected SSH repo falling back to metadata-fallback shows no list rather than a stale one. The dialog is gated on isGitRepoKind, so folder workspaces are unaffected.
  • Compatibility: classification, the prefix table and shouldShowWorktree's ordering are all unchanged — this only feeds a branch that already existed. The inbox and ImportedWorktreesVisibilityLine behave identically; their selectors are untouched and their tests pass.
  • UI: aria-label and aria-busy on the section, truncation with the full path in a tooltip, disabled buttons while pending, role="alert" on the error. All nine new strings go through translate(), with ko / ja / es / zh translated rather than left as English.

What came out of the review: useAppStore.getState() calls inside the action callback were swapped for the already-subscribed selectors, and the E2E capture caught rows printing the worktree name and its branch as two identical lines, since a worktree with no Orca metadata takes its display name from the branch — the branch line now collapses when they match.

The bot reviews on this PR then caught a real one, and it was mine: the hide list checked only whether a path sat in importedExternalWorktreePaths, never whether the repo-wide toggle was also revealing the worktree, so hide could still be a no-op for the compound case. The test I had written for it passed only because its import list was empty. The selector now defers to shouldShowWorktree, and the replacement test fails against the old predicate. Four smaller ones came from the same pass: a rollback whose own write failed reported a plain retry, the dialog's action state wasn't keyed by project, the E2E spec deleted its fixture before Electron shut down and built data-worktree-id selectors without escaping, and the zh strings didn't use the catalog's own terms for worktree and agent.

Security Audit

No filesystem access, no path construction, no shell interpolation, no command execution — the change compares paths and writes a string array.

Every path comes from git worktree list output that Orca scanned and classified itself, not from user input. It goes through the existing updateRepo, which already validates importedExternalWorktreePaths as an array of strings before persisting, and through the runtime schema for SSH hosts. Importing a path only affects sidebar visibility; it can't make Orca show a path git worktree list didn't report, because the selectors work off the detected list, so a stale entry in the record simply never matches a row.

No new IPC channels, dependencies, secrets, auth or network paths.

Notes

  • The repo-wide card above the new section still counts only non-scratch worktrees ("1 worktree available to import" in the screenshot while three rows are listed). That's existing behaviour and accurate for what the toggle governs, but it reads oddly next to the list. Happy to reword it if you'd rather.
  • importedExternalWorktreePaths accumulates entries for worktrees that no longer exist. Harmless — nothing matches them — but the list only grows. Pruning has to tell "deleted" apart from "not in this scan", so it's a separate change.
  • A per-repo setting for extra scratch prefixes, for agent CLIs that write elsewhere, would compose with this rather than conflict. Not in scope here.

ELI5

Orca hides worktrees agents create inside your repo, and there was no button to un-hide one even though the code was written to allow it. The project's worktree dialog now lists them so you can bring in just the ones you want.

5hseok added 2 commits July 29, 2026 12:27
…dialog

shouldShowWorktree reveals any path listed in importedExternalWorktreePaths,
including agent-scratch ones, but no surface could add a path there: the
discovery inbox is the only writer and its candidate selector drops
agent-scratch. Worktrees under .claude/worktrees were therefore unreachable,
and non-Orca worktrees only had the repo-wide show/hide toggle.

Add a per-worktree import list to the Non-Orca worktrees dialog covering every
hidden ownership, plus a hide action for worktrees an individual import
revealed. Worktrees the repo-wide toggle reveals are excluded from that action,
since dropping their path would not hide them.
Drive the real round trip a unit test cannot reach: git worktrees on disk, one
external and one under .claude/worktrees, classified by the main process and
imported through the dialog.

Capturing that flow also surfaced rows printing the worktree name and its branch
as two identical lines. A worktree with no Orca metadata takes its display name
from the branch, so collapse the branch line when the two match.
Comment thread src/shared/hidden-worktree-import.ts Resolved
@greptile-apps

greptile-apps Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR adds per-worktree import functionality to the "Non-Orca worktrees" visibility dialog, allowing users to reveal individual agent-scratch worktrees (which the repo-wide show toggle deliberately never reveals) without affecting other hidden worktrees. It also introduces a targeted-refresh optimization in the runtime project scheduler so that a reposChanged event for a single repo triggers only that repo's worktree scan rather than a full-environment refresh.

  • HiddenWorktreeImportSection (new component) lists importable and individually-imported worktrees with Import/Hide per row and a bulk "Import all N" button; scratch rows carry a badge to distinguish them from external ones.
  • hidden-worktree-import-actions.ts (new file) implements the optimistic write → authoritative refresh → rollback pattern for import and hide, keyed by project so one dialog instance doesn't bleed state into another.
  • Scheduler (runtime-project-refresh-scheduler.ts) now coalesces targeted repoId events into a Set<string> and propagates a repoIds argument to refreshRuntimeProjectWorktrees, which filters the repo list before fanning out concurrent fetchWorktrees calls; suppressLineageRefresh skips the per-call lineage refresh for scheduler-driven targeted passes, with the full-environment lineage refresh preserved for untargeted (null repoIds) passes.

Confidence Score: 5/5

Safe to merge. All changed code paths have unit and E2E test coverage, and the two issues raised in prior review rounds are demonstrably addressed by the new logic.

The hide-is-a-no-op compound case is now handled correctly: getIndividuallyImportedWorktrees calls shouldShowWorktree with the import list withheld so that a worktree the repo-wide toggle would reveal regardless is excluded from the hide candidates — and the replacement test fails against the old predicate. The rollback failure path now returns a distinct ambiguous-state message rather than the same retry prompt, and both branches are covered by tests. The scheduler coalescing is correct: the refreshAll/pendingRepoIds state machine resets per batch and a targeted request cannot narrow an already-queued full refresh. The runtimeWorktreeRepoHostKey refactoring adds a backwards-compatible comparisonPlatformByRepoId map for legacy IDs and is validated by the new colliding-repo-id test in orca-runtime.test.ts.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/shared/hidden-worktree-import.ts New module implementing importable/imported worktree selectors and path list helpers; getIndividuallyImportedWorktrees correctly withholds the import list when calling shouldShowWorktree to catch the compound toggle+import case.
src/renderer/src/components/sidebar/hidden-worktree-import-actions.ts Optimistic import/hide action with rollback; correctly distinguishes ambiguous-state from plain retry when the rollback write itself fails (hiddenWorktreeRollbackError path).
src/renderer/src/components/sidebar/HiddenWorktreeImportSection.tsx New UI component listing importable and individually-imported worktrees; correctly defers the pending spinner by 200 ms to avoid flicker on fast local imports.
src/renderer/src/components/sidebar/WorktreeVisibilityDialog.tsx Extended with HiddenWorktreeImportSection; action state is keyed by repoHostIdentity and guarded by a generation counter so cross-project interleaving is safe.
src/renderer/src/hooks/runtime-project-refresh-scheduler.ts Adds per-repoId targeted refresh coalescing; refreshAll/pendingRepoIds state machine correctly resets on each new pending batch and prevents a targeted request from narrowing an already-queued full refresh.
src/main/runtime/orca-runtime.ts Refactors platformByRepoId to platformByRepoHostKey to disambiguate runtime repos sharing an ID on different hosts; adds buildRuntimeWorktreeVisibilityContexts to batch visibility context construction and removes per-worktree store lookups at ps-poll time.
src/renderer/src/store/slices/worktrees.ts Added suppressLineageRefresh option to fetchWorktrees; correctly skips the remote lineage round-trip for scheduler-driven targeted per-repo refreshes while preserving it for full and action-driven refreshes.
tests/e2e/hidden-worktree-import.spec.ts New E2E spec covering the full import/hide round trip with real git worktrees; correctly defers fixture cleanup to post-Electron-shutdown to avoid EPERM on Windows.
src/shared/external-worktree-inbox.ts Adds createExplicitExternalWorktreePathMatcher for O(1) per-worktree lookups instead of scanning the imported paths array each time; normalizes on construction.
src/shared/worktree-ownership.ts shouldShowWorktree and toDetectedWorktree now accept an optional pre-built path matcher to avoid rebuilding the Set on every call; falls back to the existing per-path helper when matcher is absent.

Reviews (4): Last reviewed commit: "fix(runtime): keep mobile worktree metad..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds hidden worktree selection, persistence actions, host-aware visibility, targeted runtime refreshes, localized sidebar controls, and visibility-dialog integration. Adds shared, component, action, runtime, and end-to-end tests for these flows.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR includes unrelated formatting-only changes in configuration, test, GitHub UI, and relay-watcher files. Revert or separate the formatting-only edits in .oxlintrc.json, relay-watcher-fault-harness.mjs, GitHubMarkdownComposerEditorPane.tsx, and the unrelated E2E setup file.
Docstring Coverage ⚠️ Warning Docstring coverage is 10.26% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the primary user-visible change: importing one hidden worktree from the visibility dialog.
Description check ✅ Passed The description includes all required sections and provides detailed scope, testing results, AI review, security, and platform notes.
Linked Issues check ✅ Passed The implementation satisfies issue #11274 by adding per-worktree import and hide controls while preserving hidden-by-default scratch worktrees.

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

🧹 Nitpick comments (1)
src/renderer/src/components/sidebar/hidden-worktree-import-actions.ts (1)

42-66: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Guard against rejection paths in applyImportedPaths.

updateRepo and fetchWorktrees currently handle API failures and return false, so this path is defensive: add a try/catch around the await chain and clear pending with an error/retry state if a caller passes a rejecting dependency.

Source: Learnings


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 287b6180-1a6a-4862-8965-5c1b66c4da0a

📥 Commits

Reviewing files that changed from the base of the PR and between adc10cd and 4edbd37.

📒 Files selected for processing (13)
  • src/renderer/src/components/sidebar/HiddenWorktreeImportSection.test.tsx
  • src/renderer/src/components/sidebar/HiddenWorktreeImportSection.tsx
  • src/renderer/src/components/sidebar/WorktreeVisibilityDialog.tsx
  • src/renderer/src/components/sidebar/hidden-worktree-import-actions.test.ts
  • src/renderer/src/components/sidebar/hidden-worktree-import-actions.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/shared/hidden-worktree-import.test.ts
  • src/shared/hidden-worktree-import.ts
  • tests/e2e/hidden-worktree-import.spec.ts

Comment thread src/renderer/src/i18n/locales/zh.json Resolved
…ason a worktree shows

Review caught the hide action doing nothing when a worktree is revealed twice
over: individually imported and also covered by the repo-wide show toggle.
Dropping its path leaves it on screen. Ask shouldShowWorktree with the import
list withheld instead of re-deriving the condition, so the judgement stays on
the rule that owns it. The previous test passed only because its import list was
empty; the replacement fails against the old predicate.

Also from review:
- surface a distinct error when a failed refresh cannot be rolled back, rather
  than reporting a plain retry against a record that moved
- key the dialog's action state by project, so a pending or failed action does
  not bleed into the next project opened
- register the E2E fixture for post-Electron cleanup, take worktree rows through
  the escaping locator helper, and assert that show leaves scratch hidden
- use the zh catalog's own terms for worktree and agent

@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)
tests/e2e/hidden-worktree-import.spec.ts (1)

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

Cover individual import of the external candidate.

This test verifies that the external worktree is affected by the repo-wide toggle, but only exercises the individual Import/Hide flow for the scratch worktree. Add an assertion that importing the external candidate makes it visible and that its individual Hide action works.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5c0e03f7-236a-4f61-bf2e-f4186b6e85c2

📥 Commits

Reviewing files that changed from the base of the PR and between 4edbd37 and 18d9f7a.

📒 Files selected for processing (11)
  • src/renderer/src/components/sidebar/WorktreeVisibilityDialog.tsx
  • src/renderer/src/components/sidebar/hidden-worktree-import-actions.test.ts
  • src/renderer/src/components/sidebar/hidden-worktree-import-actions.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/shared/hidden-worktree-import.test.ts
  • src/shared/hidden-worktree-import.ts
  • tests/e2e/hidden-worktree-import.spec.ts
🚧 Files skipped from review as they are similar to previous changes (9)
  • src/renderer/src/components/sidebar/hidden-worktree-import-actions.test.ts
  • src/renderer/src/components/sidebar/hidden-worktree-import-actions.ts
  • src/renderer/src/i18n/locales/es.json
  • src/shared/hidden-worktree-import.test.ts
  • src/shared/hidden-worktree-import.ts
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/components/sidebar/WorktreeVisibilityDialog.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/ko.json

Conflicts were limited to the localization catalogs, which are generated: take
upstream's five files, regenerate the keys this branch adds with
sync:localization-catalog, and reapply the ko/ja/es/zh translations.

The non-English catalogs no longer need full parity with en.json upstream, so the
regenerated keys are added directly rather than mirrored by the fixer.
The locale catalogs conflicted again, so take main's en.json and regenerate the
keys this branch adds; the ko/ja/es/zh translations survived the auto-merge.

One conflict git could not see. main added a resolveKnownWorkspaceFileTarget
call to isRuntimeWorktreeVisible using the old single-argument signature, while
this branch had changed that method to take the repo explicitly so a repo id
shared across hosts resolves correctly. The text merged; the types did not.
Resolved the way the branch's other two call sites already do — build the
visibility contexts and look the worktree up by repo/host key — rather than
falling back to getRepo(worktree.repoId), which would reintroduce the ambiguity.
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4f3a2bf3-60b0-4fda-8514-d484b77257bf

📥 Commits

Reviewing files that changed from the base of the PR and between e68831f and ddc995c.

📒 Files selected for processing (30)
  • .oxlintrc.json
  • config/scripts/relay-watcher-fault-harness.mjs
  • src/main/ipc/worktrees.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/renderer/src/components/github/GitHubMarkdownComposerEditorPane.tsx
  • src/renderer/src/components/sidebar/HiddenWorktreeImportSection.test.tsx
  • src/renderer/src/components/sidebar/HiddenWorktreeImportSection.tsx
  • src/renderer/src/components/sidebar/WorktreeList.tsx
  • src/renderer/src/components/sidebar/WorktreeVisibilityDialog.test.tsx
  • src/renderer/src/components/sidebar/WorktreeVisibilityDialog.tsx
  • src/renderer/src/components/sidebar/hidden-worktree-import-actions.test.ts
  • src/renderer/src/components/sidebar/hidden-worktree-import-actions.ts
  • src/renderer/src/hooks/runtime-project-refresh-scheduler.test.ts
  • src/renderer/src/hooks/runtime-project-refresh-scheduler.ts
  • src/renderer/src/hooks/useIpcEvents.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/store/slices/worktree-helpers.ts
  • src/renderer/src/store/slices/worktrees.ts
  • src/shared/external-worktree-inbox.ts
  • src/shared/hidden-worktree-import.test.ts
  • src/shared/hidden-worktree-import.ts
  • src/shared/runtime-client-events.ts
  • src/shared/worktree-ownership.ts
  • tests/e2e/hidden-worktree-import.spec.ts
  • tests/e2e/setup-script-prompt-unreadable-orca-yaml.spec.ts
🚧 Files skipped from review as they are similar to previous changes (10)
  • src/renderer/src/components/sidebar/hidden-worktree-import-actions.test.ts
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/components/sidebar/HiddenWorktreeImportSection.test.tsx
  • src/shared/hidden-worktree-import.test.ts
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/components/sidebar/hidden-worktree-import-actions.ts
  • src/renderer/src/i18n/locales/zh.json
  • src/shared/hidden-worktree-import.ts

Comment on lines +6748 to +6751
const repo = findRepoForHost(repos, projectId, { settings })
if (repo) {
handleOpenWorktreeVisibility(repo)
}

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 | 🟠 Major | 🏗️ Heavy lift

Preserve the originating host for visibility recovery.

Line 6748 resolves projectId with the currently focused host. If the recovery started from the same repository ID on another host, this opens the visibility dialog for the wrong repository. Store the originating hostId with suppressExternalWorktreeInboxRepoId and pass it to findRepoForHost or directly to handleOpenWorktreeVisibility.

@brennanb2025

Copy link
Copy Markdown
Contributor

Thanks for this work — per-worktree recovery from the visibility dialog landed in #13652, so this PR is now superseded.

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]: Import a single hidden worktree instead of showing every non-Orca one

2 participants