chadtmiller.com/hud
A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts
place.hud.hudkit 0.3.1 Latest 5 packages
0
0
// HUD against a PDS of its own, kept running to try by hand: the e2e
// world (harness/e2e/world.mjs: the reference PDS and PLC with alice, bob
// and carol, seeded, and `target/debug/hud serve` over them with sign-in
// on, behind its https front at harness/tls.mjs's HOST), and a Chromium
// window that reaches that hostname on loopback and trusts HUD's
// certificate, at the workspace. Sign in with a DID or `<name>.test`, then
// the PDS's own page, with `password`.
//
// --spaces: the PDS is the spaces alpha (harness/spaces), and HUD keeps
// each person's canvases in their own spaces (HUD_SPACES=on).
//
// --ios [--device <name>]: the iOS app too, on a simulator (iPhone 17 Pro
// by default), built, installed, trusting this checkout's authority
// (harness/tls.mjs), and launched at the HUD running here. The simulator
// resolves names as the Mac does, so HOST must reach 127.0.0.1 there:
// `just local-setup` puts it in /etc/hosts, once.
//
// node harness/local.mjs [--spaces] [--ios [--device <name>]]
// `just local`, `just local --spaces --ios`
//
// Prints where everything is and who can sign in; stops with ctrl-c, or
// when the window is closed. HUD's log goes to target/e2e/hud.log.
import { execFileSync, execSync } from 'node:child_process';
import { lookup } from 'node:dns/promises';
import { existsSync } from 'node:fs';
import { join } from 'node:path';
import { chromium } from 'playwright';
import { root, start } from './e2e/world.mjs';
import { HOST } from './tls.mjs';
const arg = (name) => {
const i = process.argv.indexOf(name);
return i === -1 ? undefined : process.argv[i + 1];
};
const spaces = process.argv.includes('--spaces');
const ios = process.argv.includes('--ios');
const device = arg('--device') ?? 'iPhone 17 Pro';
if (spaces) {
const devEnv = 'harness/spaces/node_modules/@atproto/dev-env';
if (!existsSync(join(root, devEnv))) {
console.error('No spaces alpha yet: `just local-setup`, or cd harness/spaces && npm ci');
process.exit(1);
}
process.env.HUD_DEV_ENV = devEnv;
}
if (ios) {
const found = await lookup(HOST).catch(() => null);
if (found?.address !== '127.0.0.1') {
console.error(`${HOST} does not reach 127.0.0.1 on this Mac, so the simulator cannot reach HUD: \`just local-setup\` once.`);
process.exit(1);
}
}
const world = await start();
let stopping = false;
const stop = () => {
if (stopping) return;
stopping = true;
world.stop();
process.exit(0);
};
process.on('SIGINT', stop);
process.on('SIGTERM', stop);
// The certificate's public key, as Chromium's --ignore-certificate-errors-spki-list takes it.
const spki = execSync(`openssl x509 -in '${world.cert}' -pubkey -noout | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | base64`)
.toString()
.trim();
const browser = await chromium.launch({
headless: false,
args: [`--host-resolver-rules=MAP ${world.host} 127.0.0.1`, `--ignore-certificate-errors-spki-list=${spki}`],
});
browser.on('disconnected', stop);
// No emulated colour scheme (Playwright's is light): the window follows the Mac's.
const context = await browser.newContext({ viewport: null, colorScheme: null });
const page = await context.newPage();
await page.goto(`${world.base}/workspace`);
if (ios) launchApp();
const rows = world.accounts.map((a) => ` ${a.handle.padEnd(12)} ${a.did} password ${a.password}`);
console.log(
[
`HUD ${world.base}/workspace (in the window${ios ? ', and the simulator' : ''})`,
` ${world.hudUrl} (plain http, for curl and the MCP endpoint)`,
`PDS ${world.pds}${world.spaces ? ' (spaces alpha: canvases in spaces)' : ''}`,
`PLC ${world.plc}`,
'Sign in with a handle or DID, then the password, on the PDS’s own page:',
...rows,
'Log: target/e2e/hud.log. Stop: ctrl-c, or close the window.',
].join('\n'),
);
/// The iOS app on the simulator `device`: booted, trusting the authority,
/// built, installed and launched at this HUD (`-server`).
function launchApp() {
const run = (cmd, args, opts = {}) => execFileSync(cmd, args, { stdio: ['ignore', 'pipe', 'inherit'], ...opts }).toString();
const all = JSON.parse(run('xcrun', ['simctl', 'list', 'devices', 'available', '-j'])).devices;
const sim = Object.values(all)
.flat()
.find((d) => d.name === device);
if (!sim) throw new Error(`No simulator named ${device}: xcrun simctl list devices available`);
if (sim.state !== 'Booted') run('xcrun', ['simctl', 'boot', sim.udid]);
run('xcrun', ['simctl', 'bootstatus', sim.udid, '-b']);
run('open', ['-a', 'Simulator']);
run('xcrun', ['simctl', 'keychain', sim.udid, 'add-root-cert', world.ca]);
console.log(`Building the iOS app for ${device}…`);
const ios = join(root, 'ios');
run('xcodegen', ['generate', '--quiet'], { cwd: ios });
run('xcodebuild', ['-project', 'HUD.xcodeproj', '-scheme', 'HUD', '-destination', `platform=iOS Simulator,id=${sim.udid}`, '-derivedDataPath', '../target/ios', '-quiet', 'build'], { cwd: ios });
const app = join(root, 'target/ios/Build/Products/Debug-iphonesimulator/HUD.app');
const bundle = run('/usr/libexec/PlistBuddy', ['-c', 'Print CFBundleIdentifier', join(app, 'Info.plist')]).trim();
run('xcrun', ['simctl', 'install', sim.udid, app]);
run('xcrun', ['simctl', 'launch', '--terminate-running-process', sim.udid, bundle, '-server', world.base]);
console.log(`The app is open on ${device} at ${world.base}, at its sign-in.`);
}