|
1 | 1 | # OK Code |
2 | 2 |
|
3 | | -A minimal web GUI for coding agents. Currently supports Codex and Claude, with more providers coming. |
4 | | - |
5 | | -## Quick Start |
| 3 | +## 1) What this project is |
| 4 | + |
| 5 | +OK Code is a desktop-first orchestration platform for interactive coding agents. |
| 6 | +It connects a local runtime (`apps/server`) that manages provider sessions with a |
| 7 | +React client (`apps/web`) that renders live orchestration events and session state. |
| 8 | + |
| 9 | +## 2) Architecture and core flow |
| 10 | + |
| 11 | +### High-level flow |
| 12 | + |
| 13 | +```mermaid |
| 14 | +flowchart LR |
| 15 | + User["Developer"] --> UI["apps/web (React/Vite)"] |
| 16 | + UI --> WS["apps/server/src/wsServer.ts<br/>NativeApi + WS routing"] |
| 17 | + WS --> PM["apps/server/src/providerManager.ts<br/>Session request orchestration"] |
| 18 | + PM --> SM["apps/server/src/codexAppServerManager.ts<br/>Provider process lifecycle"] |
| 19 | + SM --> Codex["codex app-server (process)"] |
| 20 | + PM --> Contracts["@okcode/contracts"] |
| 21 | + WS --> Contracts |
| 22 | + Shared["packages/shared/*"] --> PM |
| 23 | + Shared --> UI |
| 24 | +``` |
6 | 25 |
|
7 | | -```bash |
8 | | -npx okcodes |
| 26 | +### Component responsibilities |
| 27 | + |
| 28 | +- `apps/server` |
| 29 | + - Owns session lifecycle: start/resume, reconnect handling, provider multiplexing. |
| 30 | + - Provides the WebSocket API that the web app talks to. |
| 31 | + - Converts provider output into shared orchestration-domain events. |
| 32 | +- `apps/web` |
| 33 | + - Owns user interaction, streaming UI, logs, and local state. |
| 34 | + - Consumes server events and sends control actions back through `NativeApi`. |
| 35 | +- `packages/contracts` |
| 36 | + - Shared protocol/event types (`effect/Schema`) used by both sides. |
| 37 | + - Keep this package schema-focused and stable. |
| 38 | +- `packages/shared` |
| 39 | + - Cross-package runtime helpers with explicit subpath exports (for example `@okcode/shared/git`). |
| 40 | + - Use shared helpers instead of duplicating transport/session utility code. |
| 41 | + |
| 42 | +## 3) Repository map |
| 43 | + |
| 44 | +```text |
| 45 | +apps/ |
| 46 | + server/ Runtime orchestration and websocket gateway. |
| 47 | + web/ React conversation and orchestration UI. |
| 48 | + desktop/ Electron shell and client bootstrap. |
| 49 | + marketing/ Marketing/public site. |
| 50 | + mobile/ Capacitor app wrapper/build tooling. |
| 51 | +packages/ |
| 52 | + contracts/ Shared protocol/schema definitions. |
| 53 | + shared/ Shared runtime utilities. |
| 54 | +docs/ |
| 55 | + releases/ Release process, release notes, and asset manifests. |
| 56 | +scripts/ |
| 57 | + Build/release/bootstrap scripts and local tooling. |
9 | 58 | ``` |
10 | 59 |
|
11 | | -This starts the OK Code server and opens your browser. The app automatically detects which providers you have installed. |
| 60 | +## 4) Setup and local development |
12 | 61 |
|
13 | | -Or install the [desktop app from the Releases page](https://github.com/OpenKnots/okcode/releases). |
| 62 | +### Required tooling |
14 | 63 |
|
15 | | -### Provider Setup |
| 64 | +- Bun (matching project engine): `bun@1.3.11+` |
| 65 | +- Node 24+ (repo declares `bun` + `node` engine compatibility) |
| 66 | +- Xcode for iOS-related work |
| 67 | +- macOS or Linux for development |
16 | 68 |
|
17 | | -OK Code supports multiple AI providers. You need **at least one** configured to start coding. |
| 69 | +### Install |
18 | 70 |
|
19 | | -<details> |
20 | | -<summary><strong>Option A: OpenAI (Codex CLI)</strong></summary> |
| 71 | +```bash |
| 72 | +bun install |
| 73 | +``` |
21 | 74 |
|
22 | | -1. Install: `npm install -g @openai/codex` |
23 | | -2. Authenticate: `codex login` |
24 | | -3. Verify: `codex login status` |
| 75 | +### Run everything |
25 | 76 |
|
26 | | -If using a custom model provider (Azure OpenAI, Portkey, etc.), configure `model_provider` in `~/.codex/config.toml` instead — no `codex login` needed. |
| 77 | +```bash |
| 78 | +bun dev |
| 79 | +``` |
27 | 80 |
|
28 | | -</details> |
| 81 | +### Common workflows |
29 | 82 |
|
30 | | -<details> |
31 | | -<summary><strong>Option B: Anthropic (Claude Code)</strong></summary> |
| 83 | +```bash |
| 84 | +bun dev:server # apps/server only |
| 85 | +bun dev:web # apps/web only |
| 86 | +bun dev:desktop # desktop shell + electron dev flow |
| 87 | +bun dev:marketing # marketing site |
| 88 | +``` |
32 | 89 |
|
33 | | -1. Install: `npm install -g @anthropic-ai/claude-code` |
34 | | -2. Authenticate: `claude auth login` |
35 | | -3. Verify: `claude auth status` |
| 90 | +### Package scoped examples |
36 | 91 |
|
37 | | -</details> |
| 92 | +```bash |
| 93 | +bun --filter @okcode/web dev |
| 94 | +bun --filter okcodes dev |
| 95 | +bun --filter @okcode/desktop build |
| 96 | +bun --filter @okcode/contracts typecheck |
| 97 | +``` |
38 | 98 |
|
39 | | -> [!TIP] |
40 | | -> You can install both providers and switch between them per session. |
| 99 | +> `bun --filter okcodes dev` is useful when you explicitly want the server package by |
| 100 | +> its legacy package name (`okcodes`). |
41 | 101 |
|
42 | | -### Troubleshooting |
| 102 | +### Quick-start operator matrix |
43 | 103 |
|
44 | | -Run the built-in diagnostic to check your setup: |
| 104 | +| Intent | Command | Expected result | Where to verify | |
| 105 | +| ------------------------- | -------------------------------- | ------------------------------------------------ | ------------------------------------------------------ | |
| 106 | +| Boot full local stack | `bun dev` | workspace starts dev scripts and shared services | logs show dev server/process startup | |
| 107 | +| Run desktop app flow only | `bun dev:desktop` | local Electron + web bundle pipeline starts | verify desktop window opens and server socket connects | |
| 108 | +| Build desktop artifacts | `bun build:desktop` | production desktop build output generated | workspace build pipeline succeeds in logs | |
| 109 | +| Build web app | `bun --filter @okcode/web build` | Vite build output produced | check dist artifacts and exit code 0 | |
| 110 | +| Validate formatting | `bun run fmt:check` | no formatting diffs | command exits 0 | |
| 111 | +| Validate lint rules | `bun run lint` | lint passes | no lints in output | |
| 112 | +| Validate TypeScript | `bun run typecheck` | no compile errors | all package typechecks pass | |
| 113 | +| Run tests | `bun run test` | Vitest suites execute | exit code 0, no failing tests | |
45 | 114 |
|
46 | | -```bash |
47 | | -npx okcodes doctor |
48 | | -``` |
| 115 | +## 5) Runtime behavior (what happens during a session) |
| 116 | + |
| 117 | +1. Web UI opens WebSocket and subscribes to orchestration events. |
| 118 | +2. UI submits user action to a `NativeApi` endpoint in `wsServer.ts`. |
| 119 | +3. Server dispatches the request through `providerManager`. |
| 120 | +4. `codexAppServerManager` starts or resumes the underlying `codex app-server` process. |
| 121 | +5. Process outputs are parsed, normalized into shared events, and pushed back to UI. |
| 122 | +6. UI applies deterministic reducers for rendering logs, state, and action controls. |
49 | 123 |
|
50 | | -If OK Code shows a provider error banner after launch: |
| 124 | +Reconnect and recovery are first-class behaviors: |
51 | 125 |
|
52 | | -| Banner message | Fix | |
53 | | -| ------------------------------ | ------------------------------------------------- | |
54 | | -| "not installed or not on PATH" | Install the CLI (see above), then restart OK Code | |
55 | | -| "not authenticated" | Run the login command for that provider | |
56 | | -| "version check failed" | Update the CLI to the latest version | |
| 126 | +- active process restarts should resume context when session state is available, |
| 127 | +- failed parses are surfaced as explicit error states instead of silent fallback behavior. |
57 | 128 |
|
58 | | -> [!NOTE] |
59 | | -> OK Code launches even without providers configured — you can explore the UI and configure provider binary paths from **Settings** before starting a session. |
| 129 | +## 6) Contracts and compatibility |
60 | 130 |
|
61 | | -## Development Setup |
| 131 | +- All contract changes should begin in `packages/contracts`. |
| 132 | +- Update both producer (`apps/server`) and consumer (`apps/web`) in the same commit. |
| 133 | +- Validate generated type surface with: |
| 134 | + - `bun run typecheck` |
| 135 | + - targeted package `typecheck` scripts when needed. |
62 | 136 |
|
63 | | -**Prerequisites**: [Bun](https://bun.sh) >= 1.3.9, [Node.js](https://nodejs.org) >= 24.13.1 |
| 137 | +## 7) Build and quality gates |
64 | 138 |
|
65 | 139 | ```bash |
66 | | -bun install |
67 | | -bun dev # start server + web in parallel |
| 140 | +bun run fmt |
| 141 | +bun run fmt:check |
| 142 | +bun run lint |
| 143 | +bun run typecheck |
| 144 | +bun run test |
68 | 145 | ``` |
69 | 146 |
|
70 | | -This runs the contracts build, then starts the server (port 3773) and web app (port 5733) together via Turbo. |
| 147 | +Notes: |
71 | 148 |
|
72 | | -Other dev commands: |
| 149 | +- `bun run test` is the required test entrypoint. |
| 150 | +- Formatting uses `oxfmt`; lint uses `oxlint`. |
| 151 | +- Release tasks in CI are intentionally strict and require clean checks to proceed. |
73 | 152 |
|
74 | | -```bash |
75 | | -bun dev:server # server only |
76 | | -bun dev:web # web only |
77 | | -bun dev:desktop # Electron desktop + web |
78 | | -bun dev:marketing # Astro marketing site |
79 | | -``` |
| 153 | +## 8) Release operations |
80 | 154 |
|
81 | | -Quality checks: |
| 155 | +Release is mostly driven by `.github/workflows/release.yml` and docs in `docs/releases`. |
82 | 156 |
|
83 | | -```bash |
84 | | -bun fmt # format (oxfmt) |
85 | | -bun lint # lint (oxlint) |
86 | | -bun typecheck # type-check all packages |
87 | | -bun run test # run tests (Vitest) |
88 | | -``` |
89 | | - |
90 | | -## Architecture |
| 157 | +- Trigger on tag push (`vX.Y.Z`) or `workflow_dispatch`. |
| 158 | +- Preflight does `bun run lint`, `bun run typecheck`, `bun run test`, |
| 159 | + and release smoke. |
| 160 | +- Artifact build step executes `bun run dist:desktop:artifact`. |
| 161 | +- Publishing requires release notes + asset manifest for the version. |
91 | 162 |
|
92 | | -OK Code is a monorepo with four apps and two shared packages, orchestrated by [Turbo](https://turbo.build). |
| 163 | +For a practical walkthrough, use the release playbook in |
| 164 | +[`docs/releases/README.md`](/Users/buns/.okcode/worktrees/okcode/okcode-ddc899c0/docs/releases/README.md). |
93 | 165 |
|
94 | | -``` |
95 | | -┌─────────────────────────────────┐ |
96 | | -│ Browser (React + Vite) │ |
97 | | -│ wsTransport (state machine) │ |
98 | | -│ Typed push decode at boundary │ |
99 | | -└──────────┬──────────────────────┘ |
100 | | - │ ws://localhost:3773 |
101 | | -┌──────────▼──────────────────────┐ |
102 | | -│ apps/server (Node.js) │ |
103 | | -│ WebSocket + HTTP static server │ |
104 | | -│ OrchestrationEngine │ |
105 | | -│ ProviderService │ |
106 | | -└──────────┬──────────────────────┘ |
107 | | - │ JSON-RPC over stdio |
108 | | -┌──────────▼──────────────────────┐ |
109 | | -│ codex app-server │ |
110 | | -└─────────────────────────────────┘ |
111 | | -``` |
| 166 | +## 9) Extending the system (recommended pattern) |
112 | 167 |
|
113 | | -The server spawns `codex app-server` as a child process, communicating over JSON-RPC on stdio. Provider runtime events are normalized into orchestration domain events and pushed to the browser over WebSocket. |
| 168 | +1. Start at the boundary where behavior changes: |
| 169 | + - event shape → `packages/contracts` |
| 170 | + - runtime orchestration → `apps/server` |
| 171 | + - rendering/state handling → `apps/web` |
| 172 | +2. Add/update shared types first. |
| 173 | +3. Update server-side translation/projection next. |
| 174 | +4. Update UI consumers and add tests or focused regression checks. |
| 175 | +5. Run all quality gates before commit. |
114 | 176 |
|
115 | | -### Packages |
| 177 | +## 10) Security and operational posture |
116 | 178 |
|
117 | | -| Package | Path | Role | |
118 | | -| ------------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
119 | | -| `okcodes` | `apps/server` | Node.js CLI and WebSocket server. Wraps Codex app-server, serves the React web app, and manages provider sessions. | |
120 | | -| `@okcode/web` | `apps/web` | React 19 + Vite SPA. Session UX, conversation rendering, and client-side state via Zustand. Connects to the server over WebSocket. | |
121 | | -| `@okcode/desktop` | `apps/desktop` | Electron shell that bundles the server and web app into a native desktop application with auto-updates. | |
122 | | -| `@okcode/marketing` | `apps/marketing` | Astro marketing site. | |
123 | | -| `@okcode/contracts` | `packages/contracts` | Shared [Effect](https://effect.website) schemas and TypeScript contracts for the WebSocket protocol, provider events, orchestration model, and session types. Schema-only — no runtime logic. | |
124 | | -| `@okcode/shared` | `packages/shared` | Shared runtime utilities (git, logging, shell, networking). Uses explicit subpath exports (`@okcode/shared/git`, etc.) — no barrel index. | |
| 179 | +- No secrets in files tracked by git. |
| 180 | +- Validate untrusted inputs before invoking spawn/process APIs. |
| 181 | +- Keep cleanup idempotent (process kill, temp files, sockets). |
| 182 | +- Emit explicit telemetry for failure modes to avoid hidden partial failures. |
125 | 183 |
|
126 | | -### Key Technologies |
| 184 | +## 11) FAQ |
127 | 185 |
|
128 | | -- **Runtime**: Node.js + Bun |
129 | | -- **UI**: React 19, Vite 8, Tailwind CSS 4, TanStack Router & Query |
130 | | -- **Server**: Effect, WebSocket (`ws`), node-pty |
131 | | -- **Desktop**: Electron |
132 | | -- **Schemas**: Effect Schema (in `@okcode/contracts`) |
133 | | -- **Build**: Turbo, tsdown |
134 | | -- **Lint/Format**: oxlint, oxfmt |
135 | | -- **Tests**: Vitest, Playwright |
| 186 | +- **Why are x64 macOS artifacts sometimes absent from release matrix?** |
| 187 | + The release workflow can be configured to build only Apple Silicon by default for `workflow_dispatch` with `mac_arm64_only=true`. |
| 188 | +- **Why strict release gates?** |
| 189 | + They prevent format/type drift from reaching published artifacts. |
| 190 | +- **Can I run release checks locally first?** |
| 191 | + Yes, run the section 7 checks and create your release notes manifest files before creating a tag. |
136 | 192 |
|
137 | | -### Event Flow |
| 193 | +## 12) Operational checklists |
138 | 194 |
|
139 | | -1. The browser opens a WebSocket to the server and registers typed listeners. |
140 | | -2. User actions become typed requests sent through the WebSocket transport. |
141 | | -3. The server routes requests to `ProviderService`, which talks to `codex app-server` over JSON-RPC. |
142 | | -4. Provider events are ingested, normalized into orchestration events, and persisted. |
143 | | -5. The server pushes domain events back to the browser through an ordered push bus (`orchestration.domainEvent` channel). |
144 | | -6. Async work (checkpoints, command reactions) runs through queue-backed workers and emits typed receipts on completion. |
| 195 | +### Pre-PR gate |
145 | 196 |
|
146 | | -For the full architecture with sequence diagrams, see [.docs/architecture.md](.docs/architecture.md). |
| 197 | +1. `bun run fmt:check` |
| 198 | +2. `bun run lint` |
| 199 | +3. `bun run typecheck` |
| 200 | +4. `bun run test` |
| 201 | +5. targeted package checks if changing app/domain boundaries |
147 | 202 |
|
148 | | -## Contributing |
| 203 | +### Pre-release hardening |
149 | 204 |
|
150 | | -Read [CONTRIBUTING.md](./CONTRIBUTING.md) before opening an issue or PR. |
| 205 | +1. Ensure release notes and asset manifest are prepared. |
| 206 | +2. Confirm release matrix intent (`mac_arm64_only` expectation). |
| 207 | +3. Confirm signing secrets availability for macOS/Windows targets. |
| 208 | +4. Confirm `docs/releases/v<version>.md` and `docs/releases/v<version>/assets.md` exist. |
| 209 | +5. Trigger release and monitor all jobs. |
151 | 210 |
|
152 | | -## Support |
| 211 | +## 12) Contributing expectations |
153 | 212 |
|
154 | | -Join the [Discord](https://discord.gg/openknot). |
| 213 | +- Favor small scoped changes with clear ownership. |
| 214 | +- Keep protocol surfaces version-consistent and documented. |
| 215 | +- Update docs whenever startup flow, payload contracts, or release behavior changes. |
| 216 | +- Prefer correctness over convenience in stream/retry code. |
0 commit comments