Skip to content

feat: offline web static serve#18510

Closed
DroganC wants to merge 5 commits intoanomalyco:devfrom
DroganC:dev
Closed

feat: offline web static serve#18510
DroganC wants to merge 5 commits intoanomalyco:devfrom
DroganC:dev

Conversation

@DroganC
Copy link

@DroganC DroganC commented Mar 21, 2026

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • [] Documentation

What does this PR do?

Description: opencode web serves the browser UI by proxying to https://app.opencode.ai when no API route matches. On machines without outbound access to that host, the UI never loads.

Changes:

  1. packages/opencode/src/server/server.ts — If packages/app/dist/index.html exists (or OPENCODE_APP_DIST points at a directory that contains it), serve files from that directory with the same SPA fallback as before (unknown paths → index.html). Otherwise keep the existing proxy behavior.
  2. Flag.OPENCODE_APP_DIST in packages/opencode/src/flag/flag.ts — Documents and centralizes the env var used for the absolute path override.
  3. One log line when local dist is used (serving web UI from local dist with root) so operators can confirm the proxy is not in use.
  4. packages/app — Changelog fetch uses /changelog.json (from public/ after build); notification and project avatar use same-origin favicon paths instead of https://opencode.ai/..., so those requests stay on the server.
  5. docs/OFFLINE_WEB.md (English) — How to build packages/app, which env vars matter, and troubleshooting. CONTRIBUTING.md — Short subsection linking to that doc.

Why it works:

The Vite production bundle is static files. Serving them from the same process that hosts the API avoids any dependency on app.opencode.ai for HTML/JS/CSS. The API routes are unchanged and still registered before the catch-all.

How did you verify your code works?

  • bun run build in packages/app so dist/index.html exists.
  • OPENCODE_APP_DIST set to that dist path (or rely on default path from packages/opencode), then bun run --conditions=browser ./src/index.ts web from packages/opencode.
  • Confirmed the browser loads the app from http://127.0.0.1:4096 and the server logs serving web UI from local dist once.
  • With dist removed or renamed, confirmed fallback still proxies (when network allows) so default behavior is preserved.

Screenshots / recordings

Optional: browser showing the app loaded from localhost while offline (no change to core UI layout intended).

Checklist

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

chenlong added 5 commits March 21, 2026 17:24
- Add OPENCODE_APP_DIST and fallback to packages/app/dist when index.html exists
- Fall back to app.opencode.ai proxy when no local build
- Use same-origin changelog and favicon assets in the app
- Document env vars and workflow in docs/OFFLINE_WEB.md
- Ignore offline/ for local models-api.json mirrors

Made-with: Cursor
- Document OPENCODE_APP_DIST in Flag; log once when serving local dist
- Rewrite OFFLINE_WEB.md in English; note issue-first policy for PRs
- Link air-gapped web flow from CONTRIBUTING.md

Made-with: Cursor
Fixes @opencode-ai/app typecheck for dialog-connect-provider and dialog-custom-provider.

Add docs/PR_BODY_offline_web.md as PR description draft for offline web PR.

Made-with: Cursor
@DroganC DroganC requested a review from adamdotdevin as a code owner March 21, 2026 09:40
@github-actions
Copy link
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 21, 2026
@github-actions
Copy link
Contributor

Hey! Your PR title Feat/offline web static serve doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

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

I found several related PRs that address similar offline/local serving functionality:

Potential Duplicates/Related PRs:

  1. PR feat(server): embed web UI assets in binary and serve locally #15721feat(server): embed web UI assets in binary and serve locally

    • Directly related: addresses the same problem of serving web UI locally to avoid external dependency on app.opencode.ai
  2. PR feat: add offline mode to disable non-essential outbound connections #18235feat: add offline mode to disable non-essential outbound connections

    • Related: aims to support offline scenarios by disabling outbound connections
  3. PR feat(server): support OPENCODE_WEB_URL for local frontend serving #17104feat(server): support OPENCODE_WEB_URL for local frontend serving

    • Related: provides configuration for local web UI serving
  4. PR feat: add OPENCODE_APP_URL for custom web app proxy #12446feat: add OPENCODE_APP_URL for custom web app proxy

    • Related: similar proxy configuration feature for web app serving
  5. PR feat(app): embed web ui in binary #12829feat(app): embed web ui in binary

    • Related: addresses embedding the web UI to reduce external dependencies

Why they're related: These PRs all tackle the core issue of serving the web UI from the local server rather than proxying to app.opencode.ai, either through embedding, local path configuration, or offline mode support. PR #15721 appears most directly duplicate as it explicitly mentions embedding assets and serving locally.

@DroganC DroganC changed the title Feat/offline web static serve feat: offline web static serve Mar 21, 2026
@DroganC DroganC closed this Mar 21, 2026
@DroganC DroganC reopened this Mar 21, 2026
@github-actions
Copy link
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Mar 21, 2026
@github-actions github-actions bot closed this Mar 21, 2026
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.

1 participant