just-bash 1.5.2 → 1.5.4
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 -0
- package/dist/AGENTS.md +229 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -365,6 +365,16 @@ pnpm build # Build TypeScript
|
|
|
365
365
|
pnpm shell # Run interactive shell
|
|
366
366
|
```
|
|
367
367
|
|
|
368
|
+
## AI Agent Instructions
|
|
369
|
+
|
|
370
|
+
For AI agents working with just-bash, additional guidance is available in `AGENTS.md`:
|
|
371
|
+
|
|
372
|
+
```bash
|
|
373
|
+
cat node_modules/just-bash/dist/AGENTS.md
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
This file contains quick reference patterns, common pitfalls, and debugging tips specifically for AI agents.
|
|
377
|
+
|
|
368
378
|
## License
|
|
369
379
|
|
|
370
380
|
Apache-2.0
|
package/dist/AGENTS.md
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
|
|
2
|
+
# AGENTS.md - just-bash
|
|
3
|
+
|
|
4
|
+
Instructions for AI agents using just-bash in projects.
|
|
5
|
+
|
|
6
|
+
## What is just-bash?
|
|
7
|
+
|
|
8
|
+
A sandboxed bash interpreter with an in-memory virtual filesystem. Use it when you need to:
|
|
9
|
+
|
|
10
|
+
- Execute shell commands without real filesystem access
|
|
11
|
+
- Provide a bash tool for AI agents
|
|
12
|
+
- Run untrusted scripts safely
|
|
13
|
+
- Process text with standard Unix tools (grep, sed, awk, jq, etc.)
|
|
14
|
+
|
|
15
|
+
## Quick Reference
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { Bash } from "just-bash";
|
|
19
|
+
|
|
20
|
+
const bash = new Bash({
|
|
21
|
+
files: { "/data/input.txt": "content" }, // Initial files
|
|
22
|
+
cwd: "/data", // Working directory
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const result = await bash.exec("cat input.txt | grep pattern");
|
|
26
|
+
// result.stdout - command output
|
|
27
|
+
// result.stderr - error output
|
|
28
|
+
// result.exitCode - 0 = success, non-zero = failure
|
|
29
|
+
```
|
|
30
|
+
|
|
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
|
+
```typescript
|
|
38
|
+
import { createBashTool } from "just-bash/ai";
|
|
39
|
+
import { generateText } from "ai";
|
|
40
|
+
|
|
41
|
+
const bashTool = createBashTool({
|
|
42
|
+
files: {
|
|
43
|
+
"/data/users.json": '[{"name": "Alice"}, {"name": "Bob"}]',
|
|
44
|
+
"/data/config.yaml": "debug: true\nport: 3000",
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const result = await generateText({
|
|
49
|
+
model: "anthropic/claude-haiku-4.5",
|
|
50
|
+
tools: { bash: bashTool },
|
|
51
|
+
prompt: "Count the users in /data/users.json",
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### With ToolLoopAgent
|
|
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
|
+
```
|
|
80
|
+
|
|
81
|
+
### With Network Access
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
import { createBashTool } from "just-bash/ai";
|
|
85
|
+
|
|
86
|
+
const bashTool = createBashTool({
|
|
87
|
+
network: {
|
|
88
|
+
allowedUrlPrefixes: ["https://api.github.com/"],
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### With Real Filesystem (Read-Only)
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import { createBashTool } from "just-bash/ai";
|
|
97
|
+
import { OverlayFs } from "just-bash/fs/overlay-fs";
|
|
98
|
+
|
|
99
|
+
const overlay = new OverlayFs({ root: "/path/to/project" });
|
|
100
|
+
const bashTool = createBashTool({
|
|
101
|
+
fs: overlay,
|
|
102
|
+
cwd: overlay.getMountPoint(),
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
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
|
+
## Key Behaviors
|
|
117
|
+
|
|
118
|
+
1. **Isolation**: Each `exec()` call is isolated. Environment variables, functions, and cwd changes don't persist between calls. Only filesystem changes persist.
|
|
119
|
+
|
|
120
|
+
2. **No real filesystem**: By default, commands only see the virtual filesystem. Use `OverlayFs` to read from a real directory (writes stay in memory).
|
|
121
|
+
|
|
122
|
+
3. **No network by default**: `curl` doesn't exist unless you configure `network` options with URL allowlists.
|
|
123
|
+
|
|
124
|
+
4. **No binaries/WASM**: Only built-in commands work. You cannot run node, python, or other binaries.
|
|
125
|
+
|
|
126
|
+
## Available Commands
|
|
127
|
+
|
|
128
|
+
**Text processing**: `awk`, `cat`, `cut`, `grep`, `head`, `jq`, `sed`, `sort`, `tail`, `tr`, `uniq`, `wc`, `xargs`
|
|
129
|
+
|
|
130
|
+
**File operations**: `cp`, `find`, `ls`, `mkdir`, `mv`, `rm`, `touch`, `tree`
|
|
131
|
+
|
|
132
|
+
**Utilities**: `base64`, `date`, `diff`, `echo`, `env`, `printf`, `seq`, `tee`
|
|
133
|
+
|
|
134
|
+
All commands support `--help` for usage details.
|
|
135
|
+
|
|
136
|
+
## Common Patterns
|
|
137
|
+
|
|
138
|
+
### Process JSON with jq
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
cat data.json | jq '.items[] | select(.active) | .name'
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Find and process files
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
find . -name "*.ts" -type f | xargs grep -l "TODO"
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Text transformation pipeline
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
cat input.txt | grep -v "^#" | sort | uniq -c | sort -rn | head -10
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### AWK for columnar data
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
cat data.csv | awk -F',' '{sum += $3} END {print sum}'
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Limitations
|
|
163
|
+
|
|
164
|
+
- **32-bit integers only**: Arithmetic operations use 32-bit signed integers
|
|
165
|
+
- **No job control**: No `&`, `bg`, `fg`, or process suspension
|
|
166
|
+
- **No external binaries**: Only built-in commands are available
|
|
167
|
+
- **Execution limits**: Loops, recursion, and command counts have configurable limits to prevent runaway execution
|
|
168
|
+
|
|
169
|
+
## Error Handling
|
|
170
|
+
|
|
171
|
+
Always check `exitCode`:
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
import { Bash } from "just-bash";
|
|
175
|
+
|
|
176
|
+
const bash = new Bash({ files: { "/file.txt": "some content" } });
|
|
177
|
+
const result = await bash.exec("grep pattern file.txt");
|
|
178
|
+
if (result.exitCode !== 0) {
|
|
179
|
+
// Command failed - check result.stderr for details
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Common exit codes:
|
|
184
|
+
|
|
185
|
+
- `0` - Success
|
|
186
|
+
- `1` - General error or no matches (grep)
|
|
187
|
+
- `2` - Misuse of command (invalid options)
|
|
188
|
+
- `127` - Command not found
|
|
189
|
+
|
|
190
|
+
## Debugging Tips
|
|
191
|
+
|
|
192
|
+
1. **Check stderr**: Error messages go to `result.stderr`
|
|
193
|
+
2. **Use --help**: All commands support `--help` for usage
|
|
194
|
+
3. **Test incrementally**: Build pipelines step by step
|
|
195
|
+
4. **Quote variables**: Use `"$var"` to handle spaces in values
|
|
196
|
+
|
|
197
|
+
## Security Model
|
|
198
|
+
|
|
199
|
+
- Virtual filesystem is isolated from the real system
|
|
200
|
+
- Network access requires explicit URL allowlists
|
|
201
|
+
- Execution limits prevent infinite loops
|
|
202
|
+
- No shell injection possible (commands are parsed, not eval'd)
|
|
203
|
+
|
|
204
|
+
## Discovering Types
|
|
205
|
+
|
|
206
|
+
TypeScript types are available in the `.d.ts` files. Use JSDoc-style exploration to understand the API:
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
# Find all type definition files
|
|
210
|
+
find node_modules/just-bash/dist -name "*.d.ts" | head -20
|
|
211
|
+
|
|
212
|
+
# View main exports and their types
|
|
213
|
+
cat node_modules/just-bash/dist/index.d.ts
|
|
214
|
+
|
|
215
|
+
# View Bash class options
|
|
216
|
+
grep -A 30 "interface BashOptions" node_modules/just-bash/dist/Bash.d.ts
|
|
217
|
+
|
|
218
|
+
# View AI tool options
|
|
219
|
+
cat node_modules/just-bash/dist/ai/index.d.ts
|
|
220
|
+
|
|
221
|
+
# Search for specific types
|
|
222
|
+
grep -r "interface.*Options" node_modules/just-bash/dist/*.d.ts
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Key types to explore:
|
|
226
|
+
- `BashOptions` - Constructor options for `new Bash()`
|
|
227
|
+
- `ExecResult` - Return type of `bash.exec()`
|
|
228
|
+
- `CreateBashToolOptions` - Options for `createBashTool()`
|
|
229
|
+
- `InitialFiles` - File specification format
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "just-bash",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.4",
|
|
4
4
|
"description": "A simulated bash environment with virtual filesystem",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -49,7 +49,8 @@
|
|
|
49
49
|
"dist/parser/*.d.ts",
|
|
50
50
|
"dist/sandbox/*.d.ts",
|
|
51
51
|
"dist/utils/*.d.ts",
|
|
52
|
-
"README.md"
|
|
52
|
+
"README.md",
|
|
53
|
+
"dist/AGENTS.md"
|
|
53
54
|
],
|
|
54
55
|
"bin": {
|
|
55
56
|
"just-bash": "./dist/bin/just-bash.js",
|
|
@@ -82,7 +83,7 @@
|
|
|
82
83
|
},
|
|
83
84
|
"packageManager": "pnpm@8.15.9+sha512.499434c9d8fdd1a2794ebf4552b3b25c0a633abcee5bb15e7b5de90f32f47b513aca98cd5cfd001c31f0db454bc3804edccd578501e4ca293a6816166bbd9f81",
|
|
84
85
|
"scripts": {
|
|
85
|
-
"build": "rm -rf dist && tsc && pnpm build:lib && pnpm build:ai && pnpm build:cli && pnpm build:shell && pnpm build:clean",
|
|
86
|
+
"build": "rm -rf dist && tsc && pnpm build:lib && pnpm build:ai && pnpm build:cli && pnpm build:shell && pnpm build:clean && sed '1,/^-->/d' AGENTS.npm.md > dist/AGENTS.md",
|
|
86
87
|
"build:clean": "find dist -name '*.test.js' -delete && find dist -name '*.test.d.ts' -delete",
|
|
87
88
|
"build:lib": "esbuild dist/index.js --bundle --splitting --platform=node --format=esm --minify --outdir=dist/bundle --chunk-names=chunks/[name]-[hash] --external:diff --external:minimatch --external:sprintf-js --external:turndown",
|
|
88
89
|
"build:ai": "esbuild dist/ai/index.js --bundle --platform=node --format=esm --minify --outfile=dist/bundle/ai/index.js --external:ai --external:zod --external:diff --external:minimatch --external:sprintf-js --external:turndown",
|