Skip to content

feat(tools): add transactional patching, managed PTY sessions, and bounded process capture - #7113

Open
cuiyuebing wants to merge 14 commits into
agentscope-ai:mainfrom
cuiyuebing:cy/dev_tools
Open

feat(tools): add transactional patching, managed PTY sessions, and bounded process capture#7113
cuiyuebing wants to merge 14 commits into
agentscope-ai:mainfrom
cuiyuebing:cy/dev_tools

Conversation

@cuiyuebing

Copy link
Copy Markdown
Member

Summary

This PR strengthens QwenPaw’s tool layer with three related capabilities:

  • A transactional apply_patch primitive
  • Persistent managed PTY shell sessions
  • Lifecycle-managed, bounded background output capture

What changed

Transactional patching

  • Add a dedicated qwenpaw.patching module.
  • Support multi-file and multi-hunk patches.
  • Support add, update, delete, and rename operations.
  • Validate hunk context before writing.
  • Report structured conflicts without partially modifying the workspace.
  • Preserve BOM, newline style, final newline state, and file permissions.
  • Stage changes and roll back failed multi-file commits.

Managed terminal sessions

  • Extend execute_shell_command with managed-session options.
  • Add session IDs, persistent cwd/environment state, and PTY support.
  • Add write_stdin for input, polling, Ctrl-C, and termination.
  • Support interactive programs and long-running commands.
  • Normalize common Ctrl-C representations and make repeated interrupts idempotent.
  • Prevent internal completion markers from leaking into interactive stdin.
  • Expose terminal state and output metrics in both text and metadata:
    • running
    • exit_code
    • original_bytes
    • omitted_bytes
    • output_bytes
    • pending_bytes
    • output_drained
  • Keep sessions available until buffered output is drained.
  • Distinguish command exit status from terminal termination status.

Background capture and cleanup

  • Add bounded, cursor-based BackgroundCapture.
  • Drain process output independently of tool-call consumption.
  • Add process-group/tree lifecycle supervision.
  • Clean up sessions during timeout, cancellation, workspace shutdown, and TTL expiry.
  • Prevent detached/nohup descendants from retaining unreachable output handles.
  • Add POSIX PTY, Windows ConPTY, and explicit degraded pipe fallback support.
  • Keep blocking PTY, ConPTY, and filesystem operations off the asyncio event loop.

Security and integration

  • Register the new tools and workspace terminal manager.
  • Extend file and shell guardians for patch targets and terminal input.
  • Fail closed when the selected sandbox cannot provide managed sessions.
  • Update Coding Mode guidance to prefer contextual apply_patch operations.

Validation

  • Associated regression suite: 607 passed, 1 skipped
  • Focused terminal and guardian suite: 123 passed
  • pre-commit run --all-files: passed
  • Includes regression coverage for:
    • Persistent cwd and environment state
    • Interactive stdin
    • Ctrl-C followed by session reuse
    • Bounded 2 MB output capture and complete draining
    • Multi-hunk patching and structured conflicts
    • Transaction rollback and sensitive-path protection

Compatibility

  • Existing one-shot shell behavior remains available.
  • Existing file-editing tools remain available for compatibility.
  • Managed sessions fail closed under unsupported sandbox backends.
  • Windows uses ConPTY when available and reports pipe fallback with
    tty=false and degraded=true.

@github-actions

Copy link
Copy Markdown

Welcome to QwenPaw! 🐾

Hi @cuiyuebing, this is your 72nd Pull Request.

📋 About PR Template

To help maintainers review your PR faster, please make sure to include:

  • Description - What this PR does and why
  • Type of Change - Bug fix / Feature / Breaking change / Documentation / Refactoring
  • Component(s) Affected - Core / Console / Channels / Skills / CLI / Documentation / Tests / CI/CD / Scripts
  • Checklist:
    • Run and pass pre-commit run --all-files
    • Run and pass relevant tests (pytest or as applicable)
    • Update documentation if needed
  • Testing - How to test these changes
  • Local Verification Evidence:
    pre-commit run --all-files
    # paste summary result
    
    pytest
    # paste summary result

Complete PR information helps speed up the review process. You can edit the PR description to add these details.

🙌 Join Developer Community

Thanks so much for your contribution! We'd love to invite you to join the official QwenPaw developer group! You can find the Discord and DingTalk group links under the "Developer Community" section on our docs page:
https://qwenpaw.agentscope.io/docs/community

We truly appreciate your enthusiasm—and look forward to your future contributions! 😊

We'll review your PR soon.

@cuiyuebing
cuiyuebing requested a deployment to maintainer-approved August 18, 2026 10:29 — with GitHub Actions Waiting
@cuiyuebing
cuiyuebing deployed to maintainer-approved August 19, 2026 02:12 — with GitHub Actions Active
@cuiyuebing
cuiyuebing deployed to maintainer-approved August 19, 2026 06:14 — with GitHub Actions Active
@cuiyuebing
cuiyuebing deployed to maintainer-approved August 20, 2026 08:40 — with GitHub Actions Active
@cuiyuebing
cuiyuebing deployed to maintainer-approved August 21, 2026 04:30 — with GitHub Actions Active
@cuiyuebing
cuiyuebing marked this pull request as ready for review August 21, 2026 05:36
Copilot AI lite review requested due to automatic review settings August 21, 2026 05:36

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@cuiyuebing
cuiyuebing deployed to maintainer-approved August 24, 2026 02:20 — with GitHub Actions Active
@cuiyuebing
cuiyuebing deployed to maintainer-approved August 24, 2026 06:08 — with GitHub Actions Active
@cuiyuebing
cuiyuebing deployed to maintainer-approved August 24, 2026 06:58 — with GitHub Actions Active
…ools

# Conflicts:
#	src/qwenpaw/agents/tools/shell.py
#	src/qwenpaw/hooks/request_setup/contextvars_hook.py
#	src/qwenpaw/modes/coding/mixin.py
@cuiyuebing
cuiyuebing deployed to maintainer-approved August 24, 2026 08:53 — with GitHub Actions Active
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants