Skip to content

feat(server): CORS for local GUI clients#1063

Merged
jayscambler merged 2 commits into
mainfrom
feat/engine-cors
Jun 9, 2026
Merged

feat(server): CORS for local GUI clients#1063
jayscambler merged 2 commits into
mainfrom
feat/engine-cors

Conversation

@jayscambler

Copy link
Copy Markdown
Contributor

Summary

The cowork desktop build (Tauri webview, and browser dev servers) calls the engine's HTTP API cross-origin: GET /api/runs/{id}/candidate, GET/PUT /api/knowledge/{scenario}. Without CORS headers those requests are blocked by the webview, which is the last gap keeping the desktop cockpit from full parity (candidate panel, knowledge editing, documents-to-knowledge).

Adds CORSMiddleware in create_app():

  • Default origins: http://localhost:1420 (desktop vite dev), http://localhost:4173 (vite preview), http://localhost:3000 (web app dev), tauri://localhost (packaged webview).
  • Overridable via AUTOCONTEXT_CORS_ORIGINS (comma-separated).
  • Methods limited to GET/PUT/POST, headers to content-type.
  • Unknown origins get no CORS headers (verified by test).

The engine binds to localhost, so allowing explicit local-app origins does not expose anything new; remote deployments can set the env var.

Tests

tests/test_server_cors.py: allowed GET echoes the origin; PUT preflight from tauri://localhost allows PUT; unknown origin receives no CORS headers; AUTOCONTEXT_CORS_ORIGINS replaces the defaults.

Checks in a clean worktree off main: new tests + server health + knowledge endpoint tests pass (12), ruff clean, mypy clean.

The cowork desktop build (Tauri webview / browser dev servers) calls the
engine's HTTP API cross-origin: candidate, knowledge GET/PUT. The engine
binds to localhost, so allowing explicit local-app origins is safe.

Defaults cover the desktop vite dev server (1420), vite preview (4173),
the web app dev server (3000), and the Tauri webview origin
(tauri://localhost); override the list via AUTOCONTEXT_CORS_ORIGINS.
Methods limited to GET/PUT/POST and headers to content-type. Unknown
origins receive no CORS headers.

Tests cover the allowed GET, the PUT preflight from tauri://localhost,
the unknown-origin case, and the env override.
Add the new env var to the repo-level .env.example (API server section,
with the local-GUI defaults shown) and to the API server section of the
package README, noting that remote or custom GUI deployments set it to
a comma-separated origin list.
@jayscambler

Copy link
Copy Markdown
Contributor Author

Addressed the P3: AUTOCONTEXT_CORS_ORIGINS is now documented in the repo-level .env.example (new API server section showing the local-GUI defaults) and in the API server section of autocontext/README.md, with a note that remote or custom GUI deployments set it to a comma-separated origin list.

@jayscambler jayscambler merged commit a9c5574 into main Jun 9, 2026
17 checks passed
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