just-bash 1.5.4 → 2.0.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/README.md +10 -8
- package/dist/AGENTS.md +17 -82
- package/dist/browser.d.ts +22 -0
- package/dist/bundle/{ai/index.js → browser.js} +306 -311
- package/package.json +8 -22
- package/dist/ai/index.d.ts +0 -66
package/README.md
CHANGED
|
@@ -135,10 +135,14 @@ await env.exec('echo "hello" > file.txt'); // writes to real filesystem
|
|
|
135
135
|
|
|
136
136
|
### AI SDK Tool
|
|
137
137
|
|
|
138
|
-
|
|
138
|
+
For AI agents, use [`bash-tool`](https://github.com/vercel-labs/bash-tool) which is optimized for just-bash and provides a ready-to-use [AI SDK](https://ai-sdk.dev/) tool:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
npm install bash-tool
|
|
142
|
+
```
|
|
139
143
|
|
|
140
144
|
```typescript
|
|
141
|
-
import { createBashTool } from "
|
|
145
|
+
import { createBashTool } from "bash-tool";
|
|
142
146
|
import { generateText } from "ai";
|
|
143
147
|
|
|
144
148
|
const bashTool = createBashTool({
|
|
@@ -146,13 +150,13 @@ const bashTool = createBashTool({
|
|
|
146
150
|
});
|
|
147
151
|
|
|
148
152
|
const result = await generateText({
|
|
149
|
-
model: "anthropic/claude-
|
|
153
|
+
model: "anthropic/claude-sonnet-4",
|
|
150
154
|
tools: { bash: bashTool },
|
|
151
155
|
prompt: "Count the users in /data/users.json",
|
|
152
156
|
});
|
|
153
157
|
```
|
|
154
158
|
|
|
155
|
-
See [
|
|
159
|
+
See the [bash-tool documentation](https://github.com/vercel-labs/bash-tool) for more details and examples.
|
|
156
160
|
|
|
157
161
|
### Vercel Sandbox Compatible API
|
|
158
162
|
|
|
@@ -367,14 +371,12 @@ pnpm shell # Run interactive shell
|
|
|
367
371
|
|
|
368
372
|
## AI Agent Instructions
|
|
369
373
|
|
|
370
|
-
For AI agents
|
|
374
|
+
For AI agents, we recommend using [`bash-tool`](https://github.com/vercel-labs/bash-tool) which is optimized for just-bash and provides additional guidance in its `AGENTS.md`:
|
|
371
375
|
|
|
372
376
|
```bash
|
|
373
|
-
cat node_modules/
|
|
377
|
+
cat node_modules/bash-tool/dist/AGENTS.md
|
|
374
378
|
```
|
|
375
379
|
|
|
376
|
-
This file contains quick reference patterns, common pitfalls, and debugging tips specifically for AI agents.
|
|
377
|
-
|
|
378
380
|
## License
|
|
379
381
|
|
|
380
382
|
Apache-2.0
|
package/dist/AGENTS.md
CHANGED
|
@@ -8,111 +8,50 @@ Instructions for AI agents using just-bash in projects.
|
|
|
8
8
|
A sandboxed bash interpreter with an in-memory virtual filesystem. Use it when you need to:
|
|
9
9
|
|
|
10
10
|
- Execute shell commands without real filesystem access
|
|
11
|
-
- Provide a bash tool for AI agents
|
|
12
11
|
- Run untrusted scripts safely
|
|
13
12
|
- Process text with standard Unix tools (grep, sed, awk, jq, etc.)
|
|
14
13
|
|
|
15
|
-
##
|
|
16
|
-
|
|
17
|
-
```typescript
|
|
18
|
-
import { Bash } from "just-bash";
|
|
14
|
+
## For AI Agents
|
|
19
15
|
|
|
20
|
-
|
|
21
|
-
files: { "/data/input.txt": "content" }, // Initial files
|
|
22
|
-
cwd: "/data", // Working directory
|
|
23
|
-
});
|
|
16
|
+
If you're building an AI agent that needs a bash tool, use [`bash-tool`](https://github.com/vercel-labs/bash-tool) which is optimized for just-bash:
|
|
24
17
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// result.stderr - error output
|
|
28
|
-
// result.exitCode - 0 = success, non-zero = failure
|
|
18
|
+
```sh
|
|
19
|
+
npm install bash-tool
|
|
29
20
|
```
|
|
30
21
|
|
|
31
|
-
## Building an AI Agent
|
|
32
|
-
|
|
33
|
-
just-bash integrates with the [AI SDK](https://ai-sdk.dev/) to provide a bash tool for AI agents.
|
|
34
|
-
|
|
35
|
-
### Basic Agent Setup
|
|
36
|
-
|
|
37
22
|
```typescript
|
|
38
|
-
import { createBashTool } from "
|
|
23
|
+
import { createBashTool } from "bash-tool";
|
|
39
24
|
import { generateText } from "ai";
|
|
40
25
|
|
|
41
26
|
const bashTool = createBashTool({
|
|
42
|
-
files: {
|
|
43
|
-
"/data/users.json": '[{"name": "Alice"}, {"name": "Bob"}]',
|
|
44
|
-
"/data/config.yaml": "debug: true\nport: 3000",
|
|
45
|
-
},
|
|
27
|
+
files: { "/data/users.json": '[{"name": "Alice"}, {"name": "Bob"}]' },
|
|
46
28
|
});
|
|
47
29
|
|
|
48
30
|
const result = await generateText({
|
|
49
|
-
model: "anthropic/claude-
|
|
31
|
+
model: "anthropic/claude-sonnet-4",
|
|
50
32
|
tools: { bash: bashTool },
|
|
51
33
|
prompt: "Count the users in /data/users.json",
|
|
52
34
|
});
|
|
53
35
|
```
|
|
54
36
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
For multi-step tasks, use `ToolLoopAgent` which automatically loops until completion:
|
|
58
|
-
|
|
59
|
-
```typescript
|
|
60
|
-
import { ToolLoopAgent } from "ai";
|
|
61
|
-
import { createBashTool } from "just-bash/ai";
|
|
62
|
-
|
|
63
|
-
const bashTool = createBashTool({
|
|
64
|
-
files: {
|
|
65
|
-
"/project/src/index.ts": "export const version = '1.0.0';",
|
|
66
|
-
"/project/src/utils.ts": "// TODO: implement\nexport function helper() {}",
|
|
67
|
-
"/project/package.json": '{"name": "my-app", "version": "1.0.0"}',
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
const agent = new ToolLoopAgent({
|
|
72
|
-
model: "anthropic/claude-haiku-4.5",
|
|
73
|
-
tools: { bash: bashTool },
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
const result = await agent.generate({
|
|
77
|
-
prompt: "Find all TODO comments in the project and list the files containing them",
|
|
78
|
-
});
|
|
79
|
-
```
|
|
37
|
+
See the [bash-tool documentation](https://github.com/vercel-labs/bash-tool) for more details.
|
|
80
38
|
|
|
81
|
-
|
|
39
|
+
## Quick Reference
|
|
82
40
|
|
|
83
41
|
```typescript
|
|
84
|
-
import {
|
|
42
|
+
import { Bash } from "just-bash";
|
|
85
43
|
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
},
|
|
44
|
+
const bash = new Bash({
|
|
45
|
+
files: { "/data/input.txt": "content" }, // Initial files
|
|
46
|
+
cwd: "/data", // Working directory
|
|
90
47
|
});
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
### With Real Filesystem (Read-Only)
|
|
94
48
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const overlay = new OverlayFs({ root: "/path/to/project" });
|
|
100
|
-
const bashTool = createBashTool({
|
|
101
|
-
fs: overlay,
|
|
102
|
-
cwd: overlay.getMountPoint(),
|
|
103
|
-
});
|
|
49
|
+
const result = await bash.exec("cat input.txt | grep pattern");
|
|
50
|
+
// result.stdout - command output
|
|
51
|
+
// result.stderr - error output
|
|
52
|
+
// result.exitCode - 0 = success, non-zero = failure
|
|
104
53
|
```
|
|
105
54
|
|
|
106
|
-
### Tool Options
|
|
107
|
-
|
|
108
|
-
- `files` - Initial virtual files
|
|
109
|
-
- `fs` - Custom filesystem (e.g., OverlayFs)
|
|
110
|
-
- `network` - URL allowlist for curl
|
|
111
|
-
- `commands` - Restrict available commands
|
|
112
|
-
- `customCommands` - Add custom commands
|
|
113
|
-
- `onCall` - Callback before each execution
|
|
114
|
-
- `logger` - Execution tracing
|
|
115
|
-
|
|
116
55
|
## Key Behaviors
|
|
117
56
|
|
|
118
57
|
1. **Isolation**: Each `exec()` call is isolated. Environment variables, functions, and cwd changes don't persist between calls. Only filesystem changes persist.
|
|
@@ -215,9 +154,6 @@ cat node_modules/just-bash/dist/index.d.ts
|
|
|
215
154
|
# View Bash class options
|
|
216
155
|
grep -A 30 "interface BashOptions" node_modules/just-bash/dist/Bash.d.ts
|
|
217
156
|
|
|
218
|
-
# View AI tool options
|
|
219
|
-
cat node_modules/just-bash/dist/ai/index.d.ts
|
|
220
|
-
|
|
221
157
|
# Search for specific types
|
|
222
158
|
grep -r "interface.*Options" node_modules/just-bash/dist/*.d.ts
|
|
223
159
|
```
|
|
@@ -225,5 +161,4 @@ grep -r "interface.*Options" node_modules/just-bash/dist/*.d.ts
|
|
|
225
161
|
Key types to explore:
|
|
226
162
|
- `BashOptions` - Constructor options for `new Bash()`
|
|
227
163
|
- `ExecResult` - Return type of `bash.exec()`
|
|
228
|
-
- `CreateBashToolOptions` - Options for `createBashTool()`
|
|
229
164
|
- `InitialFiles` - File specification format
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-compatible entry point for just-bash.
|
|
3
|
+
*
|
|
4
|
+
* Excludes Node.js-specific modules:
|
|
5
|
+
* - OverlayFs (requires node:fs)
|
|
6
|
+
* - ReadWriteFs (requires node:fs)
|
|
7
|
+
* - Sandbox (uses OverlayFs)
|
|
8
|
+
*
|
|
9
|
+
* Note: The gzip/gunzip/zcat commands will fail at runtime in browsers
|
|
10
|
+
* since they use node:zlib. All other commands work.
|
|
11
|
+
*/
|
|
12
|
+
export type { BashLogger, BashOptions, ExecOptions } from "./Bash.js";
|
|
13
|
+
export { Bash } from "./Bash.js";
|
|
14
|
+
export type { AllCommandName, CommandName, NetworkCommandName, } from "./commands/registry.js";
|
|
15
|
+
export { getCommandNames, getNetworkCommandNames, } from "./commands/registry.js";
|
|
16
|
+
export type { CustomCommand, LazyCommand } from "./custom-commands.js";
|
|
17
|
+
export { defineCommand } from "./custom-commands.js";
|
|
18
|
+
export { InMemoryFs } from "./fs/in-memory-fs/index.js";
|
|
19
|
+
export type { BufferEncoding, CpOptions, DirectoryEntry, FileContent, FileEntry, FileInit, FileSystemFactory, FsEntry, FsStat, InitialFiles, MkdirOptions, RmOptions, SymlinkEntry, } from "./fs/interface.js";
|
|
20
|
+
export type { NetworkConfig } from "./network/index.js";
|
|
21
|
+
export { NetworkAccessDeniedError, RedirectNotAllowedError, TooManyRedirectsError, } from "./network/index.js";
|
|
22
|
+
export type { BashExecResult, Command, CommandContext, ExecResult, IFileSystem, } from "./types.js";
|