Move the engine core into core/, a project of its own (pplus-core)

What programs mean (the languages, translators, Mojo checker and
interpreter, prover, fuzzer, machine model, catalog problems and the Mojo
corpus with godbolt's stored answers) was mixed into the site's tree, so a
change to the prover and a change to a button went through the same gate
and the same docs. This moves all of it under core/, laid out as its own
repository, ready to be extracted with its history and pinned here as a
git submodule.

- core/: src/{engines,services,sync,mojo,exercises,curriculum,common},
  mojo/, syntax/mojo.xml, its tests (with Workspace and workForProblem in
  place of the site's Session), scripts (corpus pipeline, play, the
  exercise and probe starters, engines export/diff), and its docs
  (engines, trust, mojo-corpus, exercises, coverage). Its own pixi.toml,
  package.json, README, AGENTS.md and CI workflow.
- core/tests/boundary.test.mjs: library modules use no DOM, import no
  page widget, and import nothing outside src/.
- core/scripts/cli.mjs: pixi run cli check|run|prove|fuzz|translate.
- core/scripts/dafny.py: Dafny 4.11.0 pinned by version and SHA-256 per
  platform, fetched into .tools/ (pixi run dafny-fetch, pixi run dafny).
- The site imports core only as #core/<path>.js: an import map in
  index.html, "imports" in package.json for node, core's declarations for
  tsc. The site's TypeScript builds core first (npm run build).
- assemble.sh, the Quarto engine copy, the render cache key, check-pages,
  quarto-export and quarto-css read core/dist and core/mojo; quarto-css
  copies core's syntax/mojo.xml into the extension.
- Site tests that covered engines moved to core; the rest keep Session.
- README, AGENTS.md, docs/app.md, docs/deploy.md and the CI workflow
  describe the split (checkout with submodules; core's tests and corpus
  status run against the pinned commit).

Gate: site 110 pass; core 307 pass; corpus status --strict passes.
Manual check: the assembled site opens Bridge (count-base-proved),
Developer and Hardware (count-base) with the editor, the stepper and the
board, and no module errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FgvbRdoEheAHqsRmr2WuKZ
This commit is contained in:
alexmandClaude committed 2026-10-05 05:43:58 +00:00
1 parent f43bbfe0cf
commit 82e18f7966
1567 files changed
+3670 -981

No files matched your search

+107
View File
@@ -0,0 +1,107 @@
#!/usr/bin/env node
/**
* pplus: pplus-core without a browser. The same engines, translators, prover and fuzzer the app runs, on a file.
*
* pixi run cli check <file> what the language's own reader says
* pixi run cli run <file> [--call C] [--input F] run it, print what it prints
* pixi run cli prove <file> [--speco F] every obligation: proved, broken or open
* pixi run cli fuzz <file> [--seed N] [--budget N] the fuzzer's report per routine
* pixi run cli translate <file.pseudo> --to mojo|lingo|matho|speco
*
* The language comes from the extension: .pseudo, .lingo, .matho (or .tex), .speco, .mojo, .asm (or .s). Add --json
* for machine-readable output. Exit status: 0 when nothing is wrong, 1 when the command found a problem (an error,
* a broken obligation, a failing input, a run that stopped), 2 for a usage error. Build first (`pixi run build`):
* this reads dist/.
*/
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
const ROOT = fileURLToPath(new URL('..', import.meta.url));
const dist = (p) => pathToFileURL(path.join(ROOT, 'dist', p)).href;
const usage = (why) => {
if (why) console.error(`pplus: ${why}`);
console.error('usage: pplus <check|run|prove|fuzz|translate> <file> [--call C] [--input F] [--speco F] [--seed N] [--budget N] [--to LANG] [--json]');
process.exit(2);
};
if (!fs.existsSync(path.join(ROOT, 'dist', 'common', 'workspace.js'))) usage('dist/ is missing; run `pixi run build` first');
const [cmd, file, ...rest] = process.argv.slice(2);
if (!cmd || !file) usage();
const opt = (name) => { const i = rest.indexOf(`--${name}`); return i >= 0 ? rest[i + 1] : undefined; };
const json = rest.includes('--json');
const LANG_OF = { '.pseudo': 'pseudo', '.lingo': 'lingo', '.matho': 'matho', '.tex': 'matho', '.speco': 'speco', '.mojo': 'mojo', '.asm': 'asm', '.s': 'asm' };
const lang = LANG_OF[path.extname(file).toLowerCase()];
if (!lang) usage(`cannot tell the language of ${file} from its extension (${Object.keys(LANG_OF).join(', ')})`);
if (!fs.existsSync(file)) usage(`${file} does not exist`);
const { Workspace } = await import(dist('common/workspace.js'));
const text = fs.readFileSync(file, 'utf8');
const sources = { [lang]: text };
const speco = opt('speco');
if (speco) sources.speco = fs.readFileSync(speco, 'utf8');
const input = opt('input') ? fs.readFileSync(opt('input'), 'utf8') : '';
const ws = new Workspace({ sources, lang, call: opt('call') ?? null, input });
const out = (obj, lines) => { if (json) console.log(JSON.stringify(obj, null, 2)); else for (const l of lines) console.log(l); };
const where = (d) => `${file}:${d.line ?? 1}:${d.col ?? 1}`;
switch (cmd) {
case 'check': {
const ds = ws.diagnostics(lang);
out(ds, ds.length ? ds.map((d) => `${where(d)}: ${d.severity}: ${d.message}${d.id ? ` [${d.id}]` : ''}`) : [`${file}: no problems`]);
process.exit(ds.some((d) => d.severity === 'error') ? 1 : 0);
}
case 'run': {
const errors = ws.diagnostics(lang).filter((d) => d.severity === 'error');
if (errors.length) { out({ errors }, errors.map((d) => `${where(d)}: error: ${d.message}`)); process.exit(1); }
const tr = ws.trace();
if (!tr) { out({ error: ws.runError ?? 'nothing to run' }, [`pplus: ${ws.runError ?? 'nothing to run'}`]); process.exit(1); }
const lines = [...(tr.output ?? [])];
if (tr.error) lines.push(`stopped at line ${tr.error.line}: ${tr.error.message}`);
out({ output: tr.output, error: tr.error, steps: tr.count }, lines);
process.exit(tr.error ? 1 : 0);
}
case 'prove': {
if (lang !== 'pseudo') usage('prove reads a .pseudo file (with --speco for a separate spec)');
const p = ws.proof();
if (!p) { out({ error: 'the pseudo does not parse' }, ['pplus: the pseudo does not parse; run `pplus check` first']); process.exit(1); }
const { report } = p;
const lines = [];
for (const u of report.units) {
lines.push(`${u.name}${u.partial ? ' (partial: not every path was examined)' : ''}`);
for (const o of u.obligations) lines.push(` ${o.status.padEnd(6)} line ${String(o.line).padEnd(4)} ${o.label}`);
for (const n of u.notes) lines.push(` note: ${n}`);
}
lines.push(`${report.counts.proved} proved, ${report.counts.broken} broken, ${report.counts.open} open`);
out(report, lines);
process.exit(report.counts.broken ? 1 : 0);
}
case 'fuzz': {
const reports = ws.fuzz({ seed: Number(opt('seed') ?? 1), budget: Number(opt('budget') ?? 300) });
const lines = [];
for (const r of reports) {
if (r.problem) { lines.push(`${r.name}: ${r.problem}`); continue; }
lines.push(`${r.name}: ${r.cases.length} cases, ${r.failures.length} failure${r.failures.length === 1 ? '' : 's'}`);
for (const f of r.failures) lines.push(` ${f.call}: ${f.message}`);
}
out(reports.map((r) => ({ name: r.name, problem: r.problem, cases: r.cases.length, failures: r.failures })), lines.length ? lines : [`${file}: no routine to fuzz`]);
process.exit(reports.some((r) => r.failures.length) ? 1 : 0);
}
case 'translate': {
if (lang !== 'pseudo') usage('translate reads a .pseudo file');
const to = opt('to');
let result;
if (to === 'mojo') result = ws.derivedMojo();
else if (to === 'speco') { const { extractSpec } = await import(dist('services/speco.js')); result = { source: extractSpec(text) ?? '' }; }
else if (to === 'lingo' || to === 'matho') {
const { SyncHub } = await import(dist('sync/hub.js'));
const f = new SyncHub({ pseudo: text }).fill();
result = { source: f.sources[to] ?? '', stale: f.stale[to] };
} else usage('--to must be mojo, lingo, matho or speco');
if (result.stale) { out({ refused: result.stale }, [`pplus: ${to} cannot say this program: ${result.stale}`]); process.exit(1); }
if (json) console.log(JSON.stringify(result, null, 2)); else process.stdout.write(result.source.endsWith('\n') ? result.source : result.source + '\n');
process.exit(0);
}
default: usage(`unknown command ${cmd}`);
}