@wipcomputer/wip-ldm-os 0.4.85-alpha.17 → 0.4.85-alpha.18

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.
package/README.md CHANGED
@@ -105,6 +105,8 @@ The OS connects your AIs. Add-ons are what they actually use. Each one is a full
105
105
  ## More Info
106
106
 
107
107
  - [Architecture, principles, and technical details](TECHNICAL.md)
108
+ - [Hosted MCP and relay source](src/hosted-mcp/README.md)
109
+ - [Hosted relay self-host guide](src/hosted-mcp/docs/self-host.md)
108
110
 
109
111
  ## License
110
112
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wipcomputer/wip-ldm-os",
3
- "version": "0.4.85-alpha.17",
3
+ "version": "0.4.85-alpha.18",
4
4
  "type": "module",
5
5
  "description": "LDM OS: identity, memory, and sovereignty infrastructure for AI agents",
6
6
  "engines": {
@@ -2,6 +2,7 @@ import { readFileSync } from "node:fs";
2
2
  import {
3
3
  codexDaemonPubkeyFingerprint,
4
4
  createCodexDaemonPubkeyRegistry,
5
+ evaluateCodexDaemonReconnectPubkey,
5
6
  } from "../src/hosted-mcp/codex-relay-e2ee-registry.mjs";
6
7
 
7
8
  const server = readFileSync("src/hosted-mcp/server.mjs", "utf8");
@@ -35,6 +36,8 @@ assertContains(server, "consumeCodexPairPresenceToken(pairPresenceToken, identit
35
36
  assertContains(server, 'json(res, 404, { error: "invalid or already-used code" });', "pair code reuse rejection");
36
37
  assertContains(server, 'json(res, 410, { error: "code expired or already used" });', "pair code expiry rejection");
37
38
  assertContains(server, "invalidateCodexBrowserSessionsForAgent(identity.agentId, \"daemon key replaced\")", "daemon replacement invalidates stale browser sessions");
39
+ assertContains(server, "evaluateCodexDaemonReconnectPubkey(", "daemon reconnect checks existing key policy");
40
+ assertContains(server, "daemon key change requires fresh pair", "changed daemon reconnect key requires pair flow");
38
41
  assertContains(server, "p.replaced_daemon_key = !!daemonKeyResult?.replaced;", "pair state records replacement status");
39
42
  assertContains(server, "replaced_daemon_key: !!p.replaced_daemon_key", "pair-status exposes relink replacement status");
40
43
  assertContains(pairHtml, "codex_pair_presence_token: getPairPresenceToken()", "pair page sends pair presence token");
@@ -69,6 +72,22 @@ assert(registry.auditLog[1].replaced === true, "audit marks replacement");
69
72
  assert(registry.auditLog[1].old_pubkey_fingerprint === oldFingerprint, "audit stores old fingerprint");
70
73
  assert(registry.auditLog[1].new_pubkey_fingerprint === newFingerprint, "audit stores new fingerprint");
71
74
 
75
+ const firstReconnectPolicy = evaluateCodexDaemonReconnectPubkey(null, "daemon-reconnect-key");
76
+ assert(firstReconnectPolicy.allowed === true, "daemon reconnect can self-heal when no key is registered");
77
+ assert(firstReconnectPolicy.replaced === false, "first daemon reconnect is not a replacement");
78
+ const sameReconnectPolicy = evaluateCodexDaemonReconnectPubkey({ pubkey: "daemon-reconnect-key" }, "daemon-reconnect-key");
79
+ assert(sameReconnectPolicy.allowed === true, "daemon reconnect can re-register the same key");
80
+ assert(sameReconnectPolicy.replaced === false, "same-key daemon reconnect is not a replacement");
81
+ const changedReconnectPolicy = evaluateCodexDaemonReconnectPubkey({ pubkey: "daemon-reconnect-key" }, "attacker-reconnect-key");
82
+ assert(changedReconnectPolicy.allowed === false, "daemon reconnect cannot replace an existing key");
83
+ assert(changedReconnectPolicy.reason === "fresh_pair_required", "changed daemon reconnect requires fresh pair");
84
+ assert(changedReconnectPolicy.replaced === true, "changed daemon reconnect is detected as replacement");
85
+ assert(changedReconnectPolicy.old_fingerprint === codexDaemonPubkeyFingerprint("daemon-reconnect-key"), "changed reconnect reports old fingerprint");
86
+ assert(changedReconnectPolicy.new_fingerprint === codexDaemonPubkeyFingerprint("attacker-reconnect-key"), "changed reconnect reports new fingerprint");
87
+ const invalidReconnectPolicy = evaluateCodexDaemonReconnectPubkey({ pubkey: "daemon-reconnect-key" }, "");
88
+ assert(invalidReconnectPolicy.allowed === false, "daemon reconnect rejects missing pubkey");
89
+ assert(invalidReconnectPolicy.reason === "invalid_daemon_pubkey", "missing daemon reconnect pubkey has explicit reason");
90
+
72
91
  const executeCalls = [];
73
92
  const persistedRegistry = createCodexDaemonPubkeyRegistry({
74
93
  usePrisma: true,
@@ -0,0 +1,15 @@
1
+ # Hosted MCP And Relay
2
+
3
+ This directory contains the public source for the hosted WIP relay that serves `wip.computer`.
4
+
5
+ It includes:
6
+
7
+ - OAuth, passkey, and hosted MCP routes in `server.mjs`;
8
+ - Codex Remote Control relay routes under `/api/codex-relay/*`;
9
+ - nginx snippets for the relay, MCP, and site proxy;
10
+ - Prisma schema and migrations for Postgres-backed account, API key, passkey, device, and wallet state;
11
+ - PM2 and deploy helpers for the WIP-operated VPS.
12
+
13
+ WIP runs the production hosted relay so user setup is easy and works across networks. The source is public so users can inspect the relay path and build their own infrastructure.
14
+
15
+ For the self-hosting shape, read [docs/self-host.md](docs/self-host.md).
@@ -12,6 +12,39 @@ export function codexDaemonPubkeyFingerprint(pubkey) {
12
12
  return "sha256:" + createHash("sha256").update(pubkey).digest("base64url").slice(0, 16);
13
13
  }
14
14
 
15
+ export function evaluateCodexDaemonReconnectPubkey(existingKey, incomingPubkey) {
16
+ const existingPubkey = typeof existingKey?.pubkey === "string" && existingKey.pubkey ? existingKey.pubkey : null;
17
+ const nextPubkey = typeof incomingPubkey === "string" && incomingPubkey ? incomingPubkey : null;
18
+ const oldFingerprint = codexDaemonPubkeyFingerprint(existingPubkey);
19
+ const newFingerprint = codexDaemonPubkeyFingerprint(nextPubkey);
20
+
21
+ if (!nextPubkey) {
22
+ return {
23
+ allowed: false,
24
+ reason: "invalid_daemon_pubkey",
25
+ replaced: false,
26
+ old_fingerprint: oldFingerprint,
27
+ new_fingerprint: newFingerprint,
28
+ };
29
+ }
30
+ if (!existingPubkey || existingPubkey === nextPubkey) {
31
+ return {
32
+ allowed: true,
33
+ reason: null,
34
+ replaced: false,
35
+ old_fingerprint: oldFingerprint,
36
+ new_fingerprint: newFingerprint,
37
+ };
38
+ }
39
+ return {
40
+ allowed: false,
41
+ reason: "fresh_pair_required",
42
+ replaced: true,
43
+ old_fingerprint: oldFingerprint,
44
+ new_fingerprint: newFingerprint,
45
+ };
46
+ }
47
+
15
48
  export function buildCodexBootstrapPayload({ identity, threadId, daemonOnline, daemonKey }) {
16
49
  return {
17
50
  handle: identity.handle,
@@ -0,0 +1,268 @@
1
+ # Hosted Relay Self-Host Guide
2
+
3
+ This guide explains how to inspect and run the hosted relay source that backs WIP-hosted services such as Codex Remote Control.
4
+
5
+ The public source lives here:
6
+
7
+ ```text
8
+ src/hosted-mcp
9
+ ```
10
+
11
+ WIP's production relay runs at `wip.computer`. Self-hosting means running the same relay source on your own domain, with your own database, TLS certificate, process manager, and secrets.
12
+
13
+ ## What The Hosted Relay Does
14
+
15
+ The hosted relay is a Node server with several surfaces:
16
+
17
+ - hosted MCP over HTTP at `/mcp`;
18
+ - OAuth and passkey login routes;
19
+ - demo routes under `/demo`;
20
+ - Codex Remote Control pairing and relay routes under `/api/codex-relay/*`;
21
+ - health reporting at `/health`.
22
+
23
+ For Codex Remote Control, the relay lets a local `codex-daemon` dial out to a public server. Browser and phone clients connect to that same public server. After E2EE setup, prompt text, assistant output, command output, and errors are carried as encrypted frames. The relay routes and authorizes frames, but it is not the place where Codex runs.
24
+
25
+ ## Current Self-Host Status
26
+
27
+ The relay source is inspectable and runnable, but the non-WIP self-host story is not yet a one-command installer.
28
+
29
+ Important current constraints:
30
+
31
+ - `server.mjs` currently defaults `ISSUER_URL`, `MCP_RESOURCE_URL`, `RP_ID`, and `RP_ORIGIN` to `wip.computer`;
32
+ - the nginx examples are written for the WIP production domain and filesystem layout;
33
+ - the Codex Remote Control browser surface at `/codex-remote-control/<threadId>` is served by the WIP web app, not by the hosted-mcp Node process itself;
34
+ - `codex-daemon` can point at a custom relay with environment variables, but a complete non-WIP phone/web UI deployment must also point at that same relay.
35
+
36
+ That means a production self-host should treat this guide as the infrastructure map. Before broad use, parameterize or patch the WIP domain constants for your domain.
37
+
38
+ ## Prerequisites
39
+
40
+ You need:
41
+
42
+ - Node.js 20 or newer;
43
+ - npm;
44
+ - Postgres;
45
+ - nginx or another reverse proxy that supports WebSocket upgrades;
46
+ - TLS for your domain;
47
+ - PM2 or another process manager;
48
+ - a public domain such as `relay.example.com`.
49
+
50
+ Optional demo surfaces may also need:
51
+
52
+ - `OPENAI_API_KEY`;
53
+ - `XAI_API_KEY`.
54
+
55
+ Codex Remote Control relay operation does not require those demo keys.
56
+
57
+ ## Environment
58
+
59
+ Start from:
60
+
61
+ ```bash
62
+ cd src/hosted-mcp
63
+ cp .env.example .env
64
+ ```
65
+
66
+ Required:
67
+
68
+ ```bash
69
+ DATABASE_URL=postgresql://kaleidoscope:YOUR_PASSWORD@localhost:5432/kaleidoscope
70
+ ```
71
+
72
+ Common optional variables:
73
+
74
+ ```bash
75
+ MCP_PORT=18800
76
+ LDM_HOSTED_MCP_WS_ORIGIN_ALLOWLIST=https://relay.example.com
77
+ LDM_HOSTED_MCP_RL_MINT=30
78
+ LDM_HOSTED_MCP_RL_VALIDATE=60
79
+ LDM_HOSTED_MCP_RL_STATUS=120
80
+ ```
81
+
82
+ Development-only variables:
83
+
84
+ ```bash
85
+ LDM_HOSTED_MCP_DEV_MODE=1
86
+ LDM_HOSTED_MCP_ALLOW_WS_URL_TOKEN=1
87
+ ```
88
+
89
+ Do not enable those development flags in production. Production should use Postgres and bearer or ticket authentication, not JSON fallback files or URL token fallback.
90
+
91
+ ## Database Setup
92
+
93
+ Create a Postgres database and user for the relay. Then run Prisma from `src/hosted-mcp`:
94
+
95
+ ```bash
96
+ npm install
97
+ npx prisma generate
98
+ npx prisma migrate deploy
99
+ ```
100
+
101
+ The Prisma schema stores:
102
+
103
+ - users;
104
+ - WebAuthn credentials;
105
+ - device tokens;
106
+ - wallets;
107
+ - API keys.
108
+
109
+ Production should use Postgres. If Prisma cannot connect and `LDM_HOSTED_MCP_DEV_MODE` is not set, the server fails closed.
110
+
111
+ ## Local Smoke Test
112
+
113
+ From `src/hosted-mcp`:
114
+
115
+ ```bash
116
+ npm install
117
+ node server.mjs
118
+ ```
119
+
120
+ In another shell:
121
+
122
+ ```bash
123
+ curl -fsS http://127.0.0.1:18800/health
124
+ ```
125
+
126
+ Expected result: JSON health output from the Node process.
127
+
128
+ ## Process Management
129
+
130
+ WIP production uses PM2 with:
131
+
132
+ ```text
133
+ src/hosted-mcp/ecosystem.config.cjs
134
+ ```
135
+
136
+ For a self-host:
137
+
138
+ ```bash
139
+ cd src/hosted-mcp
140
+ pm2 start ecosystem.config.cjs --update-env
141
+ pm2 save
142
+ pm2 status mcp-server
143
+ ```
144
+
145
+ If you use another process manager, preserve the same contract:
146
+
147
+ - run `server.mjs` from `src/hosted-mcp`;
148
+ - provide `DATABASE_URL`;
149
+ - keep the process alive across restarts;
150
+ - preserve environment variables on reload;
151
+ - verify `/health` after restart.
152
+
153
+ ## Deploy Helper
154
+
155
+ WIP's production deploy helper is:
156
+
157
+ ```text
158
+ src/hosted-mcp/deploy.sh
159
+ ```
160
+
161
+ It copies `server.mjs`, supporting modules, static app/demo files, nginx snippets, and package metadata to WIP's VPS, then reloads nginx, reloads PM2, and writes a deploy manifest.
162
+
163
+ For self-hosting, read it as an example of the file inventory and verification sequence. Do not run it unmodified unless your SSH host, remote directories, nginx layout, PM2 process name, and deploy-manifest path intentionally match the WIP production layout.
164
+
165
+ ## nginx, TLS, And Domain
166
+
167
+ The production nginx examples live in:
168
+
169
+ ```text
170
+ src/hosted-mcp/nginx
171
+ ```
172
+
173
+ Key files:
174
+
175
+ - `codex-relay.conf` contains the `/api/codex-relay/*`, `/pair`, and WebSocket proxy routes;
176
+ - `mcp-oauth.conf` and `mcp-server.conf` contain hosted MCP and OAuth routes;
177
+ - `wip.computer.conf` shows how WIP includes those snippets inside the public site config;
178
+ - `conf.d/redact-logs.conf` defines the redacted access-log format.
179
+
180
+ For self-hosting:
181
+
182
+ 1. Put TLS in front of your relay domain.
183
+ 2. Proxy HTTP routes to `http://127.0.0.1:18800`.
184
+ 3. Preserve WebSocket upgrade headers for `/api/codex-relay/web/` and `/api/codex-relay/daemon`.
185
+ 4. Use redacted logs so bearer tokens, relay tickets, and API keys do not land in access logs.
186
+ 5. Replace WIP paths and domains with your own.
187
+
188
+ Minimum verification:
189
+
190
+ ```bash
191
+ sudo nginx -t
192
+ sudo systemctl reload nginx
193
+ curl -fsS https://relay.example.com/health
194
+ ```
195
+
196
+ ## Pointing Codex Remote Control At A Custom Relay
197
+
198
+ `codex-daemon` defaults to WIP's hosted relay. For a custom relay, set the relay endpoints before pairing and starting the daemon:
199
+
200
+ ```bash
201
+ export CODEX_DAEMON_RELAY_HTTP=https://relay.example.com
202
+ export CODEX_DAEMON_RELAY_WS=wss://relay.example.com/api/codex-relay/daemon
203
+ codex-daemon link
204
+ codex-daemon start
205
+ ```
206
+
207
+ The MCP tool that creates browser links also defaults to WIP's hosted origin. Set this for sessions that should generate links for your relay domain:
208
+
209
+ ```bash
210
+ export CODEX_REMOTE_CONTROL_ORIGIN=https://relay.example.com
211
+ ```
212
+
213
+ A full non-WIP deployment also needs a browser or phone UI that serves `/codex-remote-control/<threadId>` and talks to the same relay routes. In WIP production, that UI is part of the Kaleidoscope web app.
214
+
215
+ ## Verify The Relay
216
+
217
+ Use these checks after any deploy:
218
+
219
+ ```bash
220
+ curl -fsS https://relay.example.com/health
221
+ curl -fsS https://relay.example.com/api/codex-relay/state
222
+ ```
223
+
224
+ For WIP production deploys, `scripts/verify-deploy.sh` verifies a deploy manifest against live remote file hashes:
225
+
226
+ ```bash
227
+ bash src/hosted-mcp/scripts/verify-deploy.sh latest
228
+ ```
229
+
230
+ That script assumes the WIP deploy-manifest layout unless you pass a different manifest and remote.
231
+
232
+ ## What Not To Copy From WIP Production
233
+
234
+ Do not copy:
235
+
236
+ - WIP `.env` files;
237
+ - WIP Postgres credentials;
238
+ - WIP API keys or `ck-` tokens;
239
+ - WIP passkey, device, wallet, or user rows;
240
+ - WIP PM2 process state;
241
+ - WIP nginx certificate paths;
242
+ - WIP domain constants without changing them for your domain;
243
+ - WIP deploy manifests as proof of your deploy.
244
+
245
+ Use the source shape, not WIP's production secrets or account data.
246
+
247
+ ## Production Checklist
248
+
249
+ - Domain and TLS are live.
250
+ - `DATABASE_URL` points at your Postgres database.
251
+ - Prisma migrations have run.
252
+ - `server.mjs` starts without `LDM_HOSTED_MCP_DEV_MODE`.
253
+ - nginx proxies `/health`, `/mcp`, `/oauth/*`, `/api/codex-relay/*`, `/pair`, and WebSocket upgrades.
254
+ - WebSocket origins are restricted with `LDM_HOSTED_MCP_WS_ORIGIN_ALLOWLIST`.
255
+ - URL token fallback is disabled.
256
+ - Access logs redact bearer tokens, relay tickets, and `ck-` values.
257
+ - `codex-daemon link` completes against your domain.
258
+ - `codex-daemon start` reports relay paired.
259
+ - Browser links are generated for your domain, not `wip.computer`.
260
+
261
+ ## Open Work
262
+
263
+ The remaining product work is to turn this infrastructure map into a first-class self-host installer:
264
+
265
+ - parameterize issuer and WebAuthn relying party settings;
266
+ - package the phone/web Remote Control UI for non-WIP domains;
267
+ - add a guided `ldm` self-host profile;
268
+ - add an end-to-end self-host smoke test that pairs a daemon and browser through a non-WIP domain.
@@ -25,7 +25,9 @@ import { WebSocketServer } from "ws";
25
25
  import { parse as parseUrlQs } from "node:querystring";
26
26
  import {
27
27
  buildCodexBootstrapPayload,
28
+ codexDaemonPubkeyFingerprint,
28
29
  createCodexDaemonPubkeyRegistry,
30
+ evaluateCodexDaemonReconnectPubkey,
29
31
  } from "./codex-relay-e2ee-registry.mjs";
30
32
 
31
33
  // ── Settings ─────────────────────────────────────────────────────────
@@ -909,7 +911,7 @@ async function handleAuthVerify(req, res) {
909
911
  }
910
912
  entry.apiKey = newKey;
911
913
  entry.handle = credentialLabel;
912
- console.log("WebAuthn: minted recovery key for tenant '" + entry.agentId + "' (key: " + newKey.slice(0, 10) + "...)");
914
+ console.log("WebAuthn: minted recovery key for tenant '" + entry.agentId + "' (key: " + newKey.slice(0, 6) + "...)");
913
915
  }
914
916
 
915
917
  console.log("WebAuthn: authenticated tenant '" + entry.agentId + "' handle '" + credentialLabel + "'");
@@ -3156,6 +3158,23 @@ httpServer.on("upgrade", (req, socket, head) => {
3156
3158
  let envelope = null;
3157
3159
  try { envelope = JSON.parse(text); } catch {}
3158
3160
  if (envelope?.type === "daemon.identity") {
3161
+ const reconnectPolicy = evaluateCodexDaemonReconnectPubkey(
3162
+ codexDaemonPubkeyRegistry.get(identity.agentId),
3163
+ envelope.daemon_public_key,
3164
+ );
3165
+ if (!reconnectPolicy.allowed) {
3166
+ console.warn(
3167
+ "codex-relay: rejected daemon reconnect E2EE key for tenant " + identity.agentId
3168
+ + " reason=" + reconnectPolicy.reason
3169
+ + " old=" + (reconnectPolicy.old_fingerprint || "<none>")
3170
+ + " new=" + (reconnectPolicy.new_fingerprint || codexDaemonPubkeyFingerprint(envelope.daemon_public_key) || "<none>"),
3171
+ );
3172
+ const closeReason = reconnectPolicy.replaced
3173
+ ? "daemon key change requires fresh pair"
3174
+ : "invalid daemon identity";
3175
+ try { ws.close(reconnectPolicy.replaced ? 4003 : 1008, closeReason); } catch {}
3176
+ return;
3177
+ }
3159
3178
  void codexDaemonPubkeyRegistry.register(
3160
3179
  identity.agentId,
3161
3180
  envelope.daemon_public_key,