Something went wrong. Try again.
Cube algorithm explorer
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135#!/usr/bin/env tsx
/** * Boots a local AT Protocol network (PDS + PLC), the dev microcosm stub, * `.test` accounts, and bundled walkthrough seeds as `at.protocube.walkthrough` * records. Ephemeral — DIDs change every boot; handles are stable within a run. * * Open the Nuxt app at `http://[::1]:3000` (IPv6 loopback), not localhost. * * pnpm dev:network boot fresh; reuses any .dev/ stub index * pnpm dev:network:clean same, after wiping persistent .dev/ state */
import { createDevNetwork } from './lib/dev-network-boot';import { ensureDevAccounts } from './lib/ensure-dev-accounts';import { DEV_STATE_DIR, resetDevState } from './lib/reset-dev-state';import { runDevSeed } from './lib/run-dev-seed';import { startMicrocosmStub } from './microcosm-stub/server';
const APP_URL = process.env.APP_URL ?? 'http://[::1]:3000';
const ACCOUNTS = [ { shortName: 'alice', handle: 'alice.test', email: 'alice@test.com', password: 'alice-pass-123', displayName: 'Alice Test', }, { shortName: 'bob', handle: 'bob.test', email: 'bob@test.com', password: 'bob-pass-123', displayName: 'Bob Test', },];
async function main(): Promise<void> { if (process.argv.includes('--clean')) { const { removed } = resetDevState(); console.log( removed ? `Cleared persistent dev state (${DEV_STATE_DIR}/).\n` : `Clean boot — ${DEV_STATE_DIR}/ was already empty.\n`, ); }
console.log('Starting local AT Protocol network + microcosm stub...\n');
const network = await createDevNetwork(); const pdsUrl = network.pds.url; const plcUrl = network.plc.url;
console.log(`PDS running at: ${pdsUrl}`); console.log(`PLC running at: ${plcUrl}`); console.log(`DEV_PDS_URL=${pdsUrl}`); console.log(`DEV_PLC_URL=${plcUrl}\n`);
const stub = await startMicrocosmStub({ pdsUrl, plcUrl });
const dids = await ensureDevAccounts(network, ACCOUNTS); await network.processAll();
console.log('Seeding bundled walkthroughs...\n'); const seed = await runDevSeed({ pdsUrl, dids });
for (const account of ACCOUNTS) { await fetch( `${stub.url}/xrpc/blue.microcosm.identity.resolveMiniDoc?identifier=${encodeURIComponent(account.handle)}`, ); }
// Let the firehose catch up before printing smoke hints. await sleep(2000);
const bar = '═'.repeat(60); console.log(`\n${bar}`); console.log(` Open the app at: ${APP_URL}`); console.log(` Dev PDS: ${pdsUrl}`); console.log(` Microcosm stub (reads): ${stub.url}`); console.log(`${bar}`); console.log( ' IMPORTANT: use exactly the IPv6 loopback app URL above.\n' + ' http://localhost:3000 breaks OAuth — the PDS rejects same-site authorize.\n', );
console.log('--- Test accounts ---\n'); for (const account of ACCOUNTS) { const did = dids[account.shortName]; console.log(` ${account.handle}`); console.log(` DID: ${did}`); console.log(` Email: ${account.email}`); console.log(` Password: ${account.password}`); console.log(''); }
if (seed.publishedUris[0]) { const sampleUri = seed.publishedUris[0]; console.log('--- Stub smoke (curl) ---\n'); console.log( ` curl -s '${stub.url}/xrpc/blue.microcosm.repo.getRecordByUri?at_uri=${encodeURIComponent(sampleUri)}' | jq .uri`, ); console.log( ` curl -s '${stub.url}/xrpc/blue.microcosm.identity.resolveMiniDoc?identifier=alice.test' | jq .did,.pds`, ); console.log( ` curl -s '${stub.url}/xrpc/blue.microcosm.links.getBacklinks?subject=tag:protocube&source=at.protocube.walkthrough:tags%5B%5D&limit=5' | jq .total,.records`, ); console.log(''); }
console.log('Network + stub running. Press Ctrl+C to stop.\n');
const shutdown = async () => { console.log('\nShutting down...'); await stub.close(); await network.close(); process.exit(0); }; process.on('SIGINT', () => void shutdown()); process.on('SIGTERM', () => void shutdown());
await new Promise(() => {});}
function sleep(ms: number): Promise<void> { return new Promise((resolve) => setTimeout(resolve, ms));}
main().catch((err) => { console.error('Fatal error:', err); process.exit(1);});