[PR #20] [MERGED] Bug fix #24

Closed
opened 2026-02-27 13:59:32 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/GH05TCREW/pentestagent/pull/20
Author: @giveen
Created: 1/20/2026
Status: Merged
Merged: 1/20/2026
Merged by: @GH05TCREW

Base: mainHead: bug-fix


📝 Commits (8)

  • 0a79b5d WIP: save local edits (tui.py, .gitignore)
  • 5e6e4cd fix: heuristics for flags-only terminal commands; route semantic tools to terminal
  • ea9c69f fix(tui): append agent history when target set/restored so LLM sees changes
  • 00a7449 fix(tui): ensure workspace restores supersede manual target messages
  • 6b4a568 fix(tui): clear target and agent state when deactivating workspace
  • cabae0f feat(tui): add persistent header showing runtime/mode/target and keep it updated
  • 0219d83 fix(tui): avoid mount_before AttributeError by falling back to mount
  • 9de59f1 refactor(tui): use persistent header for target display; remove in-chat target duplicates

📊 Changes

4 files changed (+266 additions, -38 deletions)

View changed files

📝 .gitignore (+3 -0)
📝 pentestagent/agents/base_agent.py (+47 -1)
📝 pentestagent/interface/tui.py (+154 -37)
📝 pentestagent/tools/terminal/__init__.py (+62 -0)

📄 Description

Summary:
Fixes runtime and UX bugs that prevented tool execution and caused inconsistent target selection in the TUI. Improves robustness across Textual versions and makes the target visible and authoritative to the LLM.

What was broken:

  • TypeError when scheduling Textual workers: asyncio.create_task was given a Textual Worker (not a coroutine).
  • LLM-generated flags-only terminal commands (e.g. -p 1-1024 ...) were passed to /bin/sh and caused '/bin/sh: Illegal option -'.
  • Active workspace scope checks blocked scans when the target was not in the workspace, while stale/manual targets could persist in conversation and be used by the LLM.
  • UI errors on some Textual versions from calling unsupported APIs (e.g. ScrollableContainer.mount_before), and duplicated in-chat target messages cluttered the chat.

What I changed (key files):

  • pentestagent/interface/tui.py
    • Stop wrapping @work-decorated methods with asyncio.create_task; use the returned Worker correctly.
    • Ensure workspace activation/deactivation behavior: clear TUI/agent target on /workspace clear; restore last_target on activation.
    • When operator sets a manual target (/target), append a short system AgentMessage so the LLM sees the change; track manual target and remove/supersede it when a workspace restores its saved target.
    • Add a persistent header widget to display runtime/mode/target and remove duplicate in-chat target lines.
    • Guard mount_before calls with a try/fallback to mount to support Textual versions without mount_before.
  • pentestagent/agents/base_agent.py
    • If a requested tool name is not found, fall back to the terminal tool and construct a best-effort command string from function-call arguments so semantic tool names (e.g., nmap) execute.
    • Preserve workspace-scope validation but return explicit errors that instruct the operator how to proceed.
  • pentestagent/tools/terminal/__init__.py
    • Detect flags-only command strings and prefix them with a likely binary (nmap, gobuster, rustscan, masscan, curl, wget, etc.) using runtime-detected tools, preventing shell option errors.
    • Make terminal execution tolerant to malformed inputs and avoid uncaught exceptions.

Rationale:
Textual workers are Worker objects; scheduling them as coroutines caused runtime errors. Handling Worker objects correctly preserves Textual semantics. LLMs sometimes emit partial or semantic commands; best-effort normalization reduces shell failures and improves task success. The LLM relies on conversation history for state (target): explicit system messages and deterministic workspace restores ensure the LLM uses the intended target. A persistent header provides immediate operator context and avoids losing the active target when the chat scrolls.

Testing performed:

  • Reproduced and fixed the Worker scheduling TypeError.
  • Verified flags-only commands are now prefixed (nmap test) and no longer produce '/bin/sh: Illegal option -'.
  • Walked through UI flows: create/activate workspace, /workspace clear, /target , re-activate workspace — confirmed authoritative target behavior and header updates.
  • Confirmed mount_before fallback removes AttributeError on environments without that method.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/GH05TCREW/pentestagent/pull/20 **Author:** [@giveen](https://github.com/giveen) **Created:** 1/20/2026 **Status:** ✅ Merged **Merged:** 1/20/2026 **Merged by:** [@GH05TCREW](https://github.com/GH05TCREW) **Base:** `main` ← **Head:** `bug-fix` --- ### 📝 Commits (8) - [`0a79b5d`](https://github.com/GH05TCREW/pentestagent/commit/0a79b5d54e3e3df2c56611af27d46ec919b4454d) WIP: save local edits (tui.py, .gitignore) - [`5e6e4cd`](https://github.com/GH05TCREW/pentestagent/commit/5e6e4cd44ce8ac28586ad48d6cf48734ca0b3a83) fix: heuristics for flags-only terminal commands; route semantic tools to terminal - [`ea9c69f`](https://github.com/GH05TCREW/pentestagent/commit/ea9c69fe222faef130219265c1b6ee07ec18bfb2) fix(tui): append agent history when target set/restored so LLM sees changes - [`00a7449`](https://github.com/GH05TCREW/pentestagent/commit/00a7449293ce37029b70103e592ac970bdd4c9e5) fix(tui): ensure workspace restores supersede manual target messages - [`6b4a568`](https://github.com/GH05TCREW/pentestagent/commit/6b4a56847943571466355351763d526dcd4b5ad6) fix(tui): clear target and agent state when deactivating workspace - [`cabae0f`](https://github.com/GH05TCREW/pentestagent/commit/cabae0fcd6f50f3c225e8edcd522634427de0d69) feat(tui): add persistent header showing runtime/mode/target and keep it updated - [`0219d83`](https://github.com/GH05TCREW/pentestagent/commit/0219d8367fa27c53c23035d564a1a404b54f0083) fix(tui): avoid mount_before AttributeError by falling back to mount - [`9de59f1`](https://github.com/GH05TCREW/pentestagent/commit/9de59f1d0088f4ac54de32d270ff370371ee05ce) refactor(tui): use persistent header for target display; remove in-chat target duplicates ### 📊 Changes **4 files changed** (+266 additions, -38 deletions) <details> <summary>View changed files</summary> 📝 `.gitignore` (+3 -0) 📝 `pentestagent/agents/base_agent.py` (+47 -1) 📝 `pentestagent/interface/tui.py` (+154 -37) 📝 `pentestagent/tools/terminal/__init__.py` (+62 -0) </details> ### 📄 Description Summary: Fixes runtime and UX bugs that prevented tool execution and caused inconsistent target selection in the TUI. Improves robustness across Textual versions and makes the target visible and authoritative to the LLM. What was broken: - TypeError when scheduling Textual workers: asyncio.create_task was given a Textual Worker (not a coroutine). - LLM-generated flags-only terminal commands (e.g. -p 1-1024 ...) were passed to /bin/sh and caused '/bin/sh: Illegal option -'. - Active workspace scope checks blocked scans when the target was not in the workspace, while stale/manual targets could persist in conversation and be used by the LLM. - UI errors on some Textual versions from calling unsupported APIs (e.g. ScrollableContainer.mount_before), and duplicated in-chat target messages cluttered the chat. What I changed (key files): - pentestagent/interface/tui.py - Stop wrapping @work-decorated methods with asyncio.create_task; use the returned Worker correctly. - Ensure workspace activation/deactivation behavior: clear TUI/agent target on /workspace clear; restore last_target on activation. - When operator sets a manual target (/target), append a short system AgentMessage so the LLM sees the change; track manual target and remove/supersede it when a workspace restores its saved target. - Add a persistent header widget to display runtime/mode/target and remove duplicate in-chat target lines. - Guard mount_before calls with a try/fallback to mount to support Textual versions without mount_before. - pentestagent/agents/base_agent.py - If a requested tool name is not found, fall back to the terminal tool and construct a best-effort command string from function-call arguments so semantic tool names (e.g., nmap) execute. - Preserve workspace-scope validation but return explicit errors that instruct the operator how to proceed. - pentestagent/tools/terminal/__init__.py - Detect flags-only command strings and prefix them with a likely binary (nmap, gobuster, rustscan, masscan, curl, wget, etc.) using runtime-detected tools, preventing shell option errors. - Make terminal execution tolerant to malformed inputs and avoid uncaught exceptions. Rationale: Textual workers are Worker objects; scheduling them as coroutines caused runtime errors. Handling Worker objects correctly preserves Textual semantics. LLMs sometimes emit partial or semantic commands; best-effort normalization reduces shell failures and improves task success. The LLM relies on conversation history for state (target): explicit system messages and deterministic workspace restores ensure the LLM uses the intended target. A persistent header provides immediate operator context and avoids losing the active target when the chat scrolls. Testing performed: - Reproduced and fixed the Worker scheduling TypeError. - Verified flags-only commands are now prefixed (nmap test) and no longer produce '/bin/sh: Illegal option -'. - Walked through UI flows: create/activate workspace, /workspace clear, /target <ip>, re-activate workspace — confirmed authoritative target behavior and header updates. - Confirmed mount_before fallback removes AttributeError on environments without that method. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-27 13:59:32 -05:00
yindo closed this issue 2026-02-27 13:59:32 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: yindo/pentestagent#24