Skip to content

Optional container2wasm in-browser deployment (PASCLAW_C2W) + browser bundle - #185

Merged
FMXExpress merged 9 commits into
mainfrom
claude/c2w-fetch-proxy
Jun 8, 2026
Merged

FMXExpress merged 9 commits into
mainfrom
claude/c2w-fetch-proxy

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

What & why

Adds an opt-in path to run PasClaw in a browser tab via
container2wasm: the native
pasclaw binary runs inside a WebAssembly Linux emulator, and its outbound
HTTPS rides the browser's own fetch() through c2w's serverless c2w-net-proxy
(no backend/relay). Everything here is gated behind the PASCLAW_C2W compile
symbol — normal builds are byte-identical to before.

Changes

Gated code (off by default):

  • src/pkg/providers/PasClaw.Providers.HTTP.pas — ApplyBrowserProxy() routes
    TIdHTTP through HTTP_PROXY/HTTPS_PROXY (which c2w-net-proxy injects),
    from the single NewClient factory every request flows through. Indy doesn't
    verify server certs by default, so the proxy's TLS-terminating cert is
    accepted with no extra CA wiring.
  • src/pkg/providers/PasClaw.Providers.Anthropic.pas — sends
    anthropic-dangerous-direct-browser-access: true so Anthropic returns the
    CORS headers the in-browser fetch proxy needs.

Build wiring:

  • Makefile — C2W=1 adds -dPASCLAW_C2W; new make browser target.
  • docker/Dockerfile — --build-arg C2W=1 threads the flag into the image build.

Browser bundle (browser/):

  • build.sh — one-shot: builds the C2W=1 image, auto-fetches the c2w CLI,
    runs c2w --to-js + the container2wasm webpack harness + c2w-net-proxy.wasm.gzip,
    and emits a static, manually-deployable browser/site/. Also reachable as make browser.
  • coi-serviceworker.js — supplies the COOP/COEP headers the emulator's
    SharedArrayBuffer requires, so any static host (incl. GitHub Pages) works.
  • README.md — build/deploy steps + the honest constraints.

Docs: docs/c2w.md — design, recipe, and the inherent limits.

Verified

  • Full make and make C2W=1 both build a working pasclaw under FPC 3.2.2
    (zero new warnings from the gated code); make test passes.
  • Proxy routing confirmed behaviourally: a C2W=1 binary with HTTP_PROXY
    set sends its request through the proxy (observed at a local listener); a
    default binary with the same env ignores it and goes direct.
  • docker build --build-arg C2W=1 -t pasclaw:c2w . produces a working image;
    docker run --rm pasclaw:c2w version runs, OpenSSL 1.0.2 bundled.

Not exercised in CI

The c2w --to-js image→wasm conversion and a live in-browser Anthropic call.
The conversion builds c2w's emulator from source (many image pulls + HTTPS
fetches) so it needs a machine with registry access and no TLS-intercepting
proxy — it's a single make browser there. browser/site/ and browser/.bin/
are git-ignored (large/generated).

Inherent constraints (browser, not PasClaw)

Anthropic-only (CORS), bring-your-own API key (client-side), possible response
buffering through the fetch proxy, and Bochs (interpreted) performance. A
file:// double-click can't work — SharedArrayBuffer needs the COOP/COEP
headers, hence the service worker + a static host.

https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6


Generated by Claude Code

claude added 8 commits June 8, 2026 13:58
Running the native pasclaw binary inside a container2wasm guest is the only
way to get a full-featured PasClaw in a browser tab. Its serverless
networking stack (c2w-net-proxy) injects HTTP_PROXY/HTTPS_PROXY, TLS-
terminates HTTPS, and re-issues requests via the browser Fetch API — but
Indy's TIdHTTP doesn't read those env vars, so PasClaw would otherwise try a
direct socket that has no egress in the browser.

Add a PASCLAW_C2W conditional-compilation symbol, off by default, that wires
PasClaw up for that deployment and nothing else:

- Providers.HTTP: ApplyBrowserProxy() parses HTTP_PROXY/HTTPS_PROXY and points
  TIdHTTP.ProxyParams at the proxy, from the single NewClient factory every
  request flows through. No CA wiring needed — Indy doesn't verify server
  certs by default, so the proxy's MITM cert is accepted.
- Providers.Anthropic: send anthropic-dangerous-direct-browser-access: true so
  Anthropic returns the CORS headers the in-browser Fetch proxy requires.

