Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scripts/defrag-terminology.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
callClaude,
checkLinksPreserved,
checkCodeRegionsPreserved,
normalizePackageNames,
} from "./lib/defrag-utils.mjs";
import { join } from "path";

Expand Down Expand Up @@ -108,6 +109,7 @@ async function main() {
);

let normalized = corrected.replace(/\n*$/, "\n");
normalized = normalizePackageNames(normalized);

if (normalized === original) {
console.log(` No changes.`);
Expand Down
64 changes: 64 additions & 0 deletions scripts/lib/defrag-utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,70 @@ export function checkCodeRegionsPreserved(original, corrected) {
return { ok: mismatches.length === 0, mismatches };
}

/**
* Lowercase `Dojo.<platform>` package identifiers back to `dojo.<platform>`
* in prose. Skips fenced code blocks, inline code spans, and markdown link
* targets. The LLM terminology pass tends to proper-noun these even though
* the real repo/package names are lowercase (e.g., github.com/dojoengine/dojo.unreal).
*/
export function normalizePackageNames(content) {
const PACKAGE_RE = /\bDojo\.(unreal|unity|js|c|bevy|godot)\b/g;
const lowercase = (s) => s.replace(PACKAGE_RE, (_, p) => `dojo.${p}`);

const out = [];
let inBlock = false;
for (const line of content.split("\n")) {
if (line.trimStart().startsWith("```")) {
inBlock = !inBlock;
out.push(line);
continue;
}
if (inBlock) {
out.push(line);
continue;
}
out.push(lowercaseInProseLine(line, lowercase));
}
return out.join("\n");
}

function lowercaseInProseLine(line, lowercase) {
let result = "";
let i = 0;
while (i < line.length) {
if (line[i] === "`") {
const end = line.indexOf("`", i + 1);
if (end === -1) {
result += line.slice(i);
return result;
}
result += line.slice(i, end + 1);
i = end + 1;
continue;
}
if (line[i] === "]" && line[i + 1] === "(") {
const end = line.indexOf(")", i + 2);
if (end === -1) {
result += line.slice(i);
return result;
}
result += line.slice(i, end + 1);
i = end + 1;
continue;
}
let next = line.length;
for (let j = i; j < line.length; j++) {
if (line[j] === "`" || (line[j] === "]" && line[j + 1] === "(")) {
next = j;
break;
}
}
result += lowercase(line.slice(i, next));
i = next;
}
return result;
}

/**
* Check if any single diff hunk exceeds the size limit.
*/
Expand Down
Loading