Skip to content

Fix/62 windows fcntl - #160

Open
Alejo2304 wants to merge 23 commits into
FSoft-AI4Code:mainfrom
Alejo2304:fix/62-windows-fcntl
Open

Alejo2304 wants to merge 23 commits into
FSoft-AI4Code:mainfrom
Alejo2304:fix/62-windows-fcntl

Conversation

@Alejo2304

Copy link
Copy Markdown
Contributor

Summary

Fixes #62

This PR resolves remaining Windows compatibility issues so CodeWiki can run end-to-end on Windows (including the claude-code MCP workflow):

  • Direct claude.exe invocation on Windows (codewiki/src/be/caw_backend.py):
    • Previously, claude.cmd was wrapped through cmd.exe, which double-escaped quotes and split comma-separated --allowedTools arguments, preventing Claude CLI from seeing the CodeWiki MCP str_replace_editor tool.
    • Now claude.exe is resolved and invoked directly without cmd.exe/shell=True (with a fallback to claude.cmd if claude.exe is not found).
  • Replace POSIX-only commands (codewiki/src/fe/background_worker.py, codewiki/src/be/agent_tools/str_replace_editor.py):
    • Replaced rm -rf with cleanup_repo_directory() (which handles Windows read-only .git files).
    • Replaced find ... -maxdepth 2 in str_replace_editor directory view with a pure-Python Path.iterdir() traversal.
    • Updated flake8() to pass arguments as a list with shell=False so paths with spaces work on Windows.
  • Normalize line endings in MCP doc writer (codewiki/mcp/tools/doc_writer.py):
    • Added newline="\n" to write_text() calls so Windows \r\n conversion does not break str_replace matching.

Testing

  • Verified tests/test_mermaid_writers.py::test_mcp_write_edit_insert_undo_and_failed_edit passes on Windows after the doc_writer.py fix (13 passed in tests/test_mermaid_writers.py).
  • Ran uv run --active pytest -o addopts="" -q on Windows (760 passed; 8 failures in tests/test_zig_analyzer.py due to optional tree_sitter_zig not being installed in the local environment).
  • Verified codewiki generate --update with claude-code on Windows: confirmed ToolSearch discovers mcp__codewiki_tools_*__str_replace_editor, creates documentation files, and passes Mermaid validation without errors.

Testing was made with the provider claude_code and google.

Add a Windows compatibility loader for coding-agent-wrapper, whose caw.storage imports POSIX-only fcntl and whose optional TUI provider imports pty/termios. Invoke the installed claude.cmd through cmd.exe and force UTF-8 for text-mode subprocess pipes so real Claude Code sessions work from Python on Windows. Add a regression test for importing caw without POSIX modules.
Normalize repository-relative artifact paths with POSIX separators so dependency analysis produces stable JSON and prompt paths on Windows. Advertise Windows and POSIX platform support, document PowerShell setup and runtime prerequisites, and add a required windows-latest CI job covering the Windows compatibility, repository filtering, and timeout tests.
Keep the Windows-specific regression test tracked despite the repository test ignore rules. The test verifies that the subscription backend exports Agent and ToolGroup without requiring POSIX-only fcntl, pty, or termios modules.
Disable coding-agent-wrapper auto-wait for CodeWiki completion, update, and module agents. caw 0.1.10 classifies provider response text using broad limit/reset heuristics and can sleep for 60 minutes after a normal Claude response; CodeWiki now returns control to its caller instead of blocking indefinitely. Extend the usage-ledger regression test to assert the explicit setting.
Reuse the existing documentation guard reminders when a caw module agent returns without creating its page. This prevents markdown-only responses from being treated as successful runs and gives the agent bounded opportunities to write the required file. Add a regression test covering the missing-file retry path.
Create a fresh caw agent and toolkit for each bounded documentation-write retry. caw starts and stops MCP servers per completion, so reusing the same toolkit caused FastMCP to reject the second attempt with a single-use session manager error. Keep the original module prompt on retries and add the write reminder, with regression coverage for fresh agent instances.
Allow each CodeWiki toolkit operation with its full MCP permission name instead of only the server prefix. Claude Code's non-interactive permission resolver did not expose str_replace_editor from a server-only rule, causing agents to report that no write tool was available and leaving documentation pages unwritten. Add regression coverage for the generated allowed-tools rule.
Keep CodeWiki's MCP editor as the preferred documentation writer while enabling Claude Code Write and Edit tools when the CLI does not expose the custom toolkit. This prevents documentation generation from failing solely because str_replace_editor is unavailable, while the existing file guard still verifies every page. Update prompts and retain regression coverage for MCP permissions.
Tell Claude Code the exact absolute documentation path whenever the native Write or Edit fallback is used. The repository-root working directory is required for source access, but caused fallback writers to create pages outside docs; explicit paths keep the existing documentation guard and output layout consistent.
@Alejo2304
Alejo2304 force-pushed the fix/62-windows-fcntl branch from 5214683 to e2ea0f7 Compare November 15, 2026 14:48
@anhnh2002

Copy link
Copy Markdown
Collaborator

Thanks for working on Windows support. The changes are useful, but I’d like these addressed before merging:

  • Normalize only the path portion of component IDs; replacing backslashes in symbol names can merge distinct Lean declarations.
  • Record usage from every retry, rather than only the final attempt.
  • Avoid following directory symlinks outside the repository when listing files.
  • Install caw in Windows CI - the new compatibility test currently skips without it.
  • Address the claude.cmd fallback’s command-length limit for long system prompts.

The full suite passes locally on macOS (769 passed), but Windows still needs CI validation. Please also run Ruff formatting; three changed files currently fail the format check.

@Alejo2304

Copy link
Copy Markdown
Contributor Author

Thank you @anhnh2002, I'll be working on the required changes to get this merged.

This branch has not been deployed

No deployments
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.

Bug: No module named 'fcntl' on Windows

2 participants