Skip to content

Conversation

liangfung
Copy link
Contributor

@liangfung liangfung commented Oct 14, 2025

Summary

This PR introduces support for executing bash commands within Pochi workflows.

  • Extracts bash commands (prefixed with `!``) from the workflow's markdown content.
  • Executes the commands and integrates the output back into the chat context.
  • Updates related components and tests to support this new functionality.

Test plan

  • Existing tests were updated to cover the new parsing logic.
  • Manual verification of a workflow using bash commands.

🤖 Generated with Pochi

- Add new bash command execution functionality for workflows
- Parse allowed-tools from workflow frontmatter as raw strings
- Extract and validate bash commands from workflow content
- Execute validated commands with proper abort signal handling
- Integrate bash command execution into live chat kit
- Update workflow prompt generation to include allowed-tools attribute
- Add micromatch dependency for pattern matching
@zwpaper
Copy link
Member

zwpaper commented Oct 15, 2025

/pochi summary this pr

Copy link
Contributor

github-actions bot commented Oct 15, 2025

Pochi Completed

- Initializing MCP connections...
You
summary this pr   

Pochi
I'll help you understand this pull request. Let me first check out the PR branch to examine the changes.   
💫 Executing gh pr checkout 554 ✔ 
Now let me examine the PR details to understand what changes were made.   
💫 Executing gh pr view 554 ✔ 
Let me look at the file changes in this PR to understand what was implemented.   
💫 Executing gh pr diff 554 ✔ 
Let me get the rest of the diff to understand the full scope of changes.   
💫 Executing gh pr diff 554 | tail -n +3000 ✔ 
Let me check specific files that were added or modified to better understand the implementation.   
📖 Reading packages/livekit/src/chat/llm/bash-command-execute.ts ✔ 
Now let me check the workflow parser to understand how the frontmatter is being parsed:   
📖 Reading packages/common/src/tool-utils/workflow-parser.ts ✔ 
Let me also check how the workflow prompt is created to understand how the allowed-tools are integrated:   
📖 Reading packages/common/src/base/prompts/index.ts ✔ 
Let me also check how the bash command execution is implemented in the VS Code extension:   
📖 Reading packages/vscode/src/integrations/webview/vscode-host-impl.ts ✔ 
Let me create a summary of this PR based on my analysis:   
🎉 Task Completed
# Summary of PR #554: "feat: Support bash command execution for Pochi workflows"

## Overview
This PR introduces support for executing bash commands within Pochi workflows. It allows workflows to define allowed tools in their frontmatter and enables the extraction and execution of bash commands from workflow content, with proper security controls.

## Key Features

### 1. Workflow Frontmatter Parsing
- Added support for parsing `allowed-tools` field in workflow frontmatter
- Uses `gray-matter` library instead of `remark` and `vfile-matter` for more efficient parsing
- The `allowed-tools` field defines which tools can be used in a workflow

### 2. Bash Command Extraction
- Extracts bash commands prefixed with `` !` `` from workflow markdown content
- Commands are validated against allowed patterns defined in the workflow's frontmatter
- Uses `micromatch` for pattern matching to determine if a command is allowed

### 3. Command Execution
- Implements secure bash command execution with proper error handling
- Commands are executed in the context of the current workspace directory
- Supports abort signals to cancel long-running commands
- Captures both stdout and stderr output

### 4. Integration Points
- Added `executeBashCommand` method to VS Code webview bridge
- Extended workflow prompt generation to include allowed-tools attribute
- Modified LiveChatKit to process bash commands from user messages before sending to LLM

## Technical Implementation

### Workflow Frontmatter Example
```markdown
---
allowed-tools: Bash(ls:* , find:*, cat:*)
---

Command Syntax in Workflows

To list files, use: !`ls -la`
To find files: !`find . -name "*.ts"`

Security Measures

  • Commands are validated against allowed patterns before execution
  • Uses glob patterns and special syntax (:*) for flexible but controlled access
  • Execution is sandboxed to the current workspace directory
  • Proper error handling and signal aborting for long-running commands

Files Modified

  • Core workflow parsing logic in packages/common
  • Bash command execution implementation in packages/livekit
  • VS Code integration in packages/vscode
  • UI components in packages/vscode-webui
  • Dependency updates in package.json files

Testing

  • Existing tests were updated to cover the new parsing logic
  • Manual verification of workflows using bash commands was performed

🔗 **[View GitHub Action](https://github.com/TabbyML/pochi/actions/runs/18515423717)**

@liangfung liangfung changed the title feat: Support bash command execution for Pochi workflows feat(vscode): Support bash command execution for Pochi workflows Oct 15, 2025
@liangfung liangfung marked this pull request as ready for review October 15, 2025 06:05
@liangfung liangfung marked this pull request as draft October 15, 2025 06:40
@liangfung liangfung marked this pull request as ready for review October 15, 2025 06:54
Copy link
Member

@wsxiaoys wsxiaoys left a comment

Choose a reason for hiding this comment

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

Please also include jam.dev link for an e2e test

Copy link
Contributor

github-actions bot commented Oct 15, 2025

PR Preview Action v1.6.2

🚀 View preview at
https://TabbyML.github.io/pochi/pr-preview/pr-554/

Built to branch gh-pages at 2025-10-16 04:11 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@liangfung liangfung changed the title feat(vscode): Support bash command execution for Pochi workflows feat(cli, vscode): Support bash command execution for Pochi workflows Oct 15, 2025
@liangfung liangfung marked this pull request as draft October 15, 2025 10:26
@liangfung liangfung marked this pull request as ready for review October 15, 2025 12:24
@liangfung liangfung marked this pull request as draft October 15, 2025 15:20
@liangfung liangfung marked this pull request as ready for review October 15, 2025 16:34
@liangfung
Copy link
Contributor Author

#541

@wsxiaoys
Copy link
Member

/pochi please adress pr comment

Copy link
Contributor

github-actions bot commented Oct 17, 2025

🔄 Pochi Running...

- Initializing MCP connections...
You
please adress pr comment   

Pochi
I'll help address the PR comment. First, let me check out the PR branch and understand what the comment is about.   
💫 Executing gh pr checkout 554 ✔ 
Now let me check the PR comments to understand what needs to be addressed.   
💫 Executing gh pr view --comments ✔ 
Let me check the specific PR details to understand what changes were made and what comment needs to be addressed.   
💫 Executing gh pr view 554 ✔ 
Let me check the specific comment that needs to be addressed.   
💫 Executing gh api repos/TabbyML/pochi/pulls/554/comments ✔ 
Let me get the complete comments by checking the PR diff to understand all the changes that were made.   
💫 Executing gh pr diff 554 ✔ 
Now let me check the specific comments that need to be addressed. Based on the comments I've seen, I need to address several issues: 1. Move the `extractWorkflowBashCommands` function to the prompts package 2. Remove the `onExecuteBashCommand` from LiveChatKitOptions 3. Fix the timeout value in VSCodeHostImpl 4. Improve documentation about how bash command output is injected into prompts 5. Extract the onOverrideMessages logic to a separate file Let me start by creating a todo list to track these changes:   
📋 Updating todo list (6 items) ✔ 
Let me start addressing the PR comments one by one. First, let me check the current state of the files to understand what needs to be changed.   
📖 Reading packages/common/src/message-utils/workflow.ts ✔ 
📖 Reading packages/common/src/base/prompts/inject-bash-outputs.ts ✔ 
Now I'll start addressing the comments. First, let me move the `extractWorkflowBashCommands` function to the prompts package as requested:   
📋 Updating todo list (1 items) ✔ 
✏️  Writing packages/common/src/base/prompts/extract-bash-commands.ts ✔ 
Now I need to update the index.ts file in the prompts package to export this new function:   
📖 Reading packages/common/src/base/prompts/index.ts ✔ 
🔧 Applying diff to packages/common/src/base/prompts/index.ts ✔ 
🔧 Applying diff to packages/common/src/base/prompts/index.ts ✔ 
Now I need to update the message-utils to remove the export of extractWorkflowBashCommands:   
📖 Reading packages/common/src/message-utils/index.ts ✔ 
🔧 Applying diff to packages/common/src/message-utils/index.ts ✔ 
Now I need to remove the workflow.ts file from message-utils since it's no longer needed:   
💫 Executing rm packages/common/src/message-utils/workflow.ts ✔ 
Let me update the test file to import from the new location:   
📖 Reading packages/common/src/message-utils/__tests__/workflow.test.ts ✔ 
🔧 Applying diff to packages/common/src/message-utils/__tests__/workflow.test.ts ✔ 
Now I need to update the CLI on-override-messages.ts file to import from the new location:   
📖 Reading packages/cli/src/on-override-messages.ts ✔ 
🔧 Applying diff to packages/cli/src/on-override-messages.ts ✔ 
Now I need to update the VS Code webui on-override-messages.ts file:   
📖 Reading packages/vscode-webui/src/features/chat/lib/on-override-messages.ts ✔ 
🔧 Applying diff to packages/vscode-webui/src/features/chat/lib/on-override-messages.ts ✔ 
Now let me mark this task as complete and move on to the next one:   
📋 Updating todo list (1 items) ✔ 
Next, I need to remove the `onExecuteBashCommand` from LiveChatKitOptions:   
📋 Updating todo list (1 items) ✔ 
📖 Reading packages/livekit/src/chat/live-chat-kit.ts ✔ 
I don't see the `onExecuteBashCommand` in the LiveChatKitOptions. Let me check if it was already removed or if I need to look elsewhere.   
💫 Executing git log --oneline -n 10 ✔ 
Let me check what was in the previous version:   
💫 Executing git show 51c9ccd8:packages/livekit/src/chat/live-chat-kit.ts | grep -A 20 -B 5 "onExecuteBashCommand" ✔ 
Let me check the diff to see what was changed:   
💫 Executing git show 51c9ccd8 ✔ 
Let me check an earlier commit to see if there was an `onExecuteBashCommand` in LiveChatKitOptions:   
💫 Executing git show daed2b81:packages/livekit/src/chat/live-chat-kit.ts | grep -A 10 -B 10 "onExecuteBashCommand" ✔ 
Let me check the diff from that commit:   
💫 Executing git show daed2b81 ✔ 
Now I can see that the `onExecuteBashCommand` was indeed removed from LiveChatKitOptions in that commit, and the functionality was moved to the onOverrideMessages function. So this task is already completed. Let me mark it as done:   
📋 Updating todo list (1 items) ✔ 
Next, let me fix the timeout value in VSCodeHostImpl:   
📋 Updating todo list (1 items) ✔ 
📖 Reading packages/vscode/src/integrations/webview/vscode-host-impl.ts ✔ 
I can see that the timeout value is already set to 10. Let me check if there are any other instances:   
💫 Executing grep -r "timeout.*120" packages/vscode/src/integrations/webview/ ✔ 
Let me check if there are any other instances of timeout with value 120:   
💫 Executing grep -r "timeout.*120" packages/vscode/ ✔ 
Let me check the git history to see what was changed:   
💫 Executing git show 51c9ccd8:packages/vscode/src/integrations/webview/vscode-host-impl.ts | grep -A 5 -B 5 "timeout.*120" ✔ 
I can see that the timeout was changed from 120 to 10, which is what was requested. This task is already completed. Let me mark it as done:   
📋 Updating todo list (1 items) ✔ 
Now let me update the documentation to better explain how bash command output is injected into prompts:   
📋 Updating todo list (1 items) ✔ 
📖 Reading packages/docs/content/docs/workflows.mdx ✔ 
I can see that the documentation already explains how bash command outputs are injected into prompts. However, let me make it a bit clearer by adding more specific details about the injection process:   
🔧 Applying diff to packages/docs/content/docs/workflows.mdx ✔ 

🔗 View GitHub Action

@wsxiaoys wsxiaoys enabled auto-merge October 17, 2025 05:36
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 38.61386% with 124 lines in your changes missing coverage. Please review.
✅ Project coverage is 20.14%. Comparing base (ce46f08) to head (a2946be).
⚠️ Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
packages/cli/src/on-override-messages.ts 0.00% 48 Missing and 1 partial ⚠️
...ebui/src/features/chat/lib/on-override-messages.ts 0.00% 37 Missing ⚠️
...scode/src/integrations/webview/vscode-host-impl.ts 0.00% 30 Missing ⚠️
...ges/common/src/vscode-webui-bridge/webview-stub.ts 16.66% 5 Missing ⚠️
packages/cli/src/task-runner.ts 0.00% 2 Missing ⚠️
packages/vscode-webui/src/lib/vscode.ts 0.00% 1 Missing ⚠️

❌ Your patch status has failed because the patch coverage (38.61%) is below the target coverage (75.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff            @@
##           main     #554       +/-   ##
=========================================
+ Coverage      0   20.14%   +20.14%     
=========================================
  Files         0      520      +520     
  Lines         0    41943    +41943     
  Branches      0     1173     +1173     
=========================================
+ Hits          0     8450     +8450     
- Misses        0    33284    +33284     
- Partials      0      209      +209     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wsxiaoys wsxiaoys added this pull request to the merge queue Oct 17, 2025
Merged via the queue into main with commit 06a5e02 Oct 17, 2025
3 checks passed
@wsxiaoys wsxiaoys deleted the feat/bash-command-execution-workflows branch October 17, 2025 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.

4 participants