Skip to content

fix(app): auto-register server working directory as a project - #41138

Open
cshintov wants to merge 4 commits into
anomalyco:devfrom
cshintov:server-cwd-project
Open

cshintov wants to merge 4 commits into
anomalyco:devfrom
cshintov:server-cwd-project

Conversation

@cshintov

@cshintov cshintov commented Aug 7, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #37096

Related: #39655 (the empty sidebar part; a server started in the home dir is
intentionally not adopted, and the empty "Open Project" picker is #39434).

Type of change

  • Bug fix

What does this PR do?

A fresh opencode web/serve started in a folder showed an empty UI (no
projects in the sidebar, "Nothing here yet") even though the backend returns
projects and sessions. The web sidebar and session list are driven by the
app's local open-projects store (keyed on worktree), not the server /project
table, so until the user manually typed the folder path into the (empty)
picker, nothing appeared.

This adopts the server's working directory as an open project on connect
(once sync.data.path.directory is known), via a new
createServerProjects.adopt. Adoption is deliberately narrow:

  • only when this server has no open projects, so an existing list is never
    reordered or added to;
  • never for a directory the user closed, so closing it keeps it closed;
  • never for the user's home dir or a filesystem root (/, C:\), which the
    file finder cannot index and would otherwise appear empty;
  • never for desktop sidecar servers, which the app starts itself rather than
    from a project folder;
  • scoped per server.

The first two guards follow #38992 (closed by the cleanup bot), which fixed the
same symptom in the same place.

How did you verify your code works?

  • Ran the app and backend dev servers locally (bun), started the server in a
    clean scratch folder, and loaded the UI in a fresh browser context (no
    persisted state): the launch folder appeared as a project with a new session.
  • Headless browser against a dev server started in a scratch folder, each case
    in a fresh profile and checked again after reload: empty storage adopts the
    folder; a recently closed folder stays closed; an existing project list is
    left untouched; closing the last open project mid-session does not re-adopt
    the folder.
  • Unit tests in server.test.ts for adopt (empty list, existing list,
    closed folder, per-server scope) and adoptable (home, /, C:\, empty):
    17 pass. bun run test:unit in packages/app: 728 pass, 1 fail
    (i18n/desktop-native.test.ts, fails identically on dev).
  • bun typecheck in packages/app passes.

Screenshots / recordings

Before: empty sidebar, "Nothing here yet"; after: the server's working
directory (ocdemo) shown as a project with a session. (I can attach the PNG
to the issue if needed.)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Aug 7, 2026
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate Found

PR #38992: fix(app): adopt the server directory when no project is open
#38992

Why it's related: This PR addresses the same problem — handling the server's working directory when no project is currently open. Both PRs appear to be tackling the empty sidebar issue in fresh opencode web sessions and the need to automatically register the server's working directory as a project. You should check if #38992 is already merged or if this PR supersedes it with a different implementation approach.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Aug 7, 2026
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@ZipiDan

ZipiDan commented Sep 1, 2026

Copy link
Copy Markdown

Thanks for this fix — it solves the empty web UI and is needed, but it only fixes the frontend.

Please also consider reopening the two closed PRs that fix the deeper server issue:

  • fix(opencode): add --dir option to web/serve; use directory as worktree #35976 fix: add --dir option to web/serve; use directory as worktree (closed by automated-pr-cleanup 9 Aug) — makes web/serve respect the directory where you ran the command, just like TUI already does with opencode [project] / CWD. Without it the server starts with worktree:/ instead of the actual project (e.g. /workspace with podman run --workdir /workspace -v $PROJECT:/workspace:Z), so GET /project returns only global, skills in .opencode/skills/ are not found, and new sessions get cwd=/.
  • fix(app): adopt the server directory when no project is open #38992 fix: adopt the server directory when no project is open (closed 26 Aug, predecessor of this PR) — same localStorage seeding as this PR.

The text interface already follows this policy — opencode (TUI) correctly uses the current directory/project — and it would be consistent for the web interface to follow the same policy.

Container repro:

  • podman --workdir /workspace + opencode web --hostname 0.0.0.0 --port 4070 -> TUI starts in /workspace (correct), web shows empty ("No projects") and picker at / -> must manually add /workspace. http://localhost:4070 vs http://127.0.0.1:4070 are different browser storages, so it repeats. Log shows creating instance directory=/workspace but GET /project=[{"id":"global","worktree":"/"}].

This PR #41138 makes the browser show the server's folder without manual steps (great), but the server is still on / without #35976. For a full fix we need both: server (#35976) + app (#41138). Could you reopen #35976 and #38992? Happy to test together. Thanks!

@barbershopify

Copy link
Copy Markdown

Somebody please merge this in, the web UI is presently useless for anyone who doesn't put their projects directly in their user home directory.

@cshintov

Copy link
Copy Markdown
Author

sorry for missing the review. Will get on it now.

cshintov and others added 2 commits September 25, 2026 22:49
On connecting to a server, open its working directory as a project so
that a fresh `opencode web`/`serve` started in a folder surfaces that
folder and its sessions in the UI, instead of an empty "Add project"
screen.

The web nav and session list are driven by the app's local open-projects
store (keyed on worktree), not the server `/project` table. Previously
nothing appeared until the user manually typed the folder path into the
picker — a common first-run confusion that recurs across anomalyco#39655, anomalyco#39040,
anomalyco#27837 and others.

Skip the user's home directory and the filesystem root, which the file
finder cannot index and would otherwise render as empty projects.

Fixes anomalyco#39655
Opening the server directory on every connect re-opened it after the user
closed it and pushed it to the top of an existing list. Move the logic into
createServerProjects.adopt, which skips non-empty lists and recently closed
directories. Guards follow anomalyco#38992.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@cshintov

Copy link
Copy Markdown
Author

@ZipiDan thanks for testing this and for the Podman repro. I looked at both closed PRs before deciding what to do here:

Also, contributors can't reopen PRs someone else closed. That's up to the maintainers or the original authors.

@Hona @Brendonovich (CODEOWNERS for packages/app): could one of you take a look when you have a moment? It's a small change (3 files in packages/app/src/context, with tests) and it fixes the empty web UI on a fresh opencode web/serve (#37096, and the sidebar part of #39655).

cshintov and others added 2 commits September 25, 2026 23:45
…ver directory

pathKey keeps "C:/" for a drive root, so the "/" check let it through. Desktop
sidecars are started by the app rather than from a project folder, so their cwd
is never a project. Move the path check into adoptable() so it is unit tested.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
adopt() reads the project list, so the effect re-ran whenever it changed and
re-adopted the server directory when the user closed their last project.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

Web UI Session List Empty — Project Auto-Registration Fails on Windows/WSL

3 participants