package main import ( "crypto/sha256" "encoding/json" "flag" "fmt" "os" "os/exec" "path/filepath" "time" ) type runSpec struct { ID, Source, Policy string } type planSpec struct { Compiler string `json:"compiler_source_sha"` Files map[string]string `json:"files"` Models map[string]string `json:"model_sha256"` Runs []runSpec `json:"runs"` } func require(err error) { if err != nil { panic(err) } } func read(name string) []byte { b, err := os.ReadFile(name) require(err) return b } func sha(data []byte) string { return fmt.Sprintf("%x", sha256.Sum256(data)) } func exclusive(name string, data []byte) { f, err := os.OpenFile(name, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0600) require(err) _, err = f.Write(data) require(err) require(f.Close()) } func main() { compiler := flag.String("compiler", "", "existing clean Gooo executable") goBin := flag.String("go-bin", "", "Go 1.27.2 executable") corpus := flag.String("corpus", "", "frozen input directory") planSHA := flag.String("plan-sha", "", "published plan SHA256") resultRoot := flag.String("results", "", "new output directory") ordered := flag.String("ordered", "", "existing ordered model file") interaction := flag.String("interaction", "", "existing interaction model file") flag.Parse() models := map[string]string{"ordered": *ordered, "interaction": *interaction} raw := read(filepath.Join(*corpus, "plan.json")) if *planSHA == "" || sha(raw) != *planSHA { panic("plan identity mismatch") } var plan planSpec require(json.Unmarshal(raw, &plan)) if len(plan.Runs) != 27 || len(plan.Files) != 11 || len(plan.Models) != 2 { panic("unexpected cohort dimensions") } for name, digest := range plan.Files { if sha(read(filepath.Join(*corpus, name))) != digest { panic("input identity mismatch: " + name) } } for name, digest := range plan.Models { if sha(read(models[name])) != digest { panic("model identity mismatch: " + name) } } build, err := exec.Command(*compiler, "version", "--build", "--json").Output() require(err) var info struct { Source string `json:"compiler_source_sha"` Dirty string `json:"vcs_modified"` Go string `json:"go_version"` SDK struct { Version string `json:"version"` Replaced bool `json:"replaced"` } `json:"decision_runtime"` } require(json.Unmarshal(build, &info)) if info.Source != plan.Compiler || info.Dirty != "false" || info.Go != "go1.27.2" || info.SDK.Version != "v0.2.39-experimental" || info.SDK.Replaced { panic("compiler build identity mismatch") } goVersion, err := exec.Command(*goBin, "version").Output() require(err) if string(goVersion) != "go version go1.27.2 darwin/arm64\n" { panic("unexpected native toolchain or platform") } // Atomic directory creation is the one-use gate for this original cohort. require(os.Mkdir(*resultRoot, 0700)) exclusive(filepath.Join(*resultRoot, "STARTED"), []byte(time.Now().UTC().Format(time.RFC3339Nano)+"\n")) exclusive(filepath.Join(*resultRoot, "compiler-build.json"), build) exclusive(filepath.Join(*resultRoot, "compiler.sha256"), []byte(sha(read(*compiler))+"\n")) exclusive(filepath.Join(*resultRoot, "go-version.txt"), goVersion) exclusive(filepath.Join(*resultRoot, "plan.sha256"), []byte(*planSHA+"\n")) for i, row := range plan.Runs { runRoot := filepath.Join(*resultRoot, row.ID) require(os.Mkdir(runRoot, 0700)) args := []string{"-l", "-p", *compiler, "body-construct", "--entry", "Main", "--source", filepath.Join(*corpus, row.Source), "--construction-cases", filepath.Join(*corpus, "construction.json"), "--cases", filepath.Join(*corpus, "evaluation.json"), "--attempts", "4", "--go-bin", *goBin, "--out", filepath.Join(runRoot, "construction")} if row.Policy != "deterministic" { model, ok := models[row.Policy] if !ok { panic("unrecognized policy") } args = append(args, "--model", model) } stdout, err := os.OpenFile(filepath.Join(runRoot, "stdout.json"), os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0600) require(err) stderr, err := os.OpenFile(filepath.Join(runRoot, "stderr-time.txt"), os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0600) require(err) cmd := exec.Command("/usr/bin/time", args...) cmd.Stdout, cmd.Stderr = stdout, stderr started := time.Now() runErr := cmd.Run() elapsed := time.Since(started) require(stdout.Close()) require(stderr.Close()) exitCode := -1 if cmd.ProcessState != nil { exitCode = cmd.ProcessState.ExitCode() } status := map[string]any{"id": row.ID, "index": i, "policy": row.Policy, "started_at": started.UTC().Format(time.RFC3339Nano), "wall_ns": elapsed.Nanoseconds(), "source_sha256": plan.Files[row.Source], "exit_code": exitCode, "stdout_sha256": sha(read(filepath.Join(runRoot, "stdout.json"))), "stderr_sha256": sha(read(filepath.Join(runRoot, "stderr-time.txt")))} if runErr != nil { status["error"] = runErr.Error() } encoded, err := json.MarshalIndent(status, "", " ") require(err) exclusive(filepath.Join(runRoot, "status.json"), append(encoded, '\n')) fmt.Printf("%d/27 %s exit=%d\n", i+1, row.ID, exitCode) } exclusive(filepath.Join(*resultRoot, "COMPLETED"), []byte(time.Now().UTC().Format(time.RFC3339Nano)+"\n")) }