kReaperScript top-level constant

String const kReaperScript

The REAPER PARENT script. detachedWithStdio buys the process group but costs the exit code (Process.exitCode throws for a detached process), so a vanish had to be INFERRED — and a murdered agent vanishes exactly like a finished one. This wrapper IS the leader: it runs the harness as its child in the SAME group, WAITS for it, writes the real code, and exits with it.

"$@" keeps argv positional, so the no-shell contract still holds (no word splitting; gc condition.go:319). The write is atomic (.part then mv -f) and completes BEFORE the wrapper exits, so a provider that only reads the file once the leader is gone can never observe a torn value; if mv itself fails the .part file is inert and the provider falls back to the INFERRED reading rather than reading half a number.

Implementation

const String kReaperScript = r'''
"$@"
__grid_code=$?
if [ -n "$GRID_EXIT_STATUS_FILE" ]; then
  printf '%s\n' "$__grid_code" > "$GRID_EXIT_STATUS_FILE.part" 2>/dev/null &&
    mv -f "$GRID_EXIT_STATUS_FILE.part" "$GRID_EXIT_STATUS_FILE" 2>/dev/null
fi
exit $__grid_code
''';