mirror of
https://github.com/garrytan/gbrain.git
synced 2026-07-31 04:07:52 +00:00
Contributor DX magical moment. Static HTML explorer renders the full
canonical world (240 entities) as an explorable tree, opens in any browser,
zero install. Every string HTML-entity-encoded (XSS-safe — direct vuln
class per eng pass 2, confidence 9/10).
Added:
eval/generators/world-html.ts — renderer (~240 LOC; single-file
HTML with inline CSS + minimal JS)
eval/generators/world-html.test.ts — 16 tests (XSS + rendering correctness)
eval/cli/world-view.ts — render + open in default browser
eval/cli/query-validate.ts — CLI wrapper for queries/validator
eval/cli/query-new.ts — scaffold a query template
Modified:
package.json — 7 new eval:* scripts
.gitignore — ignore generated world.html
package.json scripts shipped:
bun run test:eval all eval unit tests (57 pass)
bun run eval:run full 4-adapter N=5 side-by-side
bun run eval:run:dev N=1 fast dev iteration
bun run eval:world:view render world.html + open in browser
bun run eval:world:render render only (CI-friendly, --no-open)
bun run eval:query:validate validate built-in T5+T5.5 (or a file path)
bun run eval:query:new scaffold a new Query JSON template
bun run eval:type-accuracy per-link-type accuracy report
XSS safety:
escapeHtml() encodes the 5 critical chars (& < > " '). Tested directly
with representative Opus-generated attacks:
<img src=x onerror=alert('xss')> → <img src=x onerror=alert('xss')>
<script>fetch('/steal')</script> → <script>fetch('/steal')</script>
Ledger metadata (generated_at, model) also escaped — covers the less
obvious attack surface where Opus could emit tag-like content into the
metadata file.
world.html structure:
- Left rail: entities grouped by type with counts (companies, people,
meetings, concepts), alphabetical within type
- Right pane: per-entity cards with title + slug + compiled_truth +
timeline + canonical _facts as collapsed JSON
- URL fragment deep-links (#people/alice-chen)
- Sticky rail on desktop; responsive stack on mobile
- Vanilla JS for active-link highlighting on scroll (no framework)
Generated file: ~1MB for 240 entities (full prose). Gitignored; rebuild
with `bun run eval:world:view`. Regeneration is ~50ms.
Contributor TTHW (Tier 5.5 query authoring):
1. bun run eval:world:view # see entities
2. bun run eval:query:new --tier externally-authored --author "@me"
3. edit template with real slug + query text
4. bun run eval:query:validate path/to/file.json
5. submit PR
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
65 lines
2.1 KiB
TypeScript
65 lines
2.1 KiB
TypeScript
#!/usr/bin/env bun
|
|
/**
|
|
* eval:world:view — (re)generate world.html and open it in the default browser.
|
|
*
|
|
* Combines two steps the contributor shouldn't have to think about:
|
|
* 1. Render eval/data/world-v1/world.html from the shard JSONs.
|
|
* 2. Open it in the default browser via `open` (macOS) / `xdg-open` (Linux).
|
|
*
|
|
* If the HTML already exists and shards haven't changed since, we'd ideally
|
|
* skip step 1 — but comparing timestamps is fragile and regeneration is fast
|
|
* (~50ms on 240 entities). Just regenerate every time.
|
|
*
|
|
* Usage:
|
|
* bun run eval:world:view (generates + opens)
|
|
* bun run eval:world:view --no-open (generates only; useful in CI)
|
|
*/
|
|
|
|
import { execSync } from 'child_process';
|
|
import { platform } from 'os';
|
|
import { renderWorldHtmlToFile } from '../generators/world-html.ts';
|
|
|
|
function openInBrowser(path: string): void {
|
|
const cmd = platform() === 'darwin' ? 'open' : platform() === 'win32' ? 'start' : 'xdg-open';
|
|
try {
|
|
execSync(`${cmd} "${path}"`, { stdio: 'ignore' });
|
|
} catch (e) {
|
|
// Don't fail hard — the file is rendered, that's the main thing.
|
|
console.error(`Could not open browser automatically. Open manually: ${path}`);
|
|
console.error(`(${(e as Error).message})`);
|
|
}
|
|
}
|
|
|
|
async function main() {
|
|
const args = process.argv.slice(2);
|
|
if (args.includes('--help') || args.includes('-h')) {
|
|
console.log(`eval:world:view — render + open world.html
|
|
|
|
USAGE
|
|
bun run eval:world:view render eval/data/world-v1/world.html and open it
|
|
bun run eval:world:view --no-open render only (CI-friendly)
|
|
bun run eval:world:view --dir=PATH render from a different shard directory
|
|
|
|
OUTPUT
|
|
eval/data/world-v1/world.html (gitignored; regenerate with this command).
|
|
`);
|
|
return;
|
|
}
|
|
|
|
const dir = args.find(a => a.startsWith('--dir='))?.slice('--dir='.length) ??
|
|
'eval/data/world-v1';
|
|
const noOpen = args.includes('--no-open');
|
|
|
|
const target = renderWorldHtmlToFile(dir);
|
|
console.log(`Rendered ${target}`);
|
|
|
|
if (!noOpen) {
|
|
openInBrowser(target);
|
|
}
|
|
}
|
|
|
|
main().catch(e => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
});
|