Skip to content

fix: harden process tools and validation#551

Open
ShiroKSH wants to merge 2 commits into
wonderwhy-er:mainfrom
ShiroKSH:agent/desktop-commander-hardening
Open

fix: harden process tools and validation#551
ShiroKSH wants to merge 2 commits into
wonderwhy-er:mainfrom
ShiroKSH:agent/desktop-commander-hardening

Conversation

@ShiroKSH

@ShiroKSH ShiroKSH commented Jul 9, 2026

Copy link
Copy Markdown

Summary

  • prevent invalid shells and invalid PIDs from crashing or affecting unintended processes
  • fix Windows process listing, configured read limits, PDF output-path validation, and terminal usage tracking
  • make tool validation work from a clean checkout
  • make test failures propagate to the process exit status and fix the Windows REPL test
  • update stale tool names and installation instructions

Root causes

  • process and tool schemas were looser than their runtime contracts
  • Windows tasklist output was parsed as whitespace-delimited text even though process names can contain spaces
  • generated MCPB files were required by validation even though they are gitignored
  • several test entrypoints resolved false without setting a failing exit code

Validation

  • npm run build
  • npm test — 45/45
  • npm run test:integration — 3/3
  • npm run validate:tools
  • targeted schema, process, symlink, timeout, and enhanced REPL tests
  • npm ci --ignore-scripts

No business logic or release version was changed.

Summary by CodeRabbit

  • New Features

    • Updated user guidance to emphasize process-based streaming, including continuing output retrieval by PID, plus expanded shell examples and notebook workflow clarification.
  • Bug Fixes

    • Improved long-running process reliability with better timeout and error handling.
    • Fixed Windows process listing parsing, strengthened PID/path validation, and improved config error signaling.
    • Corrected installer status/help text references.
  • Tests

    • Added schema/process-list regression coverage and standardized direct test failure handling via a shared helper.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 848f3012-15b9-47c7-8e07-bf668c61e116

📥 Commits

Reviewing files that changed from the base of the PR and between 63172d7 and 0be4edf.

📒 Files selected for processing (1)
  • src/tools/process.ts

📝 Walkthrough

Walkthrough

The PR updates process tool contracts and execution, cross-platform process listing, path/config validation, test entrypoints, and related documentation and guidance.

Changes

Core tooling updates

Layer / File(s) Summary
Documentation and operational guidance
FAQ.md, README.md, install-docker.ps1, scripts/validate-tools-sync.js, src/server.ts, src/handlers/terminal-handlers.ts, src/tools/improved-process-tools.ts
Process guidance now uses start_process and read_process_output, installer text points to install-docker.ps1, manifest validation reads manifest.template.json, and terminal/tool descriptions are updated.
Process execution and tool contracts
src/tools/schemas.ts, src/terminal-manager.ts, src/tools/process.ts, src/utils/usageTracker.ts
Process schemas now default or constrain timeout/PID values, command execution handles spawn errors and timeout cleanup, process listing is platform-specific, and terminal tool usage tracking matches the new tool names.
Path and configuration validation
src/tools/config.ts, src/tools/edit.ts, src/tools/filesystem.ts
Configuration failures are marked with isError, edit output paths are validated before use, and path lowercasing is limited to Windows.
Test execution and regression coverage
test/exit-on-failure.js, test/test-*.js, test/test-schema-regressions.js
Direct test entrypoints use a shared failure wrapper, shell detection becomes platform-aware, and regression coverage checks schema defaults, PID validation, and Windows process output.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ToolCaller
  participant start_process
  participant TerminalManager
  participant ChildProcess
  participant read_process_output
  ToolCaller->>start_process: submit command and timeout
  start_process->>TerminalManager: execute command
  TerminalManager->>ChildProcess: spawn process
  ChildProcess-->>TerminalManager: initial output, timeout, or error
  TerminalManager-->>start_process: return result
  ToolCaller->>read_process_output: request output by PID
  read_process_output->>ChildProcess: retrieve additional output
Loading

Possibly related PRs

Suggested labels: size:XL

Suggested reviewers: serg33v, edgarsskore

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% 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 accurately summarizes the main theme of the PR: hardening process tools and validation.
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.
✨ 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.

@ShiroKSH ShiroKSH marked this pull request as ready for review July 9, 2026 21:37

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
test/test-edit-block-occurrences.js (1)

354-356: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Move the runTest import to the top of the file.

The import { runTest } from './exit-on-failure.js' at line 356 is placed after its usage at line 354. While ESM hoists imports so this works, it's inconsistent with the other test files in this PR (test-repl-interaction.js line 7, test.js line 7) which place the import at the top. Move it alongside the other imports for clarity and consistency.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/test-edit-block-occurrences.js` around lines 354 - 356, Move the
`runTest` import in `test-edit-block-occurrences.js` to the top with the other
imports for consistency. Update the module so `runTest` is declared before it is
used in the `runTests`/`runTest(runTests)` flow, matching the pattern used in
`test-repl-interaction.js` and `test.js`.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/tools/process.ts`:
- Around line 55-66: The non-Windows process parsing path in process.ts is
missing the same PID validation used in the Windows branch. Update the
map/filter chain that builds ProcessInfo objects from ps aux output so malformed
lines with an invalid or NaN pid are discarded before returning results,
mirroring the existing Windows logic in the process listing function.

---

Nitpick comments:
In `@test/test-edit-block-occurrences.js`:
- Around line 354-356: Move the `runTest` import in
`test-edit-block-occurrences.js` to the top with the other imports for
consistency. Update the module so `runTest` is declared before it is used in the
`runTests`/`runTest(runTests)` flow, matching the pattern used in
`test-repl-interaction.js` and `test.js`.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0b325227-5814-479a-8c91-d27028e8b2b6

📥 Commits

Reviewing files that changed from the base of the PR and between bdb1a7b and 63172d7.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (25)
  • FAQ.md
  • README.md
  • install-docker.ps1
  • scripts/validate-tools-sync.js
  • src/handlers/terminal-handlers.ts
  • src/server.ts
  • src/terminal-manager.ts
  • src/tools/config.ts
  • src/tools/edit.ts
  • src/tools/filesystem.ts
  • src/tools/improved-process-tools.ts
  • src/tools/process.ts
  • src/tools/schemas.ts
  • src/utils/usageTracker.ts
  • test/exit-on-failure.js
  • test/test-allowed-directories.js
  • test/test-blocked-commands.js
  • test/test-default-shell.js
  • test/test-directory-creation.js
  • test/test-edit-block-occurrences.js
  • test/test-enhanced-repl.js
  • test/test-home-directory.js
  • test/test-repl-interaction.js
  • test/test-schema-regressions.js
  • test/test.js

Comment thread src/tools/process.ts Outdated
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.

1 participant