flashcards-codex-bridge
v0.1.0
Published
Connect the Flashcards chat to your local Codex CLI: npx flashcards-codex-bridge
Readme
flashcards-codex-bridge
Lets the Flashcards chat panel talk to the Codex CLI on your own machine.
npx https://easyray-storybook.pages.dev/flashcards-codex-bridge.tgzThe package is not on the npm registry: the story site's build serves it packed (src/vite-plugin.ts, used by apps/platform/dev/vite.config.ts), and npx installs a tarball URL as it would a registry tarball. The dev server serves the same address on http://localhost:3000.
Then open https://easyray-storybook.pages.dev/?id=Apps.Flashcards.TrainStationNotes&chat=1 (or https://osnovahq.com) and press Chat. Chrome asks once whether the page may reach apps on this device ("local network access"): allow it.
Prerequisites
- Node 22 or newer (tested on 25.2.1).
- Codex CLI installed and logged in:
npm install -g @openai/codex(orbrew install codex), thencodex login. The bridge checks both at start-up (codex --version,codex login status) and says which is missing. - Codex runs on your own default model (
~/.codex/config.toml); the bridge asks for none.
Why a local process is needed
codex app-server --listen ws://127.0.0.1:PORT (codex 0.169.0) refuses every WebSocket handshake that carries an Origin header, and every browser page sends one (probe 2026-11-26: Origin https://easyray-storybook.pages.dev → Expected 101 status code: 403; the same handshake without Origin → a normal initialize reply). So a page cannot reach codex directly; this bridge speaks to codex over stdio and checks the page's Origin itself.
What it does
Listens on 127.0.0.1:3417 only, starts codex app-server, gives each browser tab its own Codex thread in a read-only sandbox, and, when the page names one of the two skills the chat offers, puts that skill's text in front of the turn. The page reaches the bridge only over the WebSocket: Chrome's Local Network Access may block a plain fetch from an https page to 127.0.0.1. The note tools run in the page, never on your disk.
Origin rule
Any web page you open can reach a server on 127.0.0.1, so the bridge accepts the WebSocket only from these page origins and answers every other one with 403:
- https://osnovahq.com
- https://easyray-storybook.pages.dev
- http://localhost:3000, http://127.0.0.1:3000
Add one with --allow-origin https://example.com (repeatable) or FLASHCARDS_BRIDGE_ORIGINS=https://a.example,https://b.example.
Options
--port NorFLASHCARDS_BRIDGE_PORT: another port (the page connects to 3417, so only for tests).- A taken port stops start-up with a message; it never moves to another port, since the page would not find it.
Source and build
The router, codex protocol, origin rule and start-up checks are shared with the repo's dev bridge, apps/product/flashcards/scripts/demo-codex-bridge.ts; src/serve-node.ts adapts them to Node (node:http, ws, node:child_process). bun run build writes one file, dist/bin.mjs, with ws, the chat instructions and the two skills inlined. npm pack and bun pm pack run the build first (prepack). Until bun install links ws into this package, build with NODE_PATH=<repo>/node_modules/.bun/[email protected]/node_modules.
