flashcards-codex-bridge 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +43 -2
  2. package/dist/bin.mjs +3894 -0
  3. package/package.json +28 -4
package/README.md CHANGED
@@ -1,3 +1,44 @@
1
- # Temporary Holding Version
1
+ # flashcards-codex-bridge
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Lets the Flashcards chat panel talk to the Codex CLI on your own machine.
4
+
5
+ ```bash
6
+ npx https://easyray-storybook.pages.dev/flashcards-codex-bridge.tgz
7
+ ```
8
+
9
+ The 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.
10
+
11
+ 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.
12
+
13
+ ## Prerequisites
14
+
15
+ - Node 22 or newer (tested on 25.2.1).
16
+ - Codex CLI installed and logged in: `npm install -g @openai/codex` (or `brew install codex`), then `codex login`. The bridge checks both at start-up (`codex --version`, `codex login status`) and says which is missing.
17
+ - Codex runs on your own default model (`~/.codex/config.toml`); the bridge asks for none.
18
+
19
+ ## Why a local process is needed
20
+
21
+ `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.
22
+
23
+ ## What it does
24
+
25
+ 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.
26
+
27
+ ## Origin rule
28
+
29
+ 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:
30
+
31
+ - https://osnovahq.com
32
+ - https://easyray-storybook.pages.dev
33
+ - http://localhost:3000, http://127.0.0.1:3000
34
+
35
+ Add one with `--allow-origin https://example.com` (repeatable) or `FLASHCARDS_BRIDGE_ORIGINS=https://a.example,https://b.example`.
36
+
37
+ ## Options
38
+
39
+ - `--port N` or `FLASHCARDS_BRIDGE_PORT`: another port (the page connects to 3417, so only for tests).
40
+ - A taken port stops start-up with a message; it never moves to another port, since the page would not find it.
41
+
42
+ ## Source and build
43
+
44
+ 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/ws@8.22.0/node_modules`.