bash-tool 0.1.0 → 0.1.1

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.
Files changed (3) hide show
  1. package/README.md +26 -0
  2. package/dist/AGENTS.md +144 -0
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -64,6 +64,24 @@ const { tools } = await createBashTool({
64
64
  });
65
65
  ```
66
66
 
67
+ ### Persistent sandbox across serverless invocations
68
+
69
+ Use `Sandbox.get` to reconnect to an existing sandbox by ID:
70
+
71
+ ```typescript
72
+ import { Sandbox } from "@vercel/sandbox";
73
+
74
+ // First invocation: create sandbox and store the ID
75
+ const sandbox = await Sandbox.create();
76
+ const sandboxId = sandbox.sandboxId;
77
+ // Store sandboxId in database, session, or return to client
78
+
79
+ // Subsequent invocations: reconnect to existing sandbox
80
+ const sandbox = await Sandbox.get({ sandboxId });
81
+ const { tools } = await createBashTool({ sandbox });
82
+ // All previous files and state are preserved
83
+ ```
84
+
67
85
  ### Use a custom just-bash instance
68
86
 
69
87
  ```typescript
@@ -107,6 +125,14 @@ const customSandbox: Sandbox = {
107
125
  const { tools } = await createBashTool({ sandbox: customSandbox });
108
126
  ```
109
127
 
128
+ ## AI Agent Instructions
129
+
130
+ For AI agents working with bash-tool, additional guidance is available in `AGENTS.md`:
131
+
132
+ ```bash
133
+ cat node_modules/bash-tool/dist/AGENTS.md
134
+ ```
135
+
110
136
  ## License
111
137
 
112
138
  MIT
package/dist/AGENTS.md ADDED
@@ -0,0 +1,144 @@
1
+
2
+ # AGENTS.md - bash-tool
3
+
4
+ Instructions for AI agents using bash-tool in projects.
5
+
6
+ ## What is bash-tool?
7
+
8
+ - Provides `bash`, `readFile`, `writeFile` tools for AI SDK agents
9
+ - Runs commands in sandboxed environments (just-bash or @vercel/sandbox)
10
+ - Pre-populates sandbox with files from inline content or disk
11
+ - Generates contextual LLM instructions with working directory and file list
12
+
13
+ ## Quick Reference
14
+
15
+ ```typescript
16
+ import { createBashTool } from "bash-tool";
17
+ import { generateText } from "ai";
18
+
19
+ const { bash, tools, sandbox } = await createBashTool({
20
+ files: {
21
+ "src/index.ts": "export const x = 1;",
22
+ "package.json": '{"name": "test"}',
23
+ },
24
+ });
25
+
26
+ const result = await generateText({
27
+ model,
28
+ tools: { bash }, // or use `tools` for all three
29
+ prompt: "List files in src/",
30
+ });
31
+ ```
32
+
33
+ ## Key Behaviors
34
+
35
+ 1. **Default sandbox is just-bash** - Install `just-bash` or provide your own sandbox
36
+ 2. **Working directory defaults to `/workspace`** - All files written relative to `destination`
37
+ 3. **Files are written before tools are returned** - Sandbox is pre-populated
38
+ 4. **Tool descriptions include file list** - LLM sees available files in bash tool description
39
+ 5. **No `stop()` method** - Sandbox lifecycle is managed externally
40
+
41
+ ## Common Patterns
42
+
43
+ ### Upload local directory
44
+
45
+ ```typescript
46
+ const { bash } = await createBashTool({
47
+ uploadDirectory: { source: "./my-project", include: "**/*.ts" },
48
+ });
49
+ ```
50
+
51
+ ### Use [@vercel/sandbox](https://vercel.com/docs/vercel-sandbox) for full VM
52
+
53
+ ```typescript
54
+ import { Sandbox } from "@vercel/sandbox";
55
+ const vm = await Sandbox.create();
56
+ const { tools } = await createBashTool({ sandbox: vm });
57
+ // Call vm.stop() when done
58
+ ```
59
+
60
+ ### Persistent sandbox across serverless invocations
61
+
62
+ ```typescript
63
+ import { Sandbox } from "@vercel/sandbox";
64
+
65
+ // First invocation: create and store sandboxId
66
+ const sandbox = await Sandbox.create();
67
+ const sandboxId = sandbox.sandboxId; // store this
68
+
69
+ // Later invocations: reconnect by ID
70
+ const sandbox = await Sandbox.get({ sandboxId });
71
+ const { tools } = await createBashTool({ sandbox });
72
+ // Previous files and state preserved
73
+ ```
74
+
75
+ ### Track tool invocations
76
+
77
+ ```typescript
78
+ const { tools } = await createBashTool({
79
+ onCall: (toolName, args) => console.log(toolName, args),
80
+ });
81
+ ```
82
+
83
+ ### Custom destination
84
+
85
+ ```typescript
86
+ const { bash } = await createBashTool({
87
+ destination: "/home/user/app",
88
+ files: { "main.ts": "console.log('hi');" },
89
+ });
90
+ // Files at /home/user/app/main.ts, cwd is /home/user/app
91
+ ```
92
+
93
+ ## Limitations
94
+
95
+ - **just-bash is simulated** - Cannot support python, node.js or binaries; use @vercel/sandbox for a full VM. So, createBashTool supports full VMs, it is just the default that does not
96
+ - **No persistent state between calls** - Each `createBashTool` starts fresh, but the tool itself has persistence and it can be achieved across serverless function invocations by passing in the same sandbox across `createBashTool` invocations
97
+ - **Text files only** - `files` option accepts strings, not buffers
98
+ - **No streaming** - Command output returned after completion
99
+
100
+ ## Error Handling
101
+
102
+ ```typescript
103
+ const result = await tools.bash.execute({ command: "ls /nonexistent" }, opts);
104
+ if (result.exitCode !== 0) {
105
+ console.error("Command failed:", result.stderr);
106
+ }
107
+
108
+ // readFile throws on missing files
109
+ try {
110
+ await sandbox.readFile("/missing.txt");
111
+ } catch (e) {
112
+ // "File not found: /missing.txt" or "Failed to read file: ..."
113
+ }
114
+ ```
115
+
116
+ ## Debugging Tips
117
+
118
+ 1. **Check sandbox type** - `isVercelSandbox()` and `isJustBash()` exported for detection
119
+ 2. **Inspect tool description** - `bash.description` shows working dir and file list
120
+ 3. **Use `pwd` first** - Verify working directory matches expectations
121
+ 4. **Check `exitCode`** - Non-zero means command failed, check `stderr`
122
+ 5. **Missing just-bash error** - Install it or provide custom sandbox
123
+
124
+ ## Discovering Types
125
+
126
+ TypeScript types are available in the `.d.ts` files:
127
+
128
+ ```bash
129
+ # View main exports
130
+ cat node_modules/bash-tool/dist/index.d.ts
131
+
132
+ # View all options and types
133
+ cat node_modules/bash-tool/dist/types.d.ts
134
+
135
+ # Search for interfaces
136
+ grep -r "^export interface" node_modules/bash-tool/dist/*.d.ts
137
+ ```
138
+
139
+ Key types to explore:
140
+
141
+ - `CreateBashToolOptions` - Options for createBashTool()
142
+ - `BashToolkit` - Return type with bash, tools, sandbox
143
+ - `Sandbox` - Interface for custom sandbox implementations
144
+ - `CommandResult` - Shape of executeCommand results
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.1.0",
6
+ "version": "0.1.1",
7
7
  "description": "Generic bash tool for AI agents, compatible with AI SDK",
8
8
  "type": "module",
9
9
  "main": "dist/index.js",
@@ -69,7 +69,7 @@
69
69
  }
70
70
  },
71
71
  "scripts": {
72
- "build": "tsc -p tsconfig.build.json",
72
+ "build": "tsc -p tsconfig.build.json && sed '1,/^-->/d' AGENTS.npm.md > dist/AGENTS.md",
73
73
  "typecheck": "tsc --noEmit",
74
74
  "test": "vitest",
75
75
  "test:run": "vitest run",
@@ -77,6 +77,6 @@
77
77
  "lint:fix": "biome check --write .",
78
78
  "format": "biome format --write .",
79
79
  "knip": "knip",
80
- "validate": "pnpm run lint && pnpm run knip && pnpm run typecheck && pnpm run test"
80
+ "validate": "pnpm run lint && pnpm run knip && pnpm run typecheck && pnpm run test:run"
81
81
  }
82
82
  }