Build with `make C2W=1` (adds -dPASCLAW_C2W). Without it the wire is
byte-identical to before — both branches are excluded by {$IFDEF}. docs/c2w.md
covers the packaging outline and the inherent browser constraints
(CORS-limited to Anthropic, BYO key, possible response buffering, Bochs perf).

Verified: the edited units compile clean under FPC 3.2.2 both with and without
-dPASCLAW_C2W (exit 0, no new warnings). End-to-end browser run not yet
exercised.
Threads C2W through to `make C2W="${C2W}"` in the builder stage so
`docker build --build-arg C2W=1` produces an image whose pasclaw routes
HTTP through the container2wasm c2w-net-proxy Fetch bridge. Default
(unset) builds are unchanged. See docs/c2w.md.
Record the exact docker build --build-arg C2W=1 and c2w conversion
commands, the c2w-net-proxy.wasm browser bridge, and what's verified
(full build + tests + proxy routing + image build) vs still pending
(c2w wasm conversion, live in-browser Anthropic call).
Add browser/ — a manually-deployable static-site path for running pasclaw
in a browser tab via container2wasm, no backend/relay (LLM HTTPS rides the
browser's fetch() through c2w-net-proxy, which the C2W build targets).

- build.sh: mirrors container2wasm's emscripten 'on browser' pipeline
  pointed at the pasclaw image (docker build --build-arg C2W=1 -> c2w
  --to-js -> webpack the example htdocs -> c2w-net-proxy.wasm.gzip ->
  coi-serviceworker). Emits a static browser/site/.
- serve.py: local static server sending the COOP/COEP headers the
  emulator's SharedArrayBuffer requires.
- coi-serviceworker.js: enables cross-origin isolation on header-less
  static hosts (e.g. GitHub Pages).
- README: the 'no server' distinction (no backend vs still-needs-static-
  hosting; file:// can't work), build/deploy steps, and limits.

site/ and *.wasm are git-ignored (large, generated).
build.sh now downloads the pinned c2w CLI into browser/.bin/ (git-ignored)
when it isn't already on PATH, so the only prerequisites are docker +
node/npm + git/curl/gzip. Override with C2W=/path/to/c2w. README updated.
Single top-level command — `make browser` — to produce the static
container2wasm bundle in browser/site/ (builds the C2W=1 image and runs
the c2w --to-js + webpack pipeline in one shot).
Removes the bundled Python server. The included coi-serviceworker.js
supplies the COOP/COEP headers, so any static file server (e.g.
npx http-server) over http://localhost works; updated build.sh hint,
README, and the coi-serviceworker comment accordingly.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c6e52d56ca

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread browser/build.sh Outdated

echo
echo "Done -> $OUT/ (static, manually deployable)"
echo "Local : npx http-server $OUT -p 8080 # or any static server; open http://localhost:8080"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include the browser-networking query in the launch URL

The generated instructions tell users to open the bare static URL, but container2wasm's browser networking mode is only enabled with ?net=browser (the upstream docs list bare localhost:8080 as running without networking). Following this line boots the image without c2w-net-proxy, so the PASCLAW_C2W proxy wiring never gets HTTP_PROXY/HTTPS_PROXY and Anthropic calls fail from the browser even though the bundle includes c2w-net-proxy.wasm.gzip.

Useful? React with 👍 / 👎.

Comment thread browser/build.sh
echo " using c2w: $C2W"

echo "==> 1/6 build the image with browser networking compiled in (C2W=1)"
docker build -f docker/Dockerfile --build-arg C2W=1 -t "$IMAGE" .

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Build the browser image with an interactive command

This always rebuilds the normal Docker image, whose Dockerfile config starts pasclaw gateway --addr 0.0.0.0 --port 8088; container2wasm defaults to the image config when no runtime command is supplied. The resulting xterm page therefore starts the HTTP gateway rather than agent/tui, so users get a terminal attached to a server process instead of the in-browser CLI/TUI described by the new browser docs.

Useful? React with 👍 / 👎.

Addresses the two Codex review notes on #185:

- The c2w image's default command is the gateway SERVER, useless in a
  single-user tab. build.sh now derives a *-browser image with
  CMD [/bin/sh -lc 'pasclaw onboard && exec pasclaw agent'] and feeds THAT
  to c2w: the user is prompted for their provider + API key (BYO key) on
  launch, then drops into the interactive chat agent. docker/Dockerfile's
  default stays gateway for normal use.
- The launch URL must include ?net=browser to activate the in-browser
  fetch() proxy that sets HTTP_PROXY/HTTPS_PROXY in the guest; without it
  the agent has no network egress. Updated build.sh output, README, and
  docs/c2w.md accordingly.
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.

2 participants