Skip to content

bar-fmt: lua codemod, workspace integration, LLM type-triage (rollup) - #57

Open
keithharvey wants to merge 11 commits into
beyond-all-reason:masterfrom
keithharvey:bar-fmt-03-llm
Open

bar-fmt: lua codemod, workspace integration, LLM type-triage (rollup)#57
keithharvey wants to merge 11 commits into
beyond-all-reason:masterfrom
keithharvey:bar-fmt-03-llm

Conversation

@keithharvey

@keithharvey keithharvey commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

The bar-fmt migration as one PR (19 commits at the stack tip): bar-lua-codemod tooling and tests, workspace integration (check recipes, editor wiring, migrate::stylua-cleanup, the generic bar::restack stack rebaser), the LLM type-triage layer with the generation capstone, and the migrate:: moves that host every pipeline branch and PR on the canonical repo (#8395–#8410).

@@ -0,0 +1,185 @@
# Type Triage Worker Prompt (OpenAI variant)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think this file is good to include, mostly as a blueprint for how to do this sort of subagent/orchestrator script in the future. This PR does new things so having the some sub-agent stuff in claude/ provides helpful rails for future folks trying the same thing.

@@ -0,0 +1,1084 @@
---

@keithharvey keithharvey Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the skill file so subagents bail if they don't hit a known rule while walking through EmmyLua errors.

LuaParser, LuaStringToken, LuaSyntaxKind, LuaSyntaxNode, LuaSyntaxToken, LuaSyntaxTree,
LuaTokenKind, ParserConfig,
};
use std::collections::HashMap;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CST is "Concrete Syntax Tree" as in we don't throw away whitespace, comments, or exact token positions.

bar-lua-codemod parses BAR Lua with emmylua_parser (the same front-end
family as emmylua_check/emmylua_ls) at Lua51, doc-comment analysis off.
Transforms collect byte-range edits over the rowan CST and splice them
into the original source, so untouched bytes are untouched by
construction. cst.rs carries the shared helpers: parse gate on
SyntaxError-kind diagnostics only, bracketed-string-key extraction that
tolerates trivia, and the function-declaration-name exclusion.
codemod-cargo.sh runs cargo inside bar-dev, where the toolchain lives.
x["y"] -> x.y and ["y"] = -> y = for string keys that are valid,
non-reserved identifiers. Raw quoted content only — escapes and long
strings never convert. Injects a space when ] abutted a word character
so .identifier doesn't merge with what follows.
Spring.GetMyTeamID / GetMyAllyTeamID / GetMyPlayerID -> the canonical
GetLocal* names, wherever the prefix is the bare Spring global. Bracket
access and non-Spring prefixes are left alone.
Spring.I18N / Utilities / Debug / Lava / GetModOptionsCopy — BAR's own
helpers riding the Spring table — move to the BAR namespace. Handles the
_G.Spring.Module spelling too; function-declaration names stay put.
0.24.0 is what the current tangzx.emmylua VS Code extension bundles as
its language server, so `just bar::check` and the editor run the same
analyzer instead of sitting two minor versions apart.

Upstream renamed the aarch64 release assets from arm64 to aarch64
between 0.22.0 and 0.24.0; x86_64 names are unchanged, so the version
bump alone would 404 an ARM build. BAR's CI workflows do not pin
emmylua, so there is no lockstep constraint here.
bar::check / bar::check-errors run emmylua_check inside bar-dev against
BAR's .emmyrc.json; check-errors re-derives its exit code from the error
count so warnings and hints stay local instead of failing CI. Adds the
devtools .emmyrc.json, points the VS Code template at the exported
emmylua wrappers, and makes distrobox a hard setup requirement — the
whole toolchain lives in the container.

bar::setup-hooks installs a pre-commit hook that checks the staged blobs
instead of rewriting the working tree. What git records is what gets
checked; staged content is always LF, so .gitattributes eol and stylua's
line_endings can disagree without breaking the gate. It refuses rather
than reformatting — a hook that edits the tree mid-commit changes what
you are committing.
bar::codemod-build / codemod-test wrap codemod-cargo.sh. Migrations get
their own bar::migrate:: namespace — adoption-dated entries listed in
order, retired to [private] ~6 months after adoption. The 2026-07
stylua-cleanup entry replays the transform set (bracket-to-dot,
rename-aliases, detach-bar-modules) plus stylua onto the local BAR
checkout — the idempotent "transform your branch, then merge" path the
README callout documents.

Codemod runs carry the .styluaignore skip set explicitly: common/luaUtilities,
.lux, recoil-lua-library, mapgenerator. mapgenerator/mapinfo_template.lua
is a ${} placeholder template, not parseable Lua.

CODEMOD_BIN reads the environment. `set export` puts every variable into
the environment of every recipe, so a recipe shelling out to
bar::migrate::* would otherwise override the binary its own caller named
— sending CI back to a cargo build instead of the one baked into the
migration image, and still going green.
lua-doc-extractor also walks rts/Sim/Units/Scripts, so the generated
library covers the unit-script API that emmylua_check needs to resolve.

clean_dir removes the directory itself, so it has to run before the
mkdir, not after it.
llm-type-triage.sh chunks emmylua_check errors and dispatches parallel
LLM workers (claude --print, or the openai worker via BACKEND=openai —
hence python3-pip in bar-dev) that fix annotations per file. The
codemod-prereq SKILL.md is the categorization rulebook: error pattern ->
idempotent fix recipe, first match wins. claude/claude.md carries the
cross-repo agent context.

The type-fixes-preserve-behavior skill is the standing rule for that
work: a type fix may change types and names, never behavior. It encodes
the gui_chat.lua regression that shipped a widget which would not load.

Git dir resolves via rev-parse — a worktree's .git is a file, not a
directory.
generate-branches.sh deterministically rebuilds fmt, the mig-* leaves,
the mig rollup, and the fmt-llm capstone (env layer + gen(llm) commit),
with PR-body generation, the museum table, and stacked-PR base
overrides. bar::migrate::stylua-cleanup-generate fronts it ([private] —
generation stays out of the listing), wrapping execution in
$CREDENTIALS_RUNNER so the triage workers inherit LLM-backend
credentials; the tracking-issue template ties the PR stack together.

Every pipeline branch and PR hosts on the canonical repo. GitHub's
native stacks reject fork-headed PRs and lock --base edits, so PR edits
omit --base when it already matches, and the museum links, the tracking
checklist and the Bulk Migrations doc link all point at the same-repo
PRs (#8395-#8410).

--push and --update-prs are one transaction in both directions: museum
SHAs and branches move together or not at all. A branch that sits on its
PR base is never pushed. Blame-ignore revs are read off the branch
rather than the build loop.

stylua runs on the host, where git writes. The script re-execs itself
from its file path with stdin on /dev/null once inside the container:
enter_distrobox otherwise feeds the script itself on stdin, and any
child that reads stdin eats the remainder and the run ends silently at
exit 0.

Maintainers can run the catch-up for contributors — the Bulk Migration
action replays every migration still listed under bar::migrate, oldest
first, skipping the ones a branch already has.
Builds and publishes docker/dev.Containerfile to ghcr, and adds
docker/migration.Containerfile with the codemod binary baked in, so the
Bulk Migration action runs the same toolchain developers run locally
instead of rebuilding it per job. Adds gh to the dev image for the
pipeline's stack linking.
@keithharvey
keithharvey marked this pull request as ready for review August 13, 2026 02:59
@keithharvey
keithharvey requested a review from thvl3 as a code owner August 13, 2026 02:59
@keithharvey

Copy link
Copy Markdown
Contributor Author

@NortySpock @thvl3 Ok this one is ready to go. The codemod changes are now in BAR master so the deterministic part of this has been validated against the real repo. This one is definitely better reviewed as the individual commits, best I could do without upstream access to stack this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant