Skip to content

app: directory suggestions strip trailing spaces and can select a different folder #60294

In review

Description

@HeZ2z

Description

The web directory picker strips trailing whitespace from an already resolved directory path when navigating through a search suggestion or a recent project. On Unix, foo and foo are distinct valid directory names. Selecting the latter via these paths can therefore navigate to the former, or fail if only foo exists. Tree selection itself preserves the space.

Reproduction

On dev commit 82666b6612cdb2ba13a7a26e150b21e897a80373, from packages/app, run the actual path functions used by the picker:

bun -e 'import {cleanPickerInput,pickerAbsoluteInput,pickerMode} from "./src/workspaces/selection/domain.ts"; const root="/tmp/example"; const target=root+"/foo "; console.log("tree selection", JSON.stringify(pickerMode("directory").selection(root,"foo /"))); console.log("suggestion navigation", JSON.stringify(pickerAbsoluteInput(cleanPickerInput(target),"/tmp",root)));'

Actual output:

tree selection "/tmp/example/foo "
suggestion navigation "/tmp/example/foo"

Expected: the resolved directory path retains its final space in both cases. chooseSuggestion passes suggestion.absolute to selectDirectory, which unconditionally applies cleanPickerInput (and .trim()) before navigation. Recent-project selection uses the same function. This reproduction exercises the actual path functions and the production call chain; it was not verified through a browser UI.

Both affected source files match the current upstream dev blobs. This is separate from the old #8937 report about a startup hang.

Activity

  1. opencodejr commented on Oct 29, 2026

    @opencodejr
    Contributor

    Thanks for the precise report. I reproduced this on the latest dev (d3ad3da).

    With a directory named foo (trailing space, and no plain foo):

    • Tree selection resolves to /…/foo (correct).
    • The suggestion and recent-project path in selectDirectory/navigate runs the resolved absolute path through cleanPickerInput, whose .trim() turns it into /…/foo. That directory doesn't exist, or it can be a different folder.

    The script below reproduces it against a real directory on disk. It calls the same picker functions; I didn't drive the browser UI.

    Reproduction script (repro.ts)
    // Run from packages/app of an OpenCode checkout: bun /workspace/repro/repro.ts
    // Shows that the directory picker's suggestion/recent-project path (selectDirectory/navigate
    // in src/workspaces/selection/dialog.tsx) trims a trailing space from an already-resolved
    // absolute path, while tree selection keeps it.
    import { mkdirSync, rmSync, existsSync } from "node:fs"
    import { resolve } from "node:path"
    const repo = process.env.OC_DEV ?? "/workspace/repo"
    const { cleanPickerInput, pickerAbsoluteInput, pickerMode } = await import(
      resolve(repo, "packages/app/src/workspaces/selection/domain.ts")
    )
    
    const root = "/tmp/opencode/picker-example"
    rmSync(root, { recursive: true, force: true })
    mkdirSync(root + "/foo ", { recursive: true }) // only "foo " (trailing space) exists
    
    const target = root + "/foo "
    const tree = pickerMode("directory").selection(root, "foo /")
    // what selectDirectory(suggestion.absolute) / navigate(recentProject) compute:
    const suggestion = pickerMode("directory").navigation(pickerAbsoluteInput(cleanPickerInput(target), "/tmp", root))
    
    console.log("target              ", JSON.stringify(target), "exists:", existsSync(target))
    console.log("tree selection      ", JSON.stringify(tree), "exists:", existsSync(tree))
    console.log("suggestion/recent   ", JSON.stringify(suggestion), "exists:", existsSync(suggestion))
    if (suggestion !== target) {
      console.log("BUG: suggestion navigation resolved to a different (here non-existent) directory")
      process.exit(1)
    }
    console.log("OK")

    Run it: bun repro.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions