Skip to content

Fix Windows nmem.cmd invocation in Copilot CLI hook#257

Merged
wey-gu merged 2 commits into
nowledge-co:mainfrom
mxi-box:fix-copilot-nmem-cmd-quoting
May 20, 2026
Merged

Fix Windows nmem.cmd invocation in Copilot CLI hook#257
wey-gu merged 2 commits into
nowledge-co:mainfrom
mxi-box:fix-copilot-nmem-cmd-quoting

Conversation

@mxi-box

@mxi-box mxi-box commented May 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fixes a Windows-specific nmem.cmd invocation failure in the Copilot CLI hook.
  • Keeps cmd.exe, nmem.cmd, and the remaining CLI arguments as separate argv entries.
  • Avoids pre-formatting the command with subprocess.list2cmdline, because subprocess.run([...]) performs Windows command-line conversion again.

Original Error

RuntimeError: '"C:\Users\xxxxxxxx\AppData\Local\Nowledge Mem\cli\nmem.CMD"' 不是内部或外部命令,也不是可运行的程序或批处理文件。

Reproduction

  1. Use Windows with the Nowledge Mem desktop app installed, so nmem.CMD resolves to a path like:

    C:\Users\<user>\AppData\Local\Nowledge Mem\cli\nmem.CMD
    
  2. Run the Copilot CLI plugin hook path that saves or imports a session through nowledge-mem-copilot-cli-plugin/hooks/copilot-stop-save.py.

  3. The hook builds the .cmd invocation with subprocess.list2cmdline(...), then passes that preformatted command string inside an argv list to subprocess.run(...).

  4. On Windows, subprocess.run([...]) converts argv to a command line again, so cmd.exe receives an over-quoted command name and fails with the error above.

Testing

uv run --with pytest pytest tests/test_copilot_plugin.py::TestBuildNmemCommand -v

The targeted command-building tests pass.

Note: running the full tests/test_copilot_plugin.py file locally on Windows also passes the updated command-building tests, but one unrelated existing test fails because hooks.json is read with the default GBK locale instead of UTF-8.

Summary by CodeRabbit

  • Bug Fixes

    • Improved Windows command invocation to prevent quoting/execution issues when running the CLI hook, improving reliability on Windows.
  • Chores

    • Bumped plugin/integration version to 0.1.2 and added a 0.1.2 changelog entry documenting the Windows fix.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 19, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dbf03774-31b0-49ee-806a-8f16000373bd

📥 Commits

Reviewing files that changed from the base of the PR and between 4c22d28 and dbc1ee1.

📒 Files selected for processing (5)
  • integrations.json
  • nowledge-mem-copilot-cli-plugin/.claude-plugin/plugin.json
  • nowledge-mem-copilot-cli-plugin/CHANGELOG.md
  • nowledge-mem-copilot-cli-plugin/hooks/copilot-stop-save.py
  • nowledge-mem-copilot-cli-plugin/tests/test_copilot_plugin.py
✅ Files skipped from review due to trivial changes (3)
  • nowledge-mem-copilot-cli-plugin/CHANGELOG.md
  • nowledge-mem-copilot-cli-plugin/.claude-plugin/plugin.json
  • integrations.json

📝 Walkthrough

Walkthrough

build_nmem_command now invokes Windows .cmd files via cmd.exe with /d /c call and argv-style arguments; the Windows test asserts the full command list. Plugin and integration versions updated to 0.1.2 and CHANGELOG updated.

Changes

Windows CMD execution

Layer / File(s) Summary
Windows CMD command build and test
nowledge-mem-copilot-cli-plugin/hooks/copilot-stop-save.py, nowledge-mem-copilot-cli-plugin/tests/test_copilot_plugin.py
build_nmem_command uses ["cmd.exe", "/d", "/c", "call", nmem_bin, *args] for .cmd on Windows; test test_windows_cmd asserts the exact command list.
Release metadata and changelog
nowledge-mem-copilot-cli-plugin/CHANGELOG.md, nowledge-mem-copilot-cli-plugin/.claude-plugin/plugin.json, integrations.json
Bump plugin and integration version to 0.1.2; add 0.1.2 changelog entry describing the Windows .cmd invocation fix.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • nowledge-co/community#231: Related change switching to an explicit cmd.exe bridge for invoking nmem.cmd with argv-style argument handling.

Poem

A rabbit taps the Windows shell,
"/d /c call" now rings the bell,
Args passed neat, no quoting fray,
Batch files hop and run their way. 🐰

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: fixing Windows nmem.cmd invocation in the Copilot CLI hook, which aligns with the core fix of changing command argument handling to prevent double quoting.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mxi-box mxi-box marked this pull request as draft May 19, 2026 10:16
Return cmd.exe and nmem.cmd arguments as argv entries so subprocess
performs command-line conversion only once on Windows. This fixes nmem.CMD
invocation failures when cmd.exe receives escaped quotes as part of the
command name.
@mxi-box mxi-box force-pushed the fix-copilot-nmem-cmd-quoting branch from 4c22d28 to 624dcb3 Compare May 19, 2026 10:23
@mxi-box mxi-box marked this pull request as ready for review May 19, 2026 10:24
@wey-gu wey-gu merged commit 7076692 into nowledge-co:main May 20, 2026
1 check passed
@wey-gu

wey-gu commented May 20, 2026

Copy link
Copy Markdown
Member

Thank you @mxi-box, this was a sharp Windows compatibility fix. Really appreciate you catching the nmem.cmd quoting edge case and helping make Copilot CLI smoother for users.

@mxi-box mxi-box deleted the fix-copilot-nmem-cmd-quoting branch May 22, 2026 05:40
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.

2 participants