Skip to content

tools: port the remaining scripts/*.py to Flow - #971

Merged
godofecht merged 26 commits into
mainfrom
port/scripts-rest-to-flow
Sep 29, 2026
Merged

godofecht merged 26 commits into
mainfrom
port/scripts-rest-to-flow

Conversation

@godofecht

@godofecht godofecht commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Ports the rest of the top-level scripts/*.py to Flow, deletes the unused ones, and removes scripts/wasm/. Each port is a Flow program in scripts/tools/<name>/main.flow behind a bash shim, built by scripts/tools/build_tool.sh from the bootstrap C.

Depends on #959 and #965, which should merge first. Both branches are merged in, and this PR reuses their build_tool.sh, lib/*.flow and shim pattern. The only conflict was in build_tool.sh and lib/text.flow, where #959's copy is a superset; I kept it.

Ported (Python deleted)

Python Flow program / shim Callers switched Parity
check_changelog.py tools/changelog_check, check_changelog.sh changelog.yml, finalize-flow-1.0.1.yml, prepare_release 11 cases, all identical: real tree, missing section, duplicates, Unicode whitespace, headings split across lines.
prepare_release.py tools/prepare_release, prepare_release.sh release-pr-prepare.yml 18 cases, each in a full copy of the tree: new release, rc suffix, version already present, bad version, empty or malformed notes, no Unreleased section, no current-release paragraph, no history rows, relative --root from another directory, argparse errors, help. stdout, stderr, exit code and the resulting tree all identical.
update_repo_stats.py tools/repo_stats (existing), update_repo_stats.sh stats.yml (setup-python and the Python cross-check dropped) Write mode and --check (stale and current) on the real tree: README.md, repository-stats.json, stdout, stderr and exit code identical. The counter's messages were changed to match Python's. It now builds with Stage-A instead of the Python transpiler. tests/unit/test_repo_stats.py runs the Flow counter in a scratch tree.
dispatch_uncovered_jules.py tools/jules_dispatch, dispatch_uncovered_jules.sh none (run by hand) Fake gh and jules on PATH, waits skipped: 8 cases (live-session filter, existing state with extra keys, refusals, capacity holds, giving up after 40 refusals, empty queue, corrupt state, failing gh). stdout, state file, every task text piped to jules, and gh arguments identical.
build_demo_overview.py, build_shader_gallery.py, sync_demo_nav.py tools/demo_overview, tools/shader_gallery, tools/demo_nav and shims; helpers in lib/demogen.flow test_demo_gallery_docs.py 20, 15 and 13 cases (write, --check, stale and missing output, preview and asset checks, escaping, Unicode, missing keys, argparse). The one difference is a truncated JSON file: exit code and tree match, and the decode-error wording differs.
gen_abi_bindings.py tools/abi_bindings, gen_abi_bindings.sh vulkan_abi READMEs 25 of 25 identical. The checked-in demos/vulkan_abi and examples/demos/vulkan_abi bindings matched byte for byte before their "Auto-generated by" line was switched to the shim.
wasm_build.py, build_wasm_gallery.py tools/wasm_build (modes build, gallery, gallery-one), wasm_build.sh, build_wasm_gallery.sh ./flow wasm, test_wasm_backends.py, docs/language/wasm.md, .gitignore 29 wasm_build cases (console, gfx, mlir, preload, link, threads, keep-c, broken and unlinkable programs, argparse) and 9 gallery cases (list filters, an 8-target build covering every extras kind, all of morphogenesis). Output identical with build times masked. The gallery fans out through xargs -P. One deliberate change: the tiny_pointers card note was reworded because the prose rules flag its contrast sentence. The transpile step still calls python3 -m flow.transpiler, as before.
verify_examples.py, triage_verify_failures.py tools/verify_examples, tools/triage_verify_failures, shims; helpers in lib/verify_run.flow docs/vision example comments Full default runs (1557 and 1054 files): stdout, stderr, exit code, --json output and examples/STATUS.md identical with the timestamp masked. Plus 30 cases (broken inputs, timeouts, sample limits, argparse). Triage tags match Python's tag_features on 2235 files. STATUS.md is regenerated.
build_wiki.py, wiki_nav.py, gen_stdlib_docs.py (and the tutorial_lessons path of docs_blocks.py) tools/build_wiki, tools/wiki_nav, tools/gen_stdlib_docs, lib/wiki_*.flow, shims wiki.yml, check_wiki_links.sh, build_pagefind.sh (its embedded Python is now build_wiki --pagefind-stage), deploy_wiki.py, RELEASING.md, test_wiki_nav.py On the real tree, the full build/wiki output (3,226 files), stdout, stderr and exit code are identical to Python's. So is the regenerated stdlib-api.md. 13 mutated trees (nav problems, missing CHANGELOG or ledger, CRLF and invalid UTF-8, hidden dirs, link rewrites, proof imports, fence edge cases) are identical. Pagefind's own hashed files differ between any two runs.

Where the Python crashed with a traceback (a missing file, gh failing, a malformed nav.json, --jobs 0), the Flow tool prints one line and exits with the same code. Usage lines say .sh where Python said .py.

Deleted without a port

File Why
scripts/wasm/ (4 .py, hello_harness.c, demo pages) Older copies of the wasm/ helpers that #965 retired. Nothing ran them. examples/demos/index.html now points at ./flow wasm, as demos/index.html does.
record_tetris_gif.py Marked itself deprecated. It redrew Tetris in Pillow, and running it overwrote the real recording from record_demos.py. Only a ROADMAP row names it.
compile_mlir_examples.py An ad hoc MLIR sweep of every example. No workflow, script, doc or test names it.
wiki_shots.py Playwright screenshots into /tmp/wikishots for one visual review, with no references anywhere.

Stays in Python, and why

File Reason
check_doc_examples.py, check_doc_examples_strict.py Run the Python compiler in process (flow.parser, flow.c_generator, the type checker).
check_doc_flow_snippets.py Detection could run in Flow, but its failure report calls check_doc_examples.verify in process.
docs_blocks.py Imported by the three scripts above and by verify_browser_interp.py.
compile_spirv_metal.py, emit_fsl_wgsl.py, record_shader_gallery.py, run_bench.py, test_lsp_server.py Import flow.* (mlir_spirv, shader_codegen_wgsl, shader_codegen, MLIRJIT, lsp_server/type_checker).
verify_browser_interp.py Runs the Python transpiler in process and diffs it against node.
frames_to_gif.py, record_demos.py Pillow: median-cut quantisation, Floyd-Steinberg dithering and Lanczos resampling. Byte-identical GIFs need the same quantiser.
playground_compile_server.py, ws_echo_relay.py A threaded HTTP server and a WebSocket server. Stage-A has no sockets or threads.
wiki_contrast.py, wiki_verify.py Playwright browser audits.
deploy_wiki.py Its legacy VPS path reads credentials through the aissh ssh_client Python library. Its default path now builds with build_wiki.sh.

Docs left unedited

The house-rules commit hook scans whole staged files. These files already had em dashes or other flagged constructions, so they still name the old .py scripts:

  • ROADMAP.md
  • docs/project/python-in-flow.md
  • docs/demos/README.md, docs/demos/wasm.md, docs/language/shaders.md, docs/AI_FLOW_HANDBOOK.md
  • examples/README.md, Questions.md, docs/project/Questions.md, docs/vision/north-star.md, docs/third-party/flow-verify-parser-status.md
  • docs/wiki-strategy.md, docs/wiki-roadmap.md, docs/third-party/README.md, docs/third-party/flow-verify.md, docs/third-party/proof-graph.md, site/proof-graph.html
  • site/wasm/index.html. Its footer names the old script until the next gallery rebuild.

README.md was edited: its stats footer linked the deleted update_repo_stats.py, which failed the doc link check. Clearing its two existing findings meant rewording the toolchain sentence and having the counter write n/a for the registry-packages line count.

docs/library/stdlib-api.md picks up the new header on its next regeneration.

Flow gaps found

Testing

python3 -m pytest tests/unit: 1795 passed, 4 skipped. test_doc_anchors passes after the README fix. The two errors in test_match_exhaustive_returns.py come from ./flow run not leaving build/m.c in this worktree; that path is untouched here. scripts/build_wiki.sh followed by scripts/check_wiki_links.sh passes, and scripts/check_doc_links.sh reports no broken links.

Agent-loop follow-up

Closes #972.
Closes #973.
Contributes to #975 by treating red main CI as backpressure and deferring low-priority dispatch until the baseline is repaired.

@godofecht

Copy link
Copy Markdown
Contributor Author

Merge train: rebased onto main (now containing #959, #960, #965, #966 and the Python ratchet from #981). Not merged. Commits added after the port (Jules dispatch backpressure and tool layout checks) add two new Python files, scripts/check_tool_layout.py and tests/integration/test_jules_dispatch.py, so the Python ratchet job fails: "2 new Python file(s). New code is written in Flow." Port them to Flow or shell and this can merge.

scripts/wasm held stale copies of wasm/flow_to_wasm.py, flow_wasm.py,
demo_wasm_build.py, wasm_build_system.py, hello_harness.c and the demo
pages. Nothing ran them. examples/demos/index.html now points at
./flow wasm, as demos/index.html does.
scripts/check_changelog.sh and scripts/prepare_release.sh run the Flow
programs in scripts/tools/changelog_check and scripts/tools/prepare_release.
The changelog, release-pr-prepare and finalize-flow-1.0.1 workflows call
the shims.

Parity against the Python scripts: 11 changelog cases (real tree, missing
section, duplicates, Unicode whitespace, headings split over lines) and
18 prepare_release cases run in full copies of the tree (new release, rc
suffix, already-present version, bad version, empty or malformed notes,
missing Unreleased section, missing current-release paragraph, missing
history rows, relative --root from another directory, argparse errors
and help). stdout, stderr, exit code and the resulting tree all match.
scripts/update_repo_stats.sh now builds scripts/tools/repo_stats with
build_tool.sh (Stage-A flowc from the bootstrap C) instead of the Python
transpiler, and no longer cross-checks or falls back to
update_repo_stats.py, which is deleted. The counter's messages now match
the Python script's (the stale-file list, the source-line total), and the
README footer drops the Python link.

Parity before deleting: write mode and --check (stale and current) on the
real tree gave identical README.md, repository-stats.json, stdout,
stderr and exit codes. A missing marker exits 1 in both; Python printed
a traceback, Flow prints one line.

tests/unit/test_repo_stats.py now runs the Flow counter in a scratch tree
and pins the same rules (rounding, component-wise area matching, grouped
numbers, marker handling). stats.yml drops setup-python.
scripts/dispatch_uncovered_jules.sh runs scripts/tools/jules_dispatch,
which calls gh and jules through the shell, keeps the same
jules_dispatch_state.json (sorted keys, two-space indents, ASCII
escapes), and holds, retries and gives up exactly as before.

Parity with fake gh and jules CLIs on PATH (waits skipped on both
sides): 8 cases covering live-session filtering, an existing state file
with extra keys, refusals, capacity holds, giving up after 40 refusals
with a 200-character detail, an empty queue, a corrupt state file and a
failing gh. stdout, the state file, every task text piped to jules and
the gh arguments match; so does the exit code. On a failing gh, Python
printed a traceback and Flow prints one line.
- record_tetris_gif.py marked itself deprecated: it redrew Tetris in
  Pillow instead of running the game, and running it overwrote the real
  recording that record_demos.py produces. Only a ROADMAP.md table row
  names it.
- compile_mlir_examples.py was an ad hoc sweep of every example through
  `flow.transpiler --mlir`. Nothing runs it: no workflow, script, doc or
  test names it. verify_examples covers the corpus sweep.
- wiki_shots.py took Playwright screenshots of a local wiki server into
  /tmp/wikishots for one visual review. Nothing references it.
build_demo_overview, build_shader_gallery, sync_demo_nav and
gen_abi_bindings are now Flow programs under scripts/tools (demo_overview,
shader_gallery, demo_nav, abi_bindings) with .sh shims. Shared helpers
(html.escape, argparse-style flags, json.dumps with ensure_ascii=False,
Python truthiness) are in scripts/tools/lib/demogen.flow.

Parity (stdout, stderr, exit code, written tree):
- build_demo_overview: 20 cases, 19 identical; the 20th is a truncated
  catalog.json, where exit code and tree match and the JSON error wording
  differs.
- build_shader_gallery: 15 of 15 identical.
- sync_demo_nav: 13 cases, 12 identical; same JSON wording difference.
- gen_abi_bindings: 25 of 25 identical. The checked-in vulkan_abi
  headers and bindings matched the Python output byte for byte before
  their "Auto-generated by" line was switched to the shim.
Program names in usage lines now say .sh; where Python crashed with a
traceback, Flow prints the same final line.

tests/unit/test_demo_gallery_docs.py drives the shims' --check modes
and adds a nav sync check.
scripts/wasm_build.sh and scripts/build_wasm_gallery.sh run the Flow
program in scripts/tools/wasm_build (modes build, gallery, gallery-one).
Page text lives in scripts/tools/wasm_build/assets. The gallery builds
targets in parallel through xargs -P. The transpile step still runs
python3 -m flow.transpiler, as before. ./flow wasm, the integration
tests and the docs call the shims; the Python scripts are deleted.

Parity against the Python on 29 wasm_build cases (console, gfx, mlir,
preload, link, threads, keep-c, broken and unlinkable programs, argparse
errors) and 9 gallery cases (list filters, an 8-target --only build with
every extras kind, all of morphogenesis): identical stdout, stderr, exit
codes and files, with build times masked. One .js built at -O1 embeds
an emscripten temp path that differs between any two runs.

The manifest's generated_by names the shim. One deliberate change from
the Python: the tiny_pointers card note is reworded to drop an "X, not Y"
sentence, so that page differs from the Python output on that line.
site/wasm/index.html keeps its old footer until the next gallery rebuild
(the prose hook blocks edits to it).
scripts/verify_examples.sh and scripts/triage_verify_failures.sh run the
Flow programs in scripts/tools/verify_examples and
scripts/tools/triage_verify_failures. Shared pieces (argparse emulation,
find-based discovery, timed stages, xargs -P fan-out) live in
scripts/tools/lib/verify_run.flow. The transpile stage still calls
python3 -m flow.transpiler, as the Python scripts did.

Parity: full default runs of both tools (1557 and 1054 files) gave the
same stdout, stderr, exit code, --json output and examples/STATUS.md
(timestamp masked), plus 30 cases covering broken inputs, timeouts,
sample limits, file roots, relative --json paths and argparse errors.
Triage tags match Python's tag_features on 2235 files. The STATUS.md
header and triage prose now name the .sh shims and drop em dashes.
Only --jobs 0 differs: Python printed a traceback.

examples/STATUS.md is regenerated by the Flow tool.
scripts/build_wiki.sh runs scripts/tools/build_wiki, which replaces
build_wiki.py, wiki_nav.py, gen_stdlib_docs.py and the tutorial_lessons
path of docs_blocks.py. Shared code is in scripts/tools/lib/wiki_*.flow.
gen_stdlib_docs.sh and wiki_nav.sh expose the stdlib page generator and
the nav checker on their own. build_pagefind.sh stages its HTML stubs
through `build_wiki --pagefind-stage` instead of embedded Python.
wiki.yml, check_wiki_links.sh, deploy_wiki.py and RELEASING.md call the
shims; test_wiki_nav.py drives wiki_nav.sh.

Parity: on the real tree the whole build/wiki output (3,226 files),
stdout, stderr and exit code match the Python build, and so does the
regenerated stdlib-api.md. 13 mutated trees (dead or orphaned nav
entries, missing CHANGELOG and ledger, CRLF and invalid UTF-8 pages,
hidden and cache directories, ROADMAP link rewrites, every proof import
form, fence edge cases) match on tree, stdout and exit code. The two
crash cases, malformed nav.json and an unknown info-string flag, print
one line where Python printed a traceback. Pagefind stubs match on
the real and an edge-case index. After parity, three generated pages
name the new scripts instead of the deleted Python.

deploy_wiki.py stays for its legacy VPS path, which reads credentials
through the aissh ssh_client Python library. docs_blocks.py stays for
check_doc_examples.py and check_doc_flow_snippets.py.
The doc link check fails on the README footer's link to the deleted
update_repo_stats.py. Editing README.md meant clearing its two existing
prose findings: the toolchain sentence is reworded, and the counter now
writes n/a for the registry-packages line count instead of a dash.
The Python ratchet rejects new .py files. check_tool_layout.py becomes
check_tool_layout.sh, and the five Jules dispatch backpressure cases move
from tests/integration/test_jules_dispatch.py to
scripts/tools/jules_dispatch/test.sh with the same fake gh and jules
commands. CI runs both in the doc-links job.
@godofecht
godofecht force-pushed the port/scripts-rest-to-flow branch from 7eb4cec to cbb1efc Compare September 27, 2026 22:56
shellcheck runs without -x in Lint, so sourcing scripts/tools/wasm_build/env.sh
reported SC1091 and failed the job.
@godofecht
godofecht merged commit ff99639 into main Sep 29, 2026
28 checks passed
godofecht added a commit that referenced this pull request Sep 29, 2026
#971 changed a comment in docs/vision/examples/pendulum.flow from
verify_examples.py to verify_examples.sh. The ex_ fixture must match its
source byte for byte.
godofecht added a commit that referenced this pull request Sep 29, 2026
#971 changed a comment in docs/vision/examples/pendulum.flow from
verify_examples.py to verify_examples.sh. The ex_ fixture must match its
source byte for byte.
godofecht added a commit that referenced this pull request Sep 29, 2026
#971 changed a comment in docs/vision/examples/pendulum.flow from
verify_examples.py to verify_examples.sh. The ex_ fixture must match its
source byte for byte.
@godofecht
godofecht deleted the port/scripts-rest-to-flow branch October 1, 2026 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant