feat(windows): add MSYS2 compat shim (#88)#211
Open
masa6161 wants to merge 2 commits into
Open
Conversation
Add scripts/lib/compat.sh with portable wrappers for MSYS2-incompatible POSIX commands (ps -o ppid=/args=/comm=, uuidgen, stat -c/-f) and replace 12 call sites across 8 files with the compat_* equivalents. On Linux/macOS the wrappers fall through to the original commands, so behavior is unchanged on those platforms. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The compat shim makes the ppid walk succeed on MSYS2, but _iid() (bats subshell) and watch.sh (standalone bash) resolve different process trees, causing instance-id mismatches. Pin AGMSG_AGENT_PID to empty on MSYS2 so both contexts use the bare session_id. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
Adds a Windows/MSYS2 compatibility shim for process interrogation, UUID generation, and cross-platform stat usage, then switches multiple scripts/tests to use the shim so Git Bash/MSYS2 can run the same workflows as Linux/macOS.
Changes:
- Added
scripts/lib/compat.shwithcompat_get_ppid,compat_get_cmdline,compat_get_comm,compat_uuidgen, andcompat_file_mtime. - Updated multiple scripts to source
compat.shand replace directps/uuidgen/statcalls withcompat_*wrappers. - Adjusted
test_watch.batsto pinAGMSG_AGENT_PIDon MSYS2 to keep instance-id derivation deterministic across differing process trees.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_watch.bats | Pins AGMSG_AGENT_PID on MSYS2 to avoid instance-id mismatches after PPID walking starts working there. |
| scripts/whoami.sh | Sources compat shim; uses compat_get_comm/compat_get_ppid for process-tree detection. |
| scripts/watch.sh | Sources compat shim; uses compat_get_cmdline for defensive “previous watcher” checks. |
| scripts/session-start.sh | Sources compat shim; uses compat_get_cmdline for orphan watcher validation before killing. |
| scripts/session-end.sh | Sources compat shim; uses compat_get_cmdline for defensive watcher kill. |
| scripts/lib/resolve-project.sh | Sources compat shim; swaps ps -o ... uses to compat_get_* in agent PID detection/walk. |
| scripts/lib/compat.sh | New shim implementing MSYS2-safe alternatives for ps -o, uuidgen, and stat variants. |
| scripts/drivers/types/codex/_session-start.sh | Uses compat_get_cmdline when extracting Codex app-server from agent argv. |
| scripts/delivery.sh | Uses compat shim for session UUID and watcher cmdline checks. |
| scripts/check-inbox.sh | Uses compat_file_mtime instead of OS-branching stat flags. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+72
to
+74
| *) | ||
| ps -o comm= -p "$pid" 2>/dev/null | ||
| ;; |
Comment on lines
+82
to
84
| comm=$(compat_get_comm "$pid" 2>/dev/null || true) | ||
| first=$(compat_get_cmdline "$pid" 2>/dev/null | awk '{print $1}') | ||
| base=$(basename -- "${first:-}" 2>/dev/null || true) |
Comment on lines
113
to
116
| local pid="$$" hops=0 | ||
| while [ "${pid:-0}" -gt 1 ] && [ "$hops" -lt 20 ]; do | ||
| pid=$(ps -o ppid= -p "$pid" 2>/dev/null | tr -d ' ') | ||
| pid=$(compat_get_ppid "$pid" 2>/dev/null) | ||
| [ -z "$pid" ] && return 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
scripts/lib/compat.sh— a platform compatibility shim that wraps MSYS2-incompatible POSIX commands (ps -o ppid=/args=/comm=,uuidgen,stat -c/-f) with portable alternatives. Replace 12 call sites across 8 scripts with thecompat_*wrappers.On Linux/macOS the wrappers fall through to the original commands, so behavior is unchanged on those platforms.
Scope (per maintainer guidance): this is the core compat-shim PR. The
delivery.sh"shell":"bash"hook-routing and the PowerShell bootstrap installers are intentionally excluded and will follow as separate PRs.What changed
New file:
scripts/lib/compat.sh— 5 wrapper functions:compat_get_ppid— replacesps -o ppid= -p <pid>compat_get_cmdline— replacesps -o args= -p <pid>compat_get_comm— replacesps -o comm= -p <pid>compat_uuidgen— replacesuuidgen(falls back to/proc/sys/kernel/random/uuid, thensqlite3)compat_file_mtime— replacesstat -f %m(macOS) /stat -c %Y(Linux)Call-site swaps (12 sites, 8 files):
resolve-project.sh(3):agmsg_pid_is_agentcomm+cmdline,agmsg_agent_pidppid walkwhoami.sh(2):detect_cli_typeprocess-tree walkdelivery.sh(2):emit_monitor_directiveuuidgen,kill_all_watcherscmdline checksession-start.sh(1): orphan watcher cmdline checksession-end.sh(1): watcher cmdline checkwatch.sh(1): previous-watcher cmdline checkcheck-inbox.sh(1): cooldownstatmtimecodex/_session-start.sh(1): app-server argv extractionTest fix:
test_watch.batspinsAGMSG_AGENT_PID=""on MSYS2 so the ppid walk (now functional) doesn't cause instance-id mismatches between bats subshell and standalone bash contexts.Coordination
8d662ba(currentmain, includes fix(windows): native pid liveness via tasklist in agmsg_instance_alive (#134) #198 and fix(directive): quote Monitor command args so space-in-path survives (#188) #200)_agmsg_pid_aliveviatasklist) operates at a different layer (pid liveness vs process interrogation) — no conflictprintf %qquoting) is preserved in bothdelivery.shandsession-start.shTest plan
Verified on Windows 11 / Git Bash (MINGW64) against the full test suite, comparing baseline (
main) vs this branch:test_delivery(101)test_resolve_project(16)test_instance_id(23)test_codex_bridge(16)test_watch(13)No regressions. Pre-existing failures are
kill -0/ git-worktree issues tracked separately in #182 and #198.Closes #88 (core shim).