feat(gateway): suggest URL from clipboard on Gateway step (issue #18) - #20
Merged
Conversation
- extractBaseUrl(): pure regex that pulls the scheme+host from arbitrary clipboard text (https?://… with no whitespace/path). Tests pass for paste-friendly URLs, rejects mailto and bare hosts and fragment-y input. - GatewayStep calls window.hoist.clipboard.read() once on mount (renderer- initiated — main never reads the clipboard opportunistically). - Below the Base URL input, an "Use this URL" pill appears if the clipboard contains a parseable URL. - Editing the input discards the suggestion (one-shot, no sticky state). - The pill shows the parsed URL inline and has ✕ to dismiss. Layout stays consistent at 1280×800; the pill wraps gracefully if the URL is long.
- scripts/test-extract-base-url.mjs: re-implements extractBaseUrl() in plain JS (kept verbatim in sync with the App.tsx version) and asserts 10 clipboard-shape cases. - package.json: test:extractor script - .github/workflows/ci.yml: app job runs npm run test:extractor between lint and build, so the regex behavior is exercised on every PR. 10/10 cases pass: ✓ https://gateway.acme.com → https://gateway.acme.com ✓ http://localhost:4000/ → http://localhost:4000 ✓ https://gateway.ai.cloudflare.com/v1/<account_id> → https://gateway.ai.cloudflare.com ✓ \n https://api.example.com/v1 \n → https://api.example.com ✓ mailto:nope@example.com → null ✓ (empty) → null ✓ https:// → null ✓ api.example.com → null ✓ https://example.com/with/path → https://example.com ✓ https://en.wikipedia.org/wiki/Claude_(...) → https://en.wikipedia.org
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #18.
Summary
When the user lands on the Gateway step in the Electron app, Hoist reads the clipboard (renderer-initiated only — main never polls) and offers a one-click "Use this URL" suggestion pill below the Base URL field if the clipboard contains a parseable URL. Single-call, single-click; user editing the input discards the suggestion.
What changed
src/shared/channels.ts— new channelclipboard:readsrc/main/ipc.ts— handler usesclipboard.readText(), trims, truncates at 4096 charssrc/preload/api.ts+src/preload/index.ts— typedClipboardReadResponse+window.hoist.clipboard.read()src/renderer/App.tsxextractBaseUrl()regex:^https?://[^\s/?#]+— accepts scheme+host only (no path/query/fragment)GatewayStepcallsclipboard.read()on mountscripts/test-extract-base-url.mjs— 10-case smoke test mirroring the App.tsx regexpackage.json—test:extractorscript.github/workflows/ci.yml— runsnpm run test:extractorin theappjob between lint and buildPrivacy
clipboard.read. Main process never reads the clipboard opportunistically.clipboard.writeTextadded).Verification
npm run typecheck✓npm run lint✓npm run test:extractor✓ (10/10 cases including wikipedia URL → host-only)npm run build✓Test cases that pass