bashterm-mcp 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,57 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [0.1.7] - 2026-05-29
6
+
7
+ ### Added
8
+ - Windows 平台完整支持:IPC 改用 Windows named pipe
9
+ - 命令执行改用 `child_process.exec()` 直接捕获输出,兼容所有平台
10
+ - Windows 下自动检测并解码 GBK 中文输出
11
+
12
+ ### Fixed
13
+ - 修复 Windows 上 Unix socket `EACCES` 权限错误
14
+ - 修复 Shell Integration API 在不支持的终端环境下不触发的问题
15
+ - 修复 Windows 中文输出乱码
16
+
17
+ ## [0.1.6] - 2026-03-19 18:18 PDT
18
+
19
+ ### Added
20
+ - Screenshots in README for marketplace (run, exec, permission dialog)
21
+ - Custom terminal tab names with date format (e.g., `MCP: BashTerm-26-03-19-17-30`)
22
+ - `name` parameter in `run` tool for custom terminal names
23
+ - Unique IPC socket per workspace to prevent conflicts between multiple VSCode instances
24
+ - Large output handling documentation
25
+ - Development workflow docs for extension cache workaround
26
+
27
+ ### Fixed
28
+ - Clean output format for all tools (`run`, `exec`, `read`, `list`, `close`, `input`) — no more raw JSON responses
29
+ - `waitForCompletion: false` not working (`z.coerce.boolean()` converted string `"false"` to `true`)
30
+ - Idle reaper killing sessions with running commands — reaper disabled, user closes sessions manually
31
+
32
+ ## [0.1.5] - 2026-03-18 14:50 PDT
33
+
34
+ ### Added
35
+ - npm publish with `bin` entry for `npx bashterm-mcp` support
36
+ - Published to VSCode Marketplace and MCP Registry
37
+
38
+ ## [0.1.3] - 2026-03-18 11:00 PDT
39
+
40
+ ### Added
41
+ - `run` tool combining create + exec in one step
42
+ - Session reuse: `run` finds idle sessions before creating new ones
43
+ - Busy session detection: won't reuse sessions with running commands
44
+
45
+ ### Fixed
46
+ - First-command timing fix with shell initialization delay
47
+
48
+ ## [0.1.0] - 2026-03-18 10:00 PDT
49
+
50
+ ### Added
51
+ - Initial release
52
+ - Tools: `create`, `exec`, `read`, `input`, `list`, `close`
53
+ - Shell Integration API for output capture and exit code detection
54
+ - Circular output buffer with pagination support
55
+ - Subagent isolation with `agentId`
56
+ - Command blocklist security
57
+ - IPC bridge for MCP stdio-to-socket communication
package/CLAUDE.md ADDED
@@ -0,0 +1,84 @@
1
+ # Project: bashterm-mcp
2
+
3
+ MCP server that runs commands in visible VSCode terminal tabs.
4
+
5
+ ## Release Process
6
+
7
+ When publishing a new version, follow these steps in order:
8
+
9
+ ### 1. Update version
10
+
11
+ ```bash
12
+ # In package.json, bump the version
13
+ # e.g., "version": "0.1.6" → "version": "0.1.7"
14
+ ```
15
+
16
+ ### 2. Update CHANGELOG.md
17
+
18
+ Add a new entry at the top with the new version and date:
19
+
20
+ ```markdown
21
+ ## [0.1.7] - YYYY-MM-DD
22
+
23
+ ### Added
24
+ - ...
25
+
26
+ ### Fixed
27
+ - ...
28
+ ```
29
+
30
+ ### 3. Update README.md
31
+
32
+ Replace the "Latest Changes" section with the new version's changes. Keep only the latest version in README — full history lives in CHANGELOG.md.
33
+
34
+ ### 4. Build and publish
35
+
36
+ ```bash
37
+ # Build
38
+ npm run build
39
+
40
+ # Publish to npm
41
+ npm publish --access public
42
+
43
+ # Package vsix
44
+ npx vsce package --allow-missing-repository
45
+
46
+ # Install locally for testing
47
+ cp dist/extension.js dist/mcp-entry.js ~/.vscode/extensions/hcdb.bashterm-mcp-<version>/dist/
48
+ ```
49
+
50
+ ### 5. Upload to VSCode Marketplace
51
+
52
+ 1. Go to https://marketplace.visualstudio.com/manage/publishers/hcdb
53
+ 2. Click "..." next to Terminal MCP → "Update"
54
+ 3. Upload the `.vsix` file
55
+
56
+ ### 6. Commit and push
57
+
58
+ ```bash
59
+ git add -A
60
+ git commit -m "v0.1.7: <summary of changes>"
61
+ git push
62
+ ```
63
+
64
+ ## Extension Cache Workaround
65
+
66
+ VSCode aggressively caches extensions. When developing locally:
67
+
68
+ ```bash
69
+ # Quick update (after modifying source)
70
+ npm run build
71
+ cp dist/extension.js ~/.vscode/extensions/hcdb.bashterm-mcp-<version>/dist/extension.js
72
+ # Then "Developer: Reload Window"
73
+
74
+ # If reload doesn't pick up changes, close and reopen VSCode completely
75
+ ```
76
+
77
+ ## Terminal Execution
78
+
79
+ Prefer the BashTerm MCP tools (`run`, `exec`, `read`, etc.) over the built-in Bash tool for executing commands. BashTerm runs commands in visible VSCode terminal tabs where the user can see output in real time.
80
+
81
+ For commands that may take longer than 30 seconds or produce large output, use pull mode:
82
+ 1. Call `run` with `waitForCompletion: false`
83
+ 2. Call `read` with `offset: -10` to check progress
84
+ 3. Repeat until done
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 sirlordt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,319 @@
1
+ # bashterm-mcp
2
+
3
+ [![中文文档](https://img.shields.io/badge/README-中文-red)](README.zh-CN.md) [![release](https://img.shields.io/badge/release-v0.1.7-green)](https://github.com/1170953489/bashterm-mcp/releases) [![npm](https://img.shields.io/badge/npm-bashterm--mcp-blue)](https://www.npmjs.com/package/bashterm-mcp) [![VSIX](https://img.shields.io/badge/vsix-v0.1.7-lightgrey)](https://github.com/1170953489/bashterm-mcp/releases)
4
+
5
+ MCP server that executes commands in **visible VSCode terminal tabs** with full output capture. Unlike inline execution, every command runs in a real terminal you can see, scroll, and interact with.
6
+
7
+ ## Key Features
8
+
9
+ - **Visible Terminals**: Commands run in real VSCode terminal tabs, not hidden processes. You see everything in real time.
10
+ - **Session Reuse**: The `run` tool automatically reuses idle sessions, creating new terminals only when needed.
11
+ - **Long-Running Support**: Fire-and-forget execution with `waitForCompletion: false`, then poll output incrementally with `read`.
12
+ - **Subagent Isolation**: Tag sessions with `agentId` to keep parallel agent workloads separated.
13
+
14
+ > **Windows Compatible** — This fork fully supports Windows, including Chinese output without garbled text.
15
+
16
+ ## Requirements
17
+
18
+ - VS Code 1.93+
19
+ - Node.js 20+
20
+
21
+ ## Getting Started
22
+
23
+ ### Claude Code
24
+
25
+ ```bash
26
+ claude mcp add BashTerm -- npx bashterm-mcp@latest
27
+ ```
28
+
29
+ ### VS Code / Copilot
30
+
31
+ Add to your `.vscode/mcp.json`:
32
+
33
+ ```json
34
+ {
35
+ "servers": {
36
+ "BashTerm": {
37
+ "type": "stdio",
38
+ "command": "npx",
39
+ "args": ["bashterm-mcp@latest"]
40
+ }
41
+ }
42
+ }
43
+ ```
44
+
45
+ <details>
46
+ <summary>Cursor</summary>
47
+
48
+ Add to your `.cursor/mcp.json`:
49
+
50
+ ```json
51
+ {
52
+ "mcpServers": {
53
+ "BashTerm": {
54
+ "command": "npx",
55
+ "args": ["-y", "bashterm-mcp@latest"]
56
+ }
57
+ }
58
+ }
59
+ ```
60
+
61
+ </details>
62
+
63
+ <details>
64
+ <summary>Claude Desktop</summary>
65
+
66
+ Add to your `claude_desktop_config.json`:
67
+
68
+ ```json
69
+ {
70
+ "mcpServers": {
71
+ "BashTerm": {
72
+ "command": "npx",
73
+ "args": ["-y", "bashterm-mcp@latest"]
74
+ }
75
+ }
76
+ }
77
+ ```
78
+
79
+ </details>
80
+
81
+ ### Your First Prompt
82
+
83
+ After installation, try asking:
84
+
85
+ > Run `ls -la` in the terminal
86
+
87
+ You should see a new terminal tab open in VSCode with the command output.
88
+
89
+ ## Screenshots
90
+
91
+ ### Running a command with `run`
92
+
93
+ ![Run command output](docs/images/run_finished.png)
94
+
95
+ ### Permission dialog for `exec`
96
+
97
+ ![Exec permission dialog](docs/images/ask_exec_permission.png)
98
+
99
+ ### Exec result with clean output
100
+
101
+ ![Exec finished](docs/images/exec_finished.png)
102
+
103
+ ## Tools
104
+
105
+ ### Quick Execution
106
+
107
+ | Tool | Description |
108
+ |------|-------------|
109
+ | `run` | Create (or reuse) a terminal and execute a command in one step. Returns clean output with exit code. |
110
+
111
+ ### Session Management
112
+
113
+ | Tool | Description |
114
+ |------|-------------|
115
+ | `create` | Create a new visible terminal session. Returns a `sessionId`. |
116
+ | `exec` | Execute a command in an existing session and capture output. |
117
+ | `read` | Read output from a session with pagination. Supports incremental reads and tail mode (`offset: -N`). |
118
+ | `input` | Send text to an interactive terminal (prompts, REPLs, confirmations). |
119
+ | `list` | List active sessions. Optionally filter by `agentId`. |
120
+ | `close` | Close a terminal session and its VSCode tab. |
121
+
122
+ ## Usage Patterns
123
+
124
+ ### Simple Command
125
+
126
+ The `run` tool handles everything — creates a terminal if needed, executes, and returns clean output:
127
+
128
+ ```
129
+ > Run npm test
130
+ ```
131
+
132
+ ```
133
+ $ npm test
134
+ PASS src/utils.test.ts (3 tests)
135
+ PASS src/index.test.ts (5 tests)
136
+
137
+ [exit: 0 | 1243ms | session-abc123]
138
+ ```
139
+
140
+ ### Long-Running Process
141
+
142
+ For builds, deployments, or any command that takes a while:
143
+
144
+ ```
145
+ > Start `npm run build` without waiting, then check progress
146
+ ```
147
+
148
+ The agent will:
149
+ 1. Call `run` with `waitForCompletion: false` — returns immediately
150
+ 2. Call `read` with `offset: -10` to check the last 10 lines
151
+ 3. Repeat until the process completes
152
+
153
+ ### Interactive Commands
154
+
155
+ For commands that need user input:
156
+
157
+ ```
158
+ > Run npm init and answer the prompts
159
+ ```
160
+
161
+ The agent will:
162
+ 1. Call `run` with `npm init`
163
+ 2. Call `read` to see the prompt
164
+ 3. Call `input` to send the answer
165
+
166
+ ### Parallel Agents
167
+
168
+ Subagents can work in isolated terminals using `agentId`:
169
+
170
+ ```
171
+ > Have one agent run tests while another runs the linter
172
+ ```
173
+
174
+ Each subagent gets its own terminal tagged with its `agentId`, preventing output from mixing.
175
+
176
+ ## Configuration
177
+
178
+ The extension reads configuration from VSCode settings under `terminalMcp.*`:
179
+
180
+ | Setting | Type | Default | Description |
181
+ |---------|------|---------|-------------|
182
+ | `terminalMcp.maxSessions` | number | 10 | Maximum concurrent terminal sessions |
183
+ | `terminalMcp.commandTimeout` | number | 30000 | Default command timeout in ms |
184
+ | `terminalMcp.maxOutputLines` | number | 5000 | Max lines kept in output buffer per session |
185
+ | `terminalMcp.idleTimeout` | number | 1800000 | Close idle sessions after this many ms (0 = disabled) |
186
+ | `terminalMcp.blockedCommands` | string[] | `["rm -rf /"]` | Commands that will be rejected |
187
+
188
+ ## Recommended: Set as Preferred Tool
189
+
190
+ LLM agents like Claude Code have a built-in `Bash` tool that executes commands inline within the chat. The output is embedded in the conversation and hard to read, especially for commands with verbose output. **We recommend telling the agent to prefer this MCP over its built-in Bash tool.**
191
+
192
+ Add the following to your project's `CLAUDE.md` (or equivalent instructions file):
193
+
194
+ ```markdown
195
+ ## Terminal Execution
196
+
197
+ Prefer the BashTerm MCP tools (`run`, `exec`, `read`, etc.) over the built-in Bash tool for executing commands.
198
+ BashTerm runs commands in visible VSCode terminal tabs where the user can see output in real time.
199
+ Only fall back to the built-in Bash tool for simple, non-interactive operations like reading environment variables.
200
+
201
+ For commands that may take longer than 30 seconds or produce large amounts of output (builds, test suites,
202
+ deployments, installs), use the pull mode pattern:
203
+ 1. Call `run` with `waitForCompletion: false` to launch the command without blocking.
204
+ 2. Call `read` with `offset: -10` to check the last 10 lines of output.
205
+ 3. Repeat step 2 until you see the command has finished (look for exit messages, prompts, or "Done").
206
+ 4. Report the final result to the user.
207
+
208
+ This prevents conversation timeouts and lets the user watch progress in the terminal in real time.
209
+ ```
210
+
211
+ **Why this matters:**
212
+
213
+ | | Built-in Bash | BashTerm MCP |
214
+ |---|---|---|
215
+ | Output visibility | Embedded in chat, hard to scroll | Visible in VSCode terminal tab |
216
+ | Real-time feedback | User sees nothing until command finishes | User watches output live |
217
+ | Long-running commands | Blocks the conversation until timeout | Fire-and-forget + polling |
218
+ | Session state | Each command is isolated | Persistent sessions with history |
219
+ | Interactive commands | Not supported | Send input to prompts/REPLs |
220
+
221
+ ## Development: Updating the Extension
222
+
223
+ VSCode aggressively caches extensions in memory. When developing locally, `code --install-extension` and even "Developer: Reload Window" may **not** reload your changes. Use this workflow:
224
+
225
+ ### Quick update (no restart needed)
226
+
227
+ After modifying source files, build and copy directly into the installed extension directory:
228
+
229
+ ```bash
230
+ cd /path/to/bashterm-mcp
231
+ npm run build
232
+ cp dist/extension.js ~/.vscode/extensions/hcdb.bashterm-mcp-<version>/dist/extension.js
233
+ ```
234
+
235
+ Then run **"Developer: Reload Window"** (`Ctrl+Shift+P`).
236
+
237
+ ### Full reinstall (when quick update doesn't work)
238
+
239
+ If VSCode still uses old code:
240
+
241
+ ```bash
242
+ # 1. Uninstall and remove all copies
243
+ code --uninstall-extension hcdb.bashterm-mcp
244
+ rm -rf ~/.vscode/extensions/hcdb.bashterm-mcp-*
245
+
246
+ # 2. Check for ghost entries with old publisher names
247
+ # Look in ~/.vscode/extensions/extensions.json for stale entries
248
+ # Remove any entries with old publisher IDs (e.g., "terminal-mcp.bashterm-mcp")
249
+
250
+ # 3. Close VSCode completely (not just reload)
251
+
252
+ # 4. Rebuild and install
253
+ npm run build
254
+ npx vsce package --allow-missing-repository
255
+ code --install-extension bashterm-mcp-<version>.vsix --force
256
+
257
+ # 5. Open VSCode
258
+ ```
259
+
260
+ ### Verify the correct version is loaded
261
+
262
+ ```bash
263
+ # Check which extension directories exist
264
+ ls ~/.vscode/extensions/ | grep terminal
265
+
266
+ # Verify your changes are in the installed extension
267
+ grep "YOUR_UNIQUE_STRING" ~/.vscode/extensions/hcdb.bashterm-mcp-*/dist/extension.js
268
+
269
+ # Compare checksums
270
+ md5sum dist/extension.js ~/.vscode/extensions/hcdb.bashterm-mcp-*/dist/extension.js
271
+ ```
272
+
273
+ ## Large Output Handling
274
+
275
+ When `read` returns output that exceeds the MCP client's token limit, the system automatically saves the full output to a temporary JSON file and returns the file path in the error message.
276
+
277
+ To extract the relevant content:
278
+
279
+ ```bash
280
+ # Get the last 50 lines (most relevant for status)
281
+ tail -50 /path/to/saved/file.txt
282
+
283
+ # Or parse the JSON to extract the text content
284
+ python3 -c "import json; data=json.load(open('/path/to/file.txt')); print(data[0]['text'][-2000:])"
285
+ ```
286
+
287
+ The file format is JSON: `[{"type": "text", "text": "..."}]`
288
+
289
+ This commonly happens with commands that produce heavy TUI output (progress bars, ANSI escape codes). Use smaller `offset` values (e.g., `offset: -20` instead of `offset: -100`) to reduce the captured output size.
290
+
291
+ ## How It Works
292
+
293
+ 1. The **VSCode extension** activates and starts an IPC server (Named Pipe on Windows, Unix socket on macOS/Linux)
294
+ 2. The **MCP entry point** (`mcp-entry.js`) is spawned by the MCP client and bridges JSON-RPC stdio with the IPC socket
295
+ 3. Commands execute via `child_process.exec()` for reliable cross-platform output capture and exit code detection
296
+ 4. Output is stored in circular buffers with pagination support for efficient reading
297
+
298
+ ## Latest Changes (0.1.7)
299
+
300
+ - **Full Windows support**: IPC uses Named Pipe instead of Unix socket (fixes `EACCES` error)
301
+ - **Chinese character encoding**: Automatic GBK decoding on Windows (no more garbled text)
302
+ - **Reliable command execution**: Uses `child_process.exec()` instead of Shell Integration API
303
+ - Added `README.zh-CN.md` (中文说明文档)
304
+
305
+ ### Previous (0.1.6)
306
+
307
+ - Screenshots in README for marketplace
308
+ - Clean output format for all tools — no more raw JSON
309
+ - Fixed `waitForCompletion: false` not working
310
+ - Disabled idle reaper — user closes sessions manually
311
+ - Unique IPC socket per workspace (multi-instance support)
312
+ - Custom terminal tab names with date format
313
+ - Large output handling documentation
314
+
315
+ See [CHANGELOG.md](CHANGELOG.md) for full history.
316
+
317
+ ## License
318
+
319
+ MIT