SNAPKITTYWEST's picture
push from SNAPKITTYWEST/snapkitty-clojure-lisp-bridge
119e586 verified
Raw History Blame Contribute Delete
5.26 kB
// Gravity-to-Forth renderer.
// Takes a repo topology (from AHMAD-BOT S-expression output)
// and renders it as Forth source β€” the ancient meta-repo format.
// The output IS the inverted documentation. Executable. Sovereign.
export function renderRepoAsForth(repoName, clusters, gravity, gaps) {
const lines = [];
lines.push(`\\ INVERTED META-REPO β€” ${repoName}`);
lines.push(`\\ Generated by AHMAD-BOT + Forth renderer`);
lines.push(`\\ Gravity: ${gravity} | Gaps: ${gaps.length}`);
lines.push(`\\ This file IS the repository's architectural truth.`);
lines.push(`\\ Feed it to the Forth machine. It will reason about the repo.`);
lines.push('');
lines.push('( ── CONSTANTS ── )');
lines.push(`variable repo-gravity`);
lines.push(`${gravity} repo-gravity !`);
lines.push('');
lines.push('( ── CLUSTER WORDS ── )');
for (const cluster of clusters) {
const safeName = cluster.id.replace(/[^a-z0-9-]/gi, '-').toLowerCase();
lines.push(`\\ cluster: ${cluster.id} | gravity: ${cluster.gravity} | status: ${cluster.status}`);
lines.push(`: ${safeName} ( -- )`);
lines.push(` ${cluster.gravity} gravity`);
if (cluster.status === 'alive') {
lines.push(` alive? IF`);
lines.push(` ." ${cluster.id} [alive] gravity=${cluster.gravity} " cr`);
lines.push(` THEN`);
} else if (cluster.status === 'broken') {
lines.push(` broken? IF`);
lines.push(` ." ${cluster.id} [broken] needs repair " cr`);
lines.push(` "${cluster.id}" repair`);
lines.push(` THEN`);
} else {
lines.push(` orphan? IF`);
lines.push(` ." ${cluster.id} [orphan] β€” grave marker " cr`);
lines.push(` "${cluster.id}" flag`);
lines.push(` THEN`);
}
lines.push(`;`);
lines.push('');
}
lines.push('( ── GAP WORDS ── )');
for (const gap of gaps) {
const safeName = `gap-${gap.type}-${gap.path.replace(/[^a-z0-9]/gi, '-').toLowerCase()}`.slice(0, 40);
lines.push(`: ${safeName} ( -- )`);
lines.push(` ." GAP [${gap.type}] @ ${gap.path} " cr`);
lines.push(` ." FIX: ${gap.fix} " cr`);
if (['missing_wire', 'dead_page'].includes(gap.type)) {
lines.push(` "${gap.path}" flag`);
} else {
lines.push(` "${gap.path}" repair`);
}
lines.push(`;`);
lines.push('');
}
lines.push('( ── INVERSION SEQUENCE ── )');
lines.push(`: run-inversion ( -- )`);
lines.push(` ." === INVERTING ${repoName} ===" cr`);
lines.push(` repo-gravity @`);
lines.push(` dup 0.6 > IF`);
lines.push(` ." repo is alive β€” inverting to sovereign format " cr`);
lines.push(` "${repoName}" invert-repo`);
lines.push(` ELSE`);
lines.push(` dup 0.3 > IF`);
lines.push(` ." repo is broken β€” repair before inversion " cr`);
lines.push(` ELSE`);
lines.push(` ." repo is orphan β€” grave marker set " cr`);
lines.push(` THEN`);
lines.push(` THEN`);
lines.push(` drop`);
// Call all cluster words
for (const cluster of clusters) {
const safeName = cluster.id.replace(/[^a-z0-9-]/gi, '-').toLowerCase();
lines.push(` ${safeName}`);
}
// Call all gap words
for (const gap of gaps) {
const safeName = `gap-${gap.type}-${gap.path.replace(/[^a-z0-9]/gi, '-').toLowerCase()}`.slice(0, 40);
lines.push(` ${safeName}`);
}
lines.push(` "${repoName}" seal`);
lines.push(`;`);
lines.push('');
lines.push('( ── ENTRY POINT ── )');
lines.push('run-inversion');
return lines.join('\n');
}
// Render a full org crawl as a multi-repo Forth suite
export function renderOrgAsForth(org, repos) {
const sections = [];
sections.push(`\\ GRAVEYARD MAP β€” ${org}`);
sections.push(`\\ ${repos.length} repos | rendered by AHMAD-BOT + Forth renderer`);
sections.push(`\\ The graveyard in Forth. Every repo is a word.`);
sections.push('');
for (const repo of repos) {
const name = repo.name.replace(/[^a-z0-9-]/gi, '-').toLowerCase();
sections.push(`\\ ── ${repo.name} (gravity: ${repo.gravity}, status: ${repo.status}) ──`);
sections.push(`: crawl-${name} ( -- )`);
sections.push(` ${repo.gravity} gravity`);
sections.push(` dup alive? IF`);
sections.push(` ." ${repo.name} alive " cr`);
sections.push(` ELSE dup broken? IF`);
sections.push(` ." ${repo.name} broken " cr`);
sections.push(` "${repo.name}" repair`);
sections.push(` ELSE`);
sections.push(` ." ${repo.name} orphan " cr`);
sections.push(` "${repo.name}" flag`);
sections.push(` THEN THEN`);
sections.push(` drop`);
sections.push(`;`);
sections.push('');
}
// Master crawl word
sections.push(`: crawl-graveyard ( -- )`);
sections.push(` ." === ${org} GRAVEYARD CRAWL ===" cr`);
for (const repo of repos) {
const name = repo.name.replace(/[^a-z0-9-]/gi, '-').toLowerCase();
sections.push(` crawl-${name}`);
}
sections.push(` ." === CRAWL COMPLETE ===" cr`);
sections.push(`;`);
sections.push('');
sections.push('crawl-graveyard');
return sections.join('\n');
}