Skip to content

feat(windows): add MSYS2 compat shim (#88)#211

Open
masa6161 wants to merge 2 commits into
fujibee:mainfrom
masa6161:feat/compat-shim-core
Open

feat(windows): add MSYS2 compat shim (#88)#211
masa6161 wants to merge 2 commits into
fujibee:mainfrom
masa6161:feat/compat-shim-core

Conversation

@masa6161

Copy link
Copy Markdown

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 the compat_* 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 — replaces ps -o ppid= -p <pid>
    • compat_get_cmdline — replaces ps -o args= -p <pid>
    • compat_get_comm — replaces ps -o comm= -p <pid>
    • compat_uuidgen — replaces uuidgen (falls back to /proc/sys/kernel/random/uuid, then sqlite3)
    • compat_file_mtime — replaces stat -f %m (macOS) / stat -c %Y (Linux)
  • Call-site swaps (12 sites, 8 files):

    • resolve-project.sh (3): agmsg_pid_is_agent comm+cmdline, agmsg_agent_pid ppid walk
    • whoami.sh (2): detect_cli_type process-tree walk
    • delivery.sh (2): emit_monitor_directive uuidgen, kill_all_watchers cmdline check
    • session-start.sh (1): orphan watcher cmdline check
    • session-end.sh (1): watcher cmdline check
    • watch.sh (1): previous-watcher cmdline check
    • check-inbox.sh (1): cooldown stat mtime
    • codex/_session-start.sh (1): app-server argv extraction
  • Test fix: test_watch.bats pins AGMSG_AGENT_PID="" on MSYS2 so the ppid walk (now functional) doesn't cause instance-id mismatches between bats subshell and standalone bash contexts.

Coordination

Test plan

Verified on Windows 11 / Git Bash (MINGW64) against the full test suite, comparing baseline (main) vs this branch:

Suite main + compat shim Delta
test_delivery (101) 101 pass 101 pass 0
test_resolve_project (16) 15 pass / 1 fail 15 pass / 1 fail 0
test_instance_id (23) 19 pass / 4 fail 19 pass / 4 fail 0
test_codex_bridge (16) 16 pass 16 pass 0
test_watch (13) 6-7 pass / 6-7 fail 6-7 pass / 6-7 fail 0

No regressions. Pre-existing failures are kill -0 / git-worktree issues tracked separately in #182 and #198.

Closes #88 (core shim).

masa6161 and others added 2 commits June 24, 2026 11:59
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]>
Copilot AI review requested due to automatic review settings June 24, 2026 03:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.sh with compat_get_ppid, compat_get_cmdline, compat_get_comm, compat_uuidgen, and compat_file_mtime.
  • Updated multiple scripts to source compat.sh and replace direct ps/uuidgen/stat calls with compat_* wrappers.
  • Adjusted test_watch.bats to pin AGMSG_AGENT_PID on 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 thread scripts/lib/compat.sh
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Native Windows support via PowerShell wrappers + compat shim

2 participants