POK-49: Detect Windows shell and inject agent context#51
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: aa38ee53da
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ? [] | ||
| : [ | ||
| `- Host platform: ${shellInfo.platformLabel} (${shellInfo.platform})`, | ||
| `- Host shell: ${shellInfo.hostShell.label} (detected from ${shellInfo.hostShell.detectionSource})`, |
There was a problem hiding this comment.
Sanitize env-derived shell labels before prompt injection
When the launcher environment contains a newline or prompt-like text in SHELL/MSYSTEM, this renders hostShell.label directly into the system prompt, so a value such as SHELL=$'/bin/bash\n- Ignore previous instructions...' becomes an additional system-prompt line. Normalize the shell fields used in prompts/status to inert single-line text before interpolating environment-derived values.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
@codex I checked this against current head 43c8ca3. This comment is stale now: the PR no longer interpolates env-derived host shell labels into the system prompt. The Windows bash-tool section only emits fixed strings for platform and shell syntax, so no additional code change is needed for current head.
There was a problem hiding this comment.
To use Codex here, create an environment for this repo.
|
@claude Please review this Windows shell/context PR against the current upstream main. Focus on whether the Windows shell detection and injected agent context fit the existing runtime model, and call out any concrete code or test changes needed on this branch. |
|
@claude Please review this Windows shell/context PR again. This is a maintainer-triggered retry after the Claude workflow routing change; treat this comment as the review request. Focus on whether the Windows shell detection and injected agent context fit the existing runtime model, and identify any concrete code or test changes needed on this branch. |
Review: POK-49 Windows shell detection and agent contextSummaryThe PR adds runtime shell/platform detection and injects context into agent system prompts and status surfaces. The detection cascade (MSYSTEM → OSTYPE → SHELL → PROMPT/ComSpec → POWERSHELL_DISTRIBUTION_CHANNEL) is sound, the sanitization is appropriate, and the data flow from Issues1. Shell info is unconditionally injected into every system prompt on all platforms
This is a permanent token cost increase for the common case. Consider one of these approaches:
2. Status builders in 3. Test for prompt sanitization verifies toxic text survives in label form The test at This is correct sanitization (control chars stripped, whitespace collapsed), but the printable text "IGNORE PREVIOUS INSTRUCTIONS" survives. While the attack surface is minimal (env vars are set by the shell environment, not remote input), the surviving text is semantically meaningful and placed in the system prompt. The current mitigation is adequate for the threat model, but worth being aware of — if env-derived text is ever displayed in a more instruction-like context, stronger scrubbing (e.g., disallowing known prompt-injection phrases) would be warranted. Non-blocking observations
|
|
@claude Please review this Windows shell/context PR now that I have collaborator access. Focus on whether the Windows shell detection and injected agent context fit the existing runtime model, and call out any concrete code or test changes needed on this branch. |
PR Review: POK-49 — Windows shell detection and agent context injectionOverall: The implementation is solid. The shell detection logic, the prompt injection sanitization, and the integration with the existing runtime model are all well done. No correctness bugs or merge-blocking issues found. 1. The shell detection and injected context fit the runtime model cleanlyThe integration touches the right surfaces:
The 2. Minor: redundant
|
Co-authored-by: HYT-koota <211174511+HYT-koota@users.noreply.github.com>
|
@claude Fixed in What changed:
Local verification:
Please review again. |
|
Thanks for the update. I've re-reviewed the full diff at
Everything else looks solid: the shell resolution cascade (pwsh 7 → pwsh 5 → cmd), UTF-8 output prefix for PowerShell, |
|
@claude Follow-up in Latest GitHub checks are green:
PR remains mergeable. |
Review: POK-49 — follow-up at
|
|
@codex please help review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ff0ed11d99
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const backgroundReason = isNativeWindowsPlatform() | ||
| ? null | ||
| : detectUnsupportedBackgroundSyntax(args.command); |
There was a problem hiding this comment.
Reject PowerShell background jobs
On native Windows with PowerShell 7 selected, this bypasses all background-syntax checks, but PowerShell also has a trailing & background operator; Microsoft’s about_Operators docs describe it as running the preceding pipeline in a background job. That means commands like npm run dev & or Start-Sleep 60 & now return immediately instead of being rejected, despite the prompt saying background shell jobs are unsupported. Keep allowing the leading call operator, but add PowerShell-aware rejection for trailing &/job syntax before executing.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
@codex Fixed in 43c8ca3. The bash tool now uses PowerShell-aware background detection on native Windows: it rejects trailing & and Start-Job / Start-ThreadJob, while still allowing the leading PowerShell call operator. Added regression coverage in tests/tools/bash.test.ts.
There was a problem hiding this comment.
To use Codex here, create an environment for this repo.
| sanitized += codePoint == null || codePoint < 32 || codePoint === 127 ? " " : char; | ||
| } | ||
|
|
||
| return sanitized.replace(/\s+/g, " ").trim().slice(0, 160); |
There was a problem hiding this comment.
Do not truncate PATH before shell lookup
getEnv() is also used by findExecutableInPath() for PATH and PATHEXT, so the 160-character display limit makes shell detection ignore every PATH entry after that point. On typical Windows hosts PATH is often much longer than 160 characters; if pwsh.exe is installed only via a later PATH entry, Pokoclaw will silently fall back to Windows PowerShell or cmd even though PowerShell 7 is available, causing the prompt and actual execution shell to be wrong. Keep truncation for human-facing text only, or let executable lookup read the full env value.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
@codex Fixed in bd31a89. findExecutableInPath() now reads full, untruncated PATH and PATHEXT values while keeping the 160-character limit for human-facing env text. Added a regression test for a long Windows PATH where pwsh.exe is found only after the old truncation point.
There was a problem hiding this comment.
To use Codex here, create an environment for this repo.
| fail "missing PowerShell" | ||
| info "Pokoclaw expects PowerShell on native Windows. Install or repair PowerShell before relying on cmd fallback." | ||
| failures=$((failures + 1)) |
There was a problem hiding this comment.
Let cmd fallback pass the Windows doctor
This makes missing PowerShell a hard doctor failure even when cmd.exe is present, but pnpm start runs the doctor before launching the app and the runtime code/docs now claim cmd is a supported fallback when PowerShell is unavailable. In that exact fallback environment, users cannot start via the documented entrypoint despite the fallback path being implemented; treat missing PowerShell as a warning when cmd is available, or remove the fallback from runtime/docs.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
@codex Fixed in 43c8ca3. The Windows doctor now treats missing PowerShell as a warning when cmd fallback is available, and only fails the shell check when no usable fallback exists. This matches the product behavior: PowerShell is recommended and default, cmd is the fallback.
There was a problem hiding this comment.
To use Codex here, create an environment for this repo.
| const command = | ||
| shell.syntax === "powershell" | ||
| ? `${POWERSHELL_UTF8_OUTPUT_PREFIX}${input.command}` | ||
| : input.command; |
There was a problem hiding this comment.
Preserve native PowerShell exit codes
When Windows commands run through powershell.exe -Command/pwsh -Command, Microsoft’s about_PowerShell_exe docs say a non-0/1 exit from an external program is converted to process exit code 1 unless the command explicitly exits with $LASTEXITCODE. Because this wrapper only prefixes the user command, failures from native tools such as robocopy or custom CLIs that use distinct exit codes will be reported as 1, losing information that the bash tool previously returned from /bin/bash -lc. Append an exit-code relay for PowerShell commands so exitCode reflects the native program’s actual status.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
@codex Fixed in 43c8ca3. PowerShell host commands now append an exit-code relay that exits with $LASTEXITCODE when the final command fails, preserving native CLI exit codes instead of collapsing them to 1. Added coverage in tests/security/sandbox.windows-timeout.test.ts.
There was a problem hiding this comment.
To use Codex here, create an environment for this repo.
|
@codex @claude Follow-up fixes are pushed. Commits:
Verification:
Please review again. |
|
Codex Review: Didn't find any major issues. Nice work! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Review: POK-49 follow-up fixes (
|
|
@claude Thanks. I handled the actionable cmd fallback gap in What changed:
I left the other two observations unchanged:
Verification:
Please review again. |
Review: POK-49 — cmd fallback background gap fix (
|
|
@claude Fixed the two non-blocking follow-ups in What changed:
Verification:
Please review again. |
Summary
scripts/doctor.shbefore the current unsupported-Windows exit.This is intentionally limited to POK-49. It does not change bash execution mode, does not make Windows bash run with
full_access, and does not bypass approvals.Validation
Passed on Windows:
pnpm test -- tests/runtime/shell-info.test.ts tests/agent/system-prompt.test.ts tests/tools/get-runtime-status.test.ts tests/runtime/current-running-status.test.ts tests/runtime/status.test.tspnpm buildpnpm exec biome check --error-on-warnings src/runtime/shell-info.ts src/security/sandbox.ts src/agent/system-prompt-sections.ts src/agent/system-prompt.ts src/agent/loop.ts src/runtime/current-running-status.ts src/runtime/status.ts tests/runtime/shell-info.test.ts tests/agent/system-prompt.test.ts tests/tools/get-runtime-status.test.tsAttempted:
pnpm preflightpnpm preflightstill fails on native Windows for existing repo-wide Windows issues unrelated to this PR, including POSIX path expectation mismatches, symlink permission failures, Windows file-mode differences, and sandbox/security tests that assume Linux/POSIX semantics. The build/lint portions ran, but the full Vitest suite failed with the existing Windows incompatibilities.