Files

39 lines
1.9 KiB
Python

#!/usr/bin/env python3
"""Long-context pad for the Codex cells of the 245k study: concatenates source files of the frozen corpus
(/data/leleka-e2e/decode/corpus/src/crates, read-only) in path order, each under a header line, up to about --chars characters
(whole files only). Codex reads $CODEX_HOME/AGENTS.md without the 32 KiB cap of the project document and sends it in the first request
as a user message (verified: an 810 kB file arrives whole), so every request of the session carries the pad: the same long-context
regime as the 245k corpus session, with the real Codex tool loop on top. The text is the same for every variant.
usage: q245_pad.py CORPUS_DIR OUT --chars 528000
"""
import os, sys, hashlib
HEADER = ("# Reference material (read-only background)\n\n"
"The sources below are a vendored snapshot of a Rust workspace that is unrelated to the task you are given. They are only here for "
"reference; do not edit them and ignore them unless the task asks about them.\n\n")
def main(argv):
root, out = argv[0], argv[1]
target = int(argv[argv.index("--chars") + 1]) if "--chars" in argv else 528000
parts, n = [HEADER], len(HEADER)
for d, dirs, files in os.walk(root):
dirs.sort()
for f in sorted(files):
if not f.endswith(".rs"):
continue
p = os.path.join(d, f)
text = open(p, encoding="utf-8", errors="replace").read()
block = "=== %s ===\n%s\n\n" % (os.path.relpath(p, root).replace(os.sep, "/"), text)
if n + len(block) > target:
continue
parts.append(block)
n += len(block)
data = "".join(parts)
open(out, "w", encoding="utf-8", newline="\n").write(data)
print(len(data), "chars,", len(parts) - 1, "files,", hashlib.sha256(data.encode("utf-8")).hexdigest())
if __name__ == "__main__":
main(sys.argv[1:])