wishforge-ide/apps/ide/collaboration/start-isolated.mjs
eust-w 0ef99b1e6d style: add Prettier and EditorConfig, format the codebase
Adds prettier 3.9.8 (exact) with a shared config (single quotes,
120 columns, trailing commas), .prettierignore, .editorconfig and the
`format` / `format:check` scripts, then formats all TypeScript,
JavaScript, CSS, JSON and YAML sources.

Purely mechanical: no behaviour change. Typecheck passes, the vitest
suite and the 74 IDE node tests produce the same results as before
(socket-binding tests still cannot run inside this sandbox).
Previously the longest source line was ~3000 characters; reviewing the
following semantic changes now produces readable diffs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 13:32:43 +08:00

35 lines
2.1 KiB
JavaScript

import 'reflect-metadata';
import { randomBytes, webcrypto } from 'node:crypto';
import { Container } from 'inversify';
import { initializeProtocol } from 'open-collaboration-protocol';
import { CollaborationServer, CredentialsManager, AuthEndpoint, SimpleLoginEndpoint } from 'open-collaboration-server';
const id = value => typeof value === 'string' && /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,199}$/.test(value);
if (!id(process.env.WF_WORKSPACE_ID) || !id(process.env.WF_TENANT_ID))
throw new Error('Each OCT instance requires its own WF_WORKSPACE_ID and WF_TENANT_ID');
const hostname = process.env.WF_OCT_HOST ?? '127.0.0.1';
if (!['127.0.0.1', '0.0.0.0'].includes(hostname)) throw new Error('Invalid isolated OCT listen address');
if (hostname !== '127.0.0.1' && process.env.WISHFORGE_GATEWAY_ENFORCED !== 'true')
throw new Error('Network binding requires an enforced workspace gateway and default-deny network policy');
const port = Number(process.env.WF_OCT_PORT ?? 8100);
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error('Invalid isolated OCT port');
// Never use OCT's shared development signing key. A restart invalidates all room
// capabilities because upstream room state is in memory and cannot be recovered.
process.env.OCT_JWT_PRIVATE_KEY = randomBytes(48).toString('base64url');
process.env.OCT_ACTIVATE_SIMPLE_LOGIN = 'true';
process.env.OCT_SERVER_OWNER = `WishForge workspace ${process.env.WF_WORKSPACE_ID}`;
initializeProtocol({ cryptoModule: webcrypto });
const { default: serverModule } = await import(
new URL('./inversify-module.js', import.meta.resolve('open-collaboration-server')).href
);
const container = new Container();
container.load(serverModule);
// This deployment deliberately has one display-name form behind the gateway;
// no external OAuth providers or account registration flows are activated.
container.rebind(AuthEndpoint).toService(SimpleLoginEndpoint);
const credentials = container.get(CredentialsManager);
credentials.getJwtExpiration = async () => '8h';
const server = container.get(CollaborationServer);
// Call the typed API instead of the 0.3.1 Commander parseInt/radix port bug.
server.startServer({ hostname, port });