anomalyco / anomalyco/opencode

tui: @ directory completion yields double slash; /cd select never submits exact path

Open Beginner friendly
#50,132 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Summary

Two related directory-completion problems in the TUI prompt: (1) the @ file reference autocomplete produces a double slash (@dir//) when expanding a directory, breaking further drill-down; (2) in /cd directory argument completion, prompt.autocomplete.select only re-inserts the already-exact path and closes the popup without submitting, leaving the command unexecuted.

Environment

  • opencode version: 2.0.8
  • OS: Darwin 27.2.0 (darwin arm64)
  • Terminal: TERM_PROGRAM=WezTerm, TERM=xterm-256color, COLORTERM=truecolor
  • Shell: /bin/zsh
  • Install/channel: latest
  • Active plugins: @prevalentware/opencode-goal-plugin, billion-context@0.1.118-pr.936.774

Reproduction

Both reproduced in a real terminal (tmux-captured pty) with the TUI running v2.0.8.

Bug 1: @ directory expansion yields @dir//
  1. In a project containing a directory sub1/, type @sub1 in the prompt.
  2. Select the directory entry and press the prompt.autocomplete.complete key (Enter in my keymap; Tab by default).
  3. The input becomes @sub1// and the popup switches to "No matching files" — drill-down into the directory is broken.

Root cause (v2.0.8 source): packages/tui/src/component/prompt/autocomplete.tsx, expandDirectory() — the @ branch runs input.insertText("@" + selectedPath + "/") unconditionally, while the server fs.find already returns directory paths with a trailing slash (sub1/). The adjacent directory-mode branch (/cd, same function) guards with selectedPath.endsWith(path.sep) ? selectedPath : selectedPath + path.sep; the @ branch lacks this guard. Git history: at commit 106f8e94 the line was insertText("@" + path) (correct, since dir paths carry a trailing slash); a later commit added the extra + "/".

Bug 2: /cd select never submits, even on an exact path

Keymap: prompt.autocomplete.complete: return, prompt.autocomplete.select: shift+return.

  1. Type a complete, valid directory argument: /cd ~/.config/opencode/scripts/
  2. The popup shows that exact directory as the first (exact-match) entry plus its children.
  3. Press prompt.autocomplete.select (Shift+Enter). The popup closes and nothing happens — the working directory is unchanged; the text just sits in the input.
  4. Only a second Enter (with the popup now hidden) submits the command.

Root cause: in the same file, select()'s directory branch only calls selected.onSelect?.() (which is insertDirectory(value)) and hide(true) — there is no submission path. When the typed argument is already an exact, valid directory, select re-inserts identical text and does nothing, which reads as "the key didn't work".

A related UX papercut that compounds this: the /cd popup lists only the current directory itself and its children — no parent or sibling entries — so after drilling down, pressing complete on the first (exact/self) entry is a no-op and the picker appears "stuck". To reach a sibling directory the user must know to type ...

Expected Behavior

  1. @ directory expansion should not duplicate the trailing slash: @sub1/ and drill-down should continue to work.
  2. When the /cd argument is already an exact valid directory, select should submit the command (or an explicit binding should exist that does), rather than re-inserting identical text.

Actual Behavior

  1. @sub1// — double slash, autocomplete breaks.
  2. Working directory unchanged after select; a second Enter with the popup dismissed is required.

Additional Context

  • Reproducibility: both 100% consistent.
  • Bug 1 was verified against the v2.0.8 tagged source and via git history (correct at 106f8e94, broken after a later change to expandDirectory).
  • Bug 2 verified by pty reproduction: after Shift+Enter the status-bar cwd is unchanged; after a following Enter it switches.
  • Suggested fix for bug 1: apply the same endsWith(path.sep) guard in the @ branch of expandDirectory().
  • Suggested fix for bug 2: in select()'s directory branch, submit when the option is the exact match for the current query (or document/select a "submit" affordance for argument popups).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in packages/tui/src/component/prompt/autocomplete.tsx and read expandDirectory() and select() for the @ and /cd directory branches. Reproduce both flows in the TUI, then verify that directory expansion preserves one trailing slash and that selecting an exact /cd directory submits the command instead of only reinserting the path.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.