Skip to content

Spec 16 web frontend and deploy leg#98

Merged
Just-Insane merged 39 commits into
mainfrom
fix/spec16-web-frontend-deploy
Jul 9, 2026
Merged

Spec 16 web frontend and deploy leg#98
Just-Insane merged 39 commits into
mainfrom
fix/spec16-web-frontend-deploy

Conversation

@Just-Insane

Copy link
Copy Markdown
Contributor

Description

Adds the remaining Spec 16 web frontend/deploy leg on top of the companion web server work from #55.

This PR adds a browser transport for Matrix calls, routes web builds through HTTP and WebSocket endpoints instead of Tauri IPC, supports browser File uploads for chat and avatar flows, and makes media/avatar URLs load correctly in both Tauri and web builds. It also adds a build:web script, web env typing, /api/auth/me device restore support, and a Cloudflare Pages preview workflow that skips cleanly when preview deploy secrets are not configured.

Related to #55

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • pnpm lint, pnpm fmt:check, pnpm typecheck, pnpm test:coverage, pnpm knip, and pnpm build all pass locally

Additional validation:

  • pnpm build:web
  • cargo test -p charm-web-server --lib
  • git diff --check

AI disclosure:

  • Partially AI assisted (clarify which code was AI assisted and briefly explain what it does).
  • Fully AI generated (explain what all the generated code does in moderate detail).

The generated code adds the web transport adapter, browser upload/media handling, the preview deploy workflow, and focused tests for the transport mapping, HTTP error handling, restore behavior, uploads, and WebSocket event dispatch.

@Just-Insane Just-Insane marked this pull request as ready for review July 8, 2026 19:48
Copilot AI review requested due to automatic review settings July 8, 2026 19:48
Comment thread src/lib/matrixTransport.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds the missing Spec 16 “web frontend + deploy” leg by introducing a browser-first transport layer for Matrix calls (HTTP + WebSocket), updating upload/media/avatar flows to work in both Tauri and browser builds, and wiring in build/CI support for web previews.

Changes:

  • Add matrixTransport to route Matrix commands/events to either Tauri IPC or companion-server HTTP/WS.
  • Make media/avatar URLs and file upload inputs work in web builds (browser File) while preserving Tauri behavior.
  • Add web build script/env typing plus a Cloudflare Pages preview workflow; extend /api/auth/me response for restore support.

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/vite-env.d.ts Adds typed Vite env vars for selecting build target and API base.
src/lib/platform.ts Adds isWebBuild() to detect browser builds/config.
src/lib/mediaUrl.ts Introduces a helper to normalize media URLs across Tauri file paths vs web/API URLs.
src/lib/matrixTransport.ts New transport adapter: maps Matrix commands to HTTP routes and listens to WS events in web builds.
src/lib/matrixTransport.test.ts Adds focused tests for route mapping, HTTP errors, uploads, and WS event dispatch.
src/lib/matrix.ts Switches core Matrix wrapper to use the new transport; broadens upload params to `string
src/features/settings/useProfile.ts Uses new media URL helper; allows avatar mutation with File.
src/features/settings/AccountPanel.tsx Adds web file input path for avatar uploads while keeping Tauri dialog flow.
src/features/rooms/roomDisplay.ts Uses toLoadableMediaUrl instead of direct convertFileSrc.
src/features/rooms/media/useMediaSource.ts Uses toLoadableMediaUrl for resolved media paths/URLs.
src/features/rooms/ChatShell.tsx Adds web file input support for attachments; updates drag/drop/paste handling to accept File.
src/features/room-info/useRoomAdminActions.ts Allows room avatar mutation with `string
src/features/room-info/RoomSettingsForm.tsx Adds web file input for room avatar uploads while keeping Tauri dialog flow.
package.json Adds build:web script to build browser-targeted bundle.
crates/charm-web-server/src/routes.rs Extends /api/auth/me to include device_id; improves cross-signing bootstrap error mapping.
.github/workflows/web-preview.yml Adds Cloudflare Pages preview deploy workflow with secret-gated skipping + PR comment.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/lib/matrixTransport.ts Outdated
Comment thread src/lib/matrixTransport.ts Outdated
Comment thread src/lib/matrixTransport.ts
Comment thread .github/workflows/web-preview.yml Outdated
@Just-Insane Just-Insane enabled auto-merge July 8, 2026 20:05
Copilot AI review requested due to automatic review settings July 8, 2026 20:08
Comment thread crates/charm-web-server/src/routes.rs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 15 out of 16 changed files in this pull request and generated 5 comments.

Comment thread src/lib/matrixTransport.ts Outdated
Comment thread src/features/rooms/media/useMediaSource.ts
Comment thread src/lib/matrix.ts Outdated
Comment thread src/lib/matrix.ts Outdated
Comment thread .github/workflows/web-preview.yml Outdated
Copilot AI review requested due to automatic review settings July 8, 2026 20:26
Comment thread src/lib/matrixTransport.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 15 out of 16 changed files in this pull request and generated 3 comments.

Comment thread src/lib/matrixTransport.test.ts
Comment thread .github/workflows/web-preview.yml
Comment thread package.json Outdated
Copilot AI review requested due to automatic review settings July 8, 2026 20:31
@sentry

sentry Bot commented Jul 8, 2026

Copy link
Copy Markdown

Sentry Snapshot Testing

Name Added Removed Changed Renamed Unchanged Skipped Status
charm-e2e
charm-e2e
0 0 0 0 39 0 ✅ Unchanged
charm-storybook
charm-storybook
0 0 0 0 103 0 ✅ Unchanged

⚙️ charm Snapshot Settings

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 16 out of 17 changed files in this pull request and generated 1 comment.

Comment thread src/lib/matrixTransport.ts Outdated
Copilot AI review requested due to automatic review settings July 8, 2026 20:39
Comment thread src/lib/matrixTransport.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 16 out of 17 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (1)

src/lib/matrix.ts:323

  • sendAttachment now accepts a File in web builds, but the parameter name filePath suggests it is always a filesystem path. Renaming the local parameter makes the dual (path vs File) contract clearer without changing the public API surface.
export function sendAttachment(
  roomId: string,
  filePath: string | File,
  txnId: string,
  caption?: string,
): Promise<void> {
  return invoke("send_attachment", { roomId, filePath, txnId, caption });
}

Comment thread crates/charm-web-server/src/routes.rs
Comment thread src/lib/matrixTransport.ts
Comment thread src/lib/matrixTransport.ts
Comment thread .github/workflows/web-preview.yml Outdated
Copilot AI review requested due to automatic review settings July 8, 2026 20:51
@Just-Insane Just-Insane temporarily deployed to cloudflare-preview July 9, 2026 02:41 — with GitHub Actions Inactive

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 35 out of 36 changed files in this pull request and generated 1 comment.

Comment thread src/features/settings/SettingsScreen.tsx
Copilot AI review requested due to automatic review settings July 9, 2026 02:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 35 out of 36 changed files in this pull request and generated 3 comments.

Comment thread src/lib/openExternalUrl.test.ts
Comment thread src/lib/openExternalUrl.test.ts
Comment thread src/lib/openExternalUrl.test.ts

@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: 4a815ae75f

ℹ️ 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 .github/workflows/web-preview.yml Outdated
Comment thread src/lib/matrixTransport.ts
Copilot AI review requested due to automatic review settings July 9, 2026 03:17
@Just-Insane Just-Insane temporarily deployed to cloudflare-preview July 9, 2026 03:17 — with GitHub Actions Inactive

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 37 out of 38 changed files in this pull request and generated 1 comment.

Comment thread .github/workflows/web-preview.yml

@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: 5ca5894aa7

ℹ️ 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 .github/workflows/web-preview.yml Outdated
Comment thread src/features/settings/SettingsScreen.tsx
Copilot AI review requested due to automatic review settings July 9, 2026 03:46
@Just-Insane Just-Insane temporarily deployed to cloudflare-preview July 9, 2026 03:46 — with GitHub Actions Inactive

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 38 out of 39 changed files in this pull request and generated 2 comments.

Comment thread src/lib/matrixTransport.ts Outdated
Comment thread src/lib/matrixTransport.ts Outdated
Copilot AI review requested due to automatic review settings July 9, 2026 03:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 41 out of 42 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 42 out of 43 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 42 out of 43 changed files in this pull request and generated 1 comment.

Comment on lines +107 to +111
marker="<!-- charm-web-preview -->"
body="${marker}
Web preview: ${PREVIEW_URL}

Built with \`VITE_CHARM_BUILD_TARGET=web\` and a same-origin \`/api/*\` Pages proxy so Strict session cookies work in authenticated preview flows."

@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: 3af4aed443

ℹ️ 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".

*/api) api_target="${api_base}/:splat" ;;
*) api_target="${api_base}/api/:splat" ;;
esac
printf '/api/* %s 200\n' "$api_target" > dist/_redirects

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Use a supported Pages API proxy

Here api_target is an absolute http(s) companion URL and this writes it into _redirects as a 200 rewrite, but Cloudflare's Pages _redirects proxying docs say “Proxying will only support relative URLs on your site. You cannot proxy external domains.” (https://developers.cloudflare.com/pages/configuration/redirects/#proxying). Because the web bundle is built with an empty VITE_CHARM_WEB_API_BASE_URL, preview login/session/media calls all stay on the Pages host; this rule will not forward them to the companion API, so authenticated previews fail unless this is implemented with a Pages Function/Worker or another supported same-origin proxy.

Useful? React with 👍 / 👎.

Comment on lines +22 to +25
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_PAGES_PROJECT: ${{ secrets.CLOUDFLARE_PAGES_PROJECT }}
CHARM_WEB_API_BASE_URL: ${{ secrets.CHARM_WEB_API_BASE_URL }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep preview secrets out of PR build steps

For same-repository PR branches where these environment secrets are available, exporting the Cloudflare credentials at job scope means the later pnpm install and pnpm build:web steps run PR-controlled package/build scripts with CLOUDFLARE_API_TOKEN in their environment. A malicious PR can exfiltrate the Pages deploy token before deployment; keep these secrets out of the build/install job and inject them only in a trusted deploy step or separate job that does not execute PR-controlled code.

Useful? React with 👍 / 👎.

CLOUDFLARE_PAGES_PROJECT: ${{ secrets.CLOUDFLARE_PAGES_PROJECT }}
CHARM_WEB_API_BASE_URL: ${{ secrets.CHARM_WEB_API_BASE_URL }}
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4

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 Disable checkout credential persistence

This checkout uses the default persist-credentials: true; the actions/checkout v4 README states that the auth token is persisted in local git config so later scripts can run authenticated git commands. In this PR workflow the later pnpm install/pnpm build:web steps execute PR-controlled code while the job token has issues: write, so a malicious same-repository PR can recover and misuse that token before the comment step. Set persist-credentials: false here and pass GH_TOKEN only to the step that calls gh.

Useful? React with 👍 / 👎.

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