@mrclrchtr/supi-bash-timeout 0.1.0
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/index.ts +39 -0
- package/package.json +29 -0
package/index.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Bash Timeout — inject default timeouts on bash tool calls.
|
|
2
|
+
//
|
|
3
|
+
// The pi bash tool accepts an optional `timeout` parameter, but the LLM
|
|
4
|
+
// doesn't always specify one. In a headless gateway daemon with no human
|
|
5
|
+
// watching, a single hung command (e.g. `find /` over a huge filesystem)
|
|
6
|
+
// blocks all subsequent messages indefinitely.
|
|
7
|
+
//
|
|
8
|
+
// This extension intercepts every bash `tool_call` event and sets a default
|
|
9
|
+
// timeout when the LLM omits one. The timeout is configurable via the
|
|
10
|
+
// PI_BASH_DEFAULT_TIMEOUT env var (seconds, default 120).
|
|
11
|
+
//
|
|
12
|
+
// ADR-0049: Gateway TUI via WebSocket
|
|
13
|
+
|
|
14
|
+
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
15
|
+
|
|
16
|
+
const DEFAULT_TIMEOUT_SECONDS = 120;
|
|
17
|
+
|
|
18
|
+
function getDefaultTimeout(): number {
|
|
19
|
+
const env = process.env.PI_BASH_DEFAULT_TIMEOUT;
|
|
20
|
+
if (env) {
|
|
21
|
+
const parsed = parseInt(env, 10);
|
|
22
|
+
if (Number.isFinite(parsed) && parsed > 0) return parsed;
|
|
23
|
+
}
|
|
24
|
+
return DEFAULT_TIMEOUT_SECONDS;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default function bashTimeout(pi: ExtensionAPI) {
|
|
28
|
+
pi.on("tool_call", async (event) => {
|
|
29
|
+
if (event.toolName !== "bash") return;
|
|
30
|
+
|
|
31
|
+
const input = event.input as { command?: string; timeout?: number };
|
|
32
|
+
|
|
33
|
+
// Only inject when the LLM didn't specify a timeout
|
|
34
|
+
if (input.timeout !== undefined && input.timeout !== null) return;
|
|
35
|
+
|
|
36
|
+
const defaultTimeout = getDefaultTimeout();
|
|
37
|
+
input.timeout = defaultTimeout;
|
|
38
|
+
});
|
|
39
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mrclrchtr/supi-bash-timeout",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "SuPi bash-timeout extension — injects default timeout on bash tool calls",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/mrclrchtr/supi.git"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"pi-package",
|
|
15
|
+
"pi",
|
|
16
|
+
"pi-coding-agent"
|
|
17
|
+
],
|
|
18
|
+
"files": [
|
|
19
|
+
"index.ts"
|
|
20
|
+
],
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@mariozechner/pi-coding-agent": "~0.66.0"
|
|
23
|
+
},
|
|
24
|
+
"pi": {
|
|
25
|
+
"extensions": [
|
|
26
|
+
"./index.ts"
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
}
|