Skip to content

Commit e8858f8

Browse files
authored
Refactor 26 (#5)
* claude * refactor * refactor * refactor-ifs * lint * knip * build-before
1 parent 19bf0e8 commit e8858f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1836
-2069
lines changed

.github/workflows/lint.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ jobs:
2525

2626
- name: Lint
2727
run: pnpm lint
28+
29+
- name: Knip
30+
run: pnpm knip

.github/workflows/unit-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@ jobs:
2323
- name: Install dependencies
2424
run: pnpm install --frozen-lockfile
2525

26+
- name: Build
27+
run: pnpm build
28+
2629
- name: Run unit tests
2730
run: pnpm test:unit

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Commands must handle unknown arguments correctly
1111
- Always ensure all tests pass in the end and there are no compile and lint errors
1212
- Use `pnpm lint:fix`
13+
- Always also run `pnpm knip`
1314
- Strongly prefer running a temporary comparison test or unit test over an ad-hoc script to figure out the behavior of some bash script or API.
1415
- The implementation should align with the real behavior of bash, not what is convenient for TS or TE tests.
1516
- Always make sure to build before using dist

CLAUDE.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,41 @@ pnpm test:run src/spec-tests/spec.test.ts -t "array-basic.test.sh"
3232
# Interactive shell
3333
pnpm shell # Full network access
3434
pnpm shell --no-network # No network
35+
36+
# Sandboxed CLI (read-only by default)
37+
node ./dist/cli/bash-env.js -c 'ls -la' --root .
38+
node ./dist/cli/bash-env.js -c 'cat package.json' --root .
39+
node ./dist/cli/bash-env.js -c 'grep -r "TODO" src/' --root .
3540
```
3641

42+
### Sandboxed Shell Execution with `bash-env`
43+
44+
The `bash-env` CLI provides a secure, sandboxed bash environment using OverlayFS:
45+
46+
```bash
47+
# Execute inline script (read-only by default)
48+
node ./dist/cli/bash-env.js -c 'ls -la && cat README.md | head -5' --root .
49+
50+
# Execute with JSON output
51+
node ./dist/cli/bash-env.js -c 'echo hello' --root . --json
52+
53+
# Allow writes (writes stay in memory, don't affect real filesystem)
54+
node ./dist/cli/bash-env.js -c 'echo test > /tmp/file.txt && cat /tmp/file.txt' --root . --allow-write
55+
56+
# Execute script file
57+
node ./dist/cli/bash-env.js script.sh --root .
58+
59+
# Exit on first error
60+
node ./dist/cli/bash-env.js -e -c 'false; echo "not reached"' --root .
61+
```
62+
63+
Options:
64+
- `--root <path>` - Root directory (default: current directory)
65+
- `--cwd <path>` - Working directory in sandbox (default: /home/user/project)
66+
- `--allow-write` - Enable write operations (writes stay in memory)
67+
- `--json` - Output as JSON (stdout, stderr, exitCode)
68+
- `-e, --errexit` - Exit on first error
69+
3770
### Debug with `pnpm dev:exec`
3871

3972
Reads script from stdin, executes it, shows output. Prefer this over ad-hoc test files.

PROJECT.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,7 @@ Woohoo
277277
- Make a binary called `bash-env` which takes a root path (default to .) and accepts a shell script via argument or STDIN and then executes it with an OverlayFS from the path
278278
- The idea is that this can be used as a secure alternative to `sh` or `bash` by AI agents
279279
- Should be a bin in `package.json`. Should be globally installable.
280+
281+
## Implementation phase 21
282+
283+
Build binaries with esbuild

knip.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"$schema": "https://unpkg.com/knip@5/schema.json",
3+
"project": ["src/**/*.ts"],
4+
"ignore": ["src/**/*.test.ts", "src/spec-tests/**"],
5+
"ignoreBinaries": ["tsx"],
6+
"rules": {
7+
"unlisted": "off",
8+
"unresolved": "off",
9+
"optionalPeerDependencies": "off",
10+
"types": "off"
11+
}
12+
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"typecheck": "tsc --noEmit",
4141
"lint": "biome check .",
4242
"lint:fix": "biome check --write .",
43+
"knip": "knip",
4344
"test": "vitest",
4445
"test:run": "vitest run",
4546
"test:unit": "vitest run --config vitest.unit.config.ts",
@@ -56,6 +57,7 @@
5657
"@types/sprintf-js": "^1.1.4",
5758
"@types/turndown": "^5.0.6",
5859
"ai": "^6.0.3",
60+
"knip": "^5.41.1",
5961
"typescript": "^5.9.3",
6062
"vitest": "^4.0.16",
6163
"zod": "^4.2.1"

0 commit comments

Comments
 (0)