Lines 1-24javascript
1// server.js — the local bridge server.
2// Serves a document OR a whole folder (e.g. the project brain), injecting the on-page
3// toolbar at response time only, relaying page → Claude turns, streaming status over SSE,
4// and live-reloading the affected page when its file changes.
5import { createServer } from 'node:http';
6import { readFile, writeFile, readFileSync, writeFileSync, watch, copyFileSync, mkdirSync, existsSync, realpathSync } from 'node:fs';
LowWeak Crypto
Package source references weak cryptographic algorithms.
src/server.jsView on unpkg · L4 7import { join, dirname, basename, extname, normalize, sep } from 'node:path';
8import { fileURLToPath } from 'node:url';
9import { randomUUID, createHash } from 'node:crypto';
10import { runTurn } from './claude.js';
11import { replaceInner, removeElement, moveElement } from './edit.js';
13const HERE = dirname(fileURLToPath(import.meta.url));
14const PUBLIC = join(HERE, '..', 'public');
17 '.html': 'text/html; charset=utf-8', '.js': 'text/javascript', '.css': 'text/css',
18 '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.gif': 'image/gif',
19 '.svg': 'image/svg+xml', '.webp': 'image/webp', '.json': 'application/json',
22// `target` is a file (single-doc mode) or a directory (folder/brain mode, opts.brain=true).
23export function startServer(target, port, opts = {}) {
24 const isDir = !!opts.brain;