brsh 1.4.0 → 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/.github/workflows/busybox-compat.yml +166 -0
- package/.github/workflows/release.yml +40 -0
- package/.releaserc.json +18 -0
- package/CHANGELOG.md +355 -0
- package/bin/brsh-cmd.js +78 -0
- package/bin/exportFileSystem.js +81 -156
- package/busybox-testsuite/cat.tests +49 -0
- package/busybox-testsuite/cp.tests +206 -0
- package/busybox-testsuite/grep.tests +237 -0
- package/busybox-testsuite/testing.sh +180 -0
- package/dist/brsh.css +2 -0
- package/dist/shell.es.js +5667 -0
- package/dist/shell.es.js.map +1 -0
- package/dist/shell.min.js +14 -222
- package/dist/shell.min.js.map +1 -149
- package/dist/terminal.es.js +6228 -0
- package/dist/terminal.es.js.map +1 -0
- package/dist/terminal.min.js +113 -18
- package/dist/terminal.min.js.map +1 -21
- package/index.js +206 -49
- package/lib/Context.js +12 -4
- package/lib/FileSystem.js +99 -6
- package/lib/NodeFileSystem.js +238 -0
- package/lib/ScriptCommand.js +193 -15
- package/lib/Terminal.js +188 -12
- package/lib/WasmCommand.js +252 -0
- package/lib/buildFilesystemStructure.js +58 -0
- package/lib/builtins/cat.js +67 -9
- package/lib/builtins/echo.js +36 -5
- package/lib/builtins/false.js +13 -0
- package/lib/builtins/grep.js +267 -0
- package/lib/builtins/index.js +9 -2
- package/lib/builtins/ls.js +86 -18
- package/lib/builtins/test.js +105 -0
- package/lib/builtins/true.js +10 -0
- package/lib/local/chmod.js +72 -0
- package/lib/local/cp.js +156 -0
- package/lib/local/index.js +8 -1
- package/lib/local/jsfunction.js +58 -0
- package/lib/local/mkdir.js +44 -0
- package/lib/local/mv.js +96 -0
- package/lib/local/pwd.js +13 -0
- package/lib/local/read.js +6 -4
- package/lib/local/rm.js +71 -0
- package/lib/local/which.js +2 -2
- package/package.json +31 -34
- package/test/builtins.test.js +505 -0
- package/test/exportFileSystem.test.js +226 -0
- package/test/helpers.js +35 -0
- package/test/local-commands.test.js +593 -0
- package/test/node-filesystem.test.js +133 -0
- package/test/scripts.test.js +277 -0
- package/test/shell.test.js +245 -0
- package/test/streaming.test.js +113 -0
- package/vite.config.shell.js +21 -0
- package/vite.config.terminal.js +27 -0
- package/vitest.config.js +15 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
name: Busybox Compatibility
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [master, main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
busybox-compat:
|
|
10
|
+
name: Busybox Test Suite
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
|
|
16
|
+
- uses: actions/setup-node@v4
|
|
17
|
+
with:
|
|
18
|
+
node-version: '22'
|
|
19
|
+
cache: npm
|
|
20
|
+
|
|
21
|
+
- name: Install dependencies
|
|
22
|
+
run: npm ci --legacy-peer-deps
|
|
23
|
+
|
|
24
|
+
- name: Set up brsh command wrappers
|
|
25
|
+
run: |
|
|
26
|
+
chmod +x bin/brsh-cmd.js
|
|
27
|
+
mkdir -p brsh-bin
|
|
28
|
+
for cmd in echo cat grep ls mkdir rm cp mv chmod pwd which true false busybox; do
|
|
29
|
+
ln -sf "$GITHUB_WORKSPACE/bin/brsh-cmd.js" "$GITHUB_WORKSPACE/brsh-bin/$cmd"
|
|
30
|
+
done
|
|
31
|
+
echo "$GITHUB_WORKSPACE/brsh-bin" >> "$GITHUB_PATH"
|
|
32
|
+
|
|
33
|
+
- name: Verify brsh-cmd.js loads
|
|
34
|
+
run: |
|
|
35
|
+
echo "Node: $(node --version)"
|
|
36
|
+
node -e "require('./index.js'); console.log('index.js loaded OK')" || echo "LOAD FAILED"
|
|
37
|
+
echo hello | node bin/brsh-cmd.js echo test-word 2>&1 && echo "brsh OK" || echo "brsh FAILED"
|
|
38
|
+
|
|
39
|
+
- name: Download busybox .tests suites (testing.sh format)
|
|
40
|
+
run: |
|
|
41
|
+
mkdir -p busybox-testsuite
|
|
42
|
+
BASE="https://raw.githubusercontent.com/mirror/busybox/master/testsuite"
|
|
43
|
+
for f in testing.sh cat.tests grep.tests \
|
|
44
|
+
mkdir.tests rm.tests cp.tests mv.tests chmod.tests pwd.tests; do
|
|
45
|
+
curl -fsSL "$BASE/$f" -o "busybox-testsuite/$f" \
|
|
46
|
+
&& echo "Downloaded $f" \
|
|
47
|
+
|| echo "Skipped $f (not found upstream)"
|
|
48
|
+
done
|
|
49
|
+
|
|
50
|
+
- name: Run busybox .tests suites
|
|
51
|
+
env:
|
|
52
|
+
# Pre-set ECHO so testing.sh skips its gcc-based auto-detection.
|
|
53
|
+
# The system sh builtin echo doesn't support -ne on Ubuntu (dash),
|
|
54
|
+
# which would cause testing.sh to try to compile ../scripts/echo.c.
|
|
55
|
+
# Use coreutils /bin/echo (not our brsh wrapper) — brsh-cmd.js appends
|
|
56
|
+
# an extra \n to every stdOut line, which would corrupt the expected
|
|
57
|
+
# files that testing.sh writes with "echo -ne".
|
|
58
|
+
ECHO: /bin/echo
|
|
59
|
+
# Enable optional blocks for features brsh implements
|
|
60
|
+
OPTIONFLAGS: ":FEATURE_CATN:FEATURE_GREP_EGREP_ALIAS:"
|
|
61
|
+
run: |
|
|
62
|
+
cd busybox-testsuite
|
|
63
|
+
|
|
64
|
+
total_pass=0
|
|
65
|
+
total_fail=0
|
|
66
|
+
ran_suites=""
|
|
67
|
+
skipped_suites=""
|
|
68
|
+
|
|
69
|
+
for suite in cat grep mkdir rm cp mv chmod pwd; do
|
|
70
|
+
testfile="${suite}.tests"
|
|
71
|
+
if [ ! -f "$testfile" ]; then
|
|
72
|
+
skipped_suites="$skipped_suites $suite(missing)"
|
|
73
|
+
continue
|
|
74
|
+
fi
|
|
75
|
+
|
|
76
|
+
ran_suites="$ran_suites $suite"
|
|
77
|
+
echo "──────────────────────────────"
|
|
78
|
+
echo "Suite: $testfile"
|
|
79
|
+
|
|
80
|
+
output=$(sh "$testfile" 2>&1) || true
|
|
81
|
+
echo "$output"
|
|
82
|
+
|
|
83
|
+
# testing.sh outputs "PASS: name" and "FAIL: name" per test
|
|
84
|
+
# Use absolute path to avoid resolving to our brsh grep wrapper
|
|
85
|
+
passed=$(/usr/bin/grep -c "^PASS:" <<< "$output" || true)
|
|
86
|
+
failed=$(/usr/bin/grep -c "^FAIL:" <<< "$output" || true)
|
|
87
|
+
total_pass=$((total_pass + passed))
|
|
88
|
+
total_fail=$((total_fail + failed))
|
|
89
|
+
done
|
|
90
|
+
|
|
91
|
+
echo ""
|
|
92
|
+
echo "══════════════════════════════"
|
|
93
|
+
echo "Suites run: $ran_suites"
|
|
94
|
+
[ -n "$skipped_suites" ] && echo "Suites skipped:$skipped_suites"
|
|
95
|
+
echo "Total passed: $total_pass"
|
|
96
|
+
echo "Total failed: $total_fail"
|
|
97
|
+
echo "══════════════════════════════"
|
|
98
|
+
[ "$total_fail" -eq 0 ] || exit 1
|
|
99
|
+
|
|
100
|
+
- name: Download busybox individual test suites
|
|
101
|
+
run: |
|
|
102
|
+
mkdir -p busybox-indiv
|
|
103
|
+
API="https://api.github.com/repos/mirror/busybox/contents/testsuite"
|
|
104
|
+
for dir in pwd rm mkdir mv cat echo cp; do
|
|
105
|
+
mkdir -p "busybox-indiv/$dir"
|
|
106
|
+
urls=$(curl -fsSL "$API/$dir" \
|
|
107
|
+
| python3 -c "import sys,json; [print(e['download_url']) for e in json.load(sys.stdin) if e['type']=='file']" \
|
|
108
|
+
2>/dev/null || true)
|
|
109
|
+
for url in $urls; do
|
|
110
|
+
fname=$(basename "$url")
|
|
111
|
+
curl -fsSL "$url" -o "busybox-indiv/$dir/$fname" \
|
|
112
|
+
&& echo "Downloaded $dir/$fname" \
|
|
113
|
+
|| echo "Skipped $dir/$fname"
|
|
114
|
+
done
|
|
115
|
+
done
|
|
116
|
+
|
|
117
|
+
- name: Run busybox individual tests
|
|
118
|
+
run: |
|
|
119
|
+
total_pass=0
|
|
120
|
+
total_fail=0
|
|
121
|
+
total_skip=0
|
|
122
|
+
|
|
123
|
+
for dir in busybox-indiv/pwd busybox-indiv/rm busybox-indiv/mkdir \
|
|
124
|
+
busybox-indiv/mv busybox-indiv/cat busybox-indiv/echo \
|
|
125
|
+
busybox-indiv/cp; do
|
|
126
|
+
applet=$(basename "$dir")
|
|
127
|
+
[ -d "$dir" ] || continue
|
|
128
|
+
|
|
129
|
+
for testfile in "$dir"/*; do
|
|
130
|
+
[ -f "$testfile" ] || continue
|
|
131
|
+
testname=$(basename "$testfile")
|
|
132
|
+
|
|
133
|
+
# Skip tests with FEATURE guards (requires busybox .config knowledge)
|
|
134
|
+
if /usr/bin/grep -q "^# FEATURE:" "$testfile" 2>/dev/null; then
|
|
135
|
+
echo "SKIP: $applet/$testname (feature guard)"
|
|
136
|
+
total_skip=$((total_skip + 1))
|
|
137
|
+
continue
|
|
138
|
+
fi
|
|
139
|
+
|
|
140
|
+
tmpdir=$(mktemp -d)
|
|
141
|
+
tmpout=$(mktemp)
|
|
142
|
+
set +e
|
|
143
|
+
(cd "$tmpdir" && sh -xe "$GITHUB_WORKSPACE/$testfile") >"$tmpout" 2>&1
|
|
144
|
+
result=$?
|
|
145
|
+
set -e
|
|
146
|
+
/bin/rm -rf "$tmpdir"
|
|
147
|
+
|
|
148
|
+
if [ $result -eq 0 ]; then
|
|
149
|
+
echo "PASS: $applet/$testname"
|
|
150
|
+
total_pass=$((total_pass + 1))
|
|
151
|
+
else
|
|
152
|
+
echo "FAIL: $applet/$testname (exit $result)"
|
|
153
|
+
[ $total_fail -lt 5 ] && sed 's/^/ /' "$tmpout" | tail -20
|
|
154
|
+
total_fail=$((total_fail + 1))
|
|
155
|
+
fi
|
|
156
|
+
/bin/rm -f "$tmpout"
|
|
157
|
+
done
|
|
158
|
+
done
|
|
159
|
+
|
|
160
|
+
echo ""
|
|
161
|
+
echo "══════════════════════════════"
|
|
162
|
+
echo "Total passed: $total_pass"
|
|
163
|
+
echo "Total skipped: $total_skip"
|
|
164
|
+
echo "Total failed: $total_fail"
|
|
165
|
+
echo "══════════════════════════════"
|
|
166
|
+
[ "$total_fail" -eq 0 ] || exit 1
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- master
|
|
7
|
+
- main
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: write
|
|
11
|
+
issues: write
|
|
12
|
+
pull-requests: write
|
|
13
|
+
id-token: write
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
release:
|
|
17
|
+
name: Release
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v4
|
|
22
|
+
with:
|
|
23
|
+
fetch-depth: 0
|
|
24
|
+
persist-credentials: false
|
|
25
|
+
|
|
26
|
+
- uses: actions/setup-node@v4
|
|
27
|
+
with:
|
|
28
|
+
node-version: '22'
|
|
29
|
+
cache: npm
|
|
30
|
+
|
|
31
|
+
- name: Install dependencies
|
|
32
|
+
run: npm ci --legacy-peer-deps
|
|
33
|
+
|
|
34
|
+
- name: Run tests
|
|
35
|
+
run: npm test
|
|
36
|
+
|
|
37
|
+
- name: Release
|
|
38
|
+
env:
|
|
39
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
40
|
+
run: npx semantic-release
|
package/.releaserc.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"branches": ["master", "main"],
|
|
3
|
+
"plugins": [
|
|
4
|
+
"@semantic-release/commit-analyzer",
|
|
5
|
+
"@semantic-release/release-notes-generator",
|
|
6
|
+
["@semantic-release/changelog", {
|
|
7
|
+
"changelogFile": "CHANGELOG.md"
|
|
8
|
+
}],
|
|
9
|
+
["@semantic-release/npm", {
|
|
10
|
+
"provenance": true
|
|
11
|
+
}],
|
|
12
|
+
["@semantic-release/git", {
|
|
13
|
+
"assets": ["package.json", "package-lock.json", "CHANGELOG.md"],
|
|
14
|
+
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
|
|
15
|
+
}],
|
|
16
|
+
"@semantic-release/github"
|
|
17
|
+
]
|
|
18
|
+
}
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
# [2.0.0](https://github.com/eliotstocker/Brsh-JS/compare/v1.4.0...v2.0.0) (2026-05-07)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* enable OIDC trusted publishing via npm plugin provenance option ([#18](https://github.com/eliotstocker/Brsh-JS/issues/18)) ([23dffe7](https://github.com/eliotstocker/Brsh-JS/commit/23dffe71861ab4b3980342887604b705de064b20))
|
|
7
|
+
* switch to esbuild ([b911e8e](https://github.com/eliotstocker/Brsh-JS/commit/b911e8ee96ba75f6ccd35d7a5ae5347c90c47881))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* add semantic-release pipeline for automated npm and GitHub releases ([#17](https://github.com/eliotstocker/Brsh-JS/issues/17)) ([b22d57c](https://github.com/eliotstocker/Brsh-JS/commit/b22d57cc6db9beffb1cf8f49f49bb0a293f8dbd1))
|
|
13
|
+
* comprehensive test suite, Vite build, bash feature expansion, and terminal UX improvements ([#16](https://github.com/eliotstocker/Brsh-JS/issues/16)) ([8d8c06e](https://github.com/eliotstocker/Brsh-JS/commit/8d8c06e60659c6256c735c712fce4186cfe5f94c))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### BREAKING CHANGES
|
|
17
|
+
|
|
18
|
+
* _setCurrentLine no longer appends a cursor <span> at the
|
|
19
|
+
end of innerText; it now rebuilds the line using DOM text nodes + a single
|
|
20
|
+
cursor span at the correct position. Visual output is equivalent but the
|
|
21
|
+
internal DOM structure differs.
|
|
22
|
+
|
|
23
|
+
https://claude.ai/code/session_01NRmUt8KLPnuEYhBjsW6MLb
|
|
24
|
+
|
|
25
|
+
* feat(terminal): add Alt+Left/Right word navigation
|
|
26
|
+
|
|
27
|
+
Alt+Left jumps to the start of the previous word (skips trailing
|
|
28
|
+
whitespace then the word); Alt+Right jumps past the end of the next
|
|
29
|
+
word. Matches the zsh/readline word-movement behaviour.
|
|
30
|
+
|
|
31
|
+
https://claude.ai/code/session_01NRmUt8KLPnuEYhBjsW6MLb
|
|
32
|
+
|
|
33
|
+
* feat(terminal): expose sendKey() public API for mobile/custom input
|
|
34
|
+
|
|
35
|
+
Allows host pages to drive all terminal actions programmatically:
|
|
36
|
+
|
|
37
|
+
terminal.sendKey('ArrowUp') // history back
|
|
38
|
+
terminal.sendKey('ArrowLeft', { alt: true }) // word left
|
|
39
|
+
terminal.sendKey('a') // character input
|
|
40
|
+
terminal.sendKey('Enter') // submit
|
|
41
|
+
terminal.sendKey('u', { ctrl: true }) // kill to line start
|
|
42
|
+
|
|
43
|
+
Routes nav keys and Ctrl combos through _navKeyEvent; everything else
|
|
44
|
+
through _keyEvent — same paths as physical keyboard events.
|
|
45
|
+
|
|
46
|
+
https://claude.ai/code/session_01NRmUt8KLPnuEYhBjsW6MLb
|
|
47
|
+
|
|
48
|
+
* feat(ci): add busybox test suite compatibility job
|
|
49
|
+
|
|
50
|
+
- bin/brsh-cmd.js — multi-call CLI that runs any brsh builtin via the
|
|
51
|
+
Node.js Shell class with useRealFilesystem enabled. Symlink as the
|
|
52
|
+
command name (echo, cat, grep, …) and argv[1] basename selects which
|
|
53
|
+
command to run; works in direct mode too (brsh-cmd echo hello).
|
|
54
|
+
- .github/workflows/busybox-compat.yml — sparse-clones the busybox
|
|
55
|
+
mirror, creates symlinks for all supported commands in a temp PATH
|
|
56
|
+
directory, then runs echo/cat/grep/mkdir/rm/cp/mv/chmod/pwd test
|
|
57
|
+
suites. Results are summarised (passed/failed counts); the step is
|
|
58
|
+
continue-on-error so the workflow reports compatibility without
|
|
59
|
+
blocking unrelated CI.
|
|
60
|
+
|
|
61
|
+
https://claude.ai/code/session_01NRmUt8KLPnuEYhBjsW6MLb
|
|
62
|
+
|
|
63
|
+
* fix(ci): fix busybox compat job — sparse checkout and grep PATH shadowing
|
|
64
|
+
|
|
65
|
+
Two bugs:
|
|
66
|
+
|
|
67
|
+
1. git sparse-checkout without an explicit checkout step left the
|
|
68
|
+
testsuite/ directory empty. Replaced with direct curl downloads of
|
|
69
|
+
only the test files needed — faster and simpler.
|
|
70
|
+
|
|
71
|
+
2. After adding brsh-bin/ to $GITHUB_PATH, grep inside the test-runner
|
|
72
|
+
step resolved to our brsh grep wrapper (no -oP support). Fixed by
|
|
73
|
+
using /usr/bin/grep explicitly for result-count parsing.
|
|
74
|
+
|
|
75
|
+
https://claude.ai/code/session_01NRmUt8KLPnuEYhBjsW6MLb
|
|
76
|
+
|
|
77
|
+
* fix(ci): fix busybox compat — ECHO detection and PASS/FAIL counting
|
|
78
|
+
|
|
79
|
+
Two more bugs found by running the harness locally:
|
|
80
|
+
|
|
81
|
+
1. testing.sh auto-detects echo support by running `echo -ne`. The
|
|
82
|
+
system sh (dash) builtin echo doesn't support -ne, so testing.sh
|
|
83
|
+
tries to compile ../scripts/echo.c via gcc — which doesn't exist,
|
|
84
|
+
causing an exit 1 for every test suite. Fixed by pre-setting the
|
|
85
|
+
ECHO env var to our brsh echo wrapper; testing.sh checks this first
|
|
86
|
+
and skips compilation entirely.
|
|
87
|
+
|
|
88
|
+
2. testing.sh outputs "PASS: name" / "FAIL: name" per test, not any
|
|
89
|
+
"N passed, N failed" summary line. Switched counting to grep for
|
|
90
|
+
^PASS: and ^FAIL: line prefixes.
|
|
91
|
+
|
|
92
|
+
Also: echo.tests does not exist in the busybox mirror (404), removed
|
|
93
|
+
from the download list. Added OPTIONFLAGS to enable optional test
|
|
94
|
+
blocks for features brsh implements (cat -n/-b, egrep alias).
|
|
95
|
+
|
|
96
|
+
https://claude.ai/code/session_01NRmUt8KLPnuEYhBjsW6MLb
|
|
97
|
+
|
|
98
|
+
* fix(ci): remove failing assertion from busybox compat job
|
|
99
|
+
|
|
100
|
+
The job's purpose is to report compatibility, not gate on it.
|
|
101
|
+
Removing [ "$total_fail" -eq 0 ] lets the step always exit 0 so the
|
|
102
|
+
check run reports green with the pass/fail counts visible in the log.
|
|
103
|
+
continue-on-error was not reliably preventing the check conclusion from
|
|
104
|
+
being reported as failure.
|
|
105
|
+
|
|
106
|
+
https://claude.ai/code/session_01NRmUt8KLPnuEYhBjsW6MLb
|
|
107
|
+
|
|
108
|
+
* fix(ci): rewrite git+ssh ansi_up URL to HTTPS for npm ci
|
|
109
|
+
|
|
110
|
+
package-lock.json resolved ansi_up as git+ssh://git@github.com/... because
|
|
111
|
+
the dev machine has a git URL rewrite (HTTPS → SSH). GitHub Actions
|
|
112
|
+
runners have no SSH key so npm ci fails to fetch that dependency.
|
|
113
|
+
|
|
114
|
+
Adding a git config URL rewrite before npm ci translates the SSH URL
|
|
115
|
+
back to HTTPS at fetch time, which works without credentials for public
|
|
116
|
+
repos.
|
|
117
|
+
|
|
118
|
+
https://claude.ai/code/session_01NRmUt8KLPnuEYhBjsW6MLb
|
|
119
|
+
|
|
120
|
+
* fix(ci): correct git URL rewrite prefix for npm ci
|
|
121
|
+
|
|
122
|
+
npm strips the "git+" scheme prefix before invoking git, so the
|
|
123
|
+
insteadOf pattern must match "ssh://git@github.com/" not the full
|
|
124
|
+
"git+ssh://git@github.com/" string from the lockfile.
|
|
125
|
+
|
|
126
|
+
Verified locally: git ls-remote correctly resolves to HTTPS with this
|
|
127
|
+
pattern.
|
|
128
|
+
|
|
129
|
+
https://claude.ai/code/session_01NRmUt8KLPnuEYhBjsW6MLb
|
|
130
|
+
|
|
131
|
+
* fix(ci): fix npm ci — HTTPS lockfile URL and legacy-peer-deps flag
|
|
132
|
+
|
|
133
|
+
Two issues preventing npm ci from working in GitHub Actions:
|
|
134
|
+
|
|
135
|
+
1. package-lock.json resolved ansi_up as git+ssh://... (local git was
|
|
136
|
+
rewriting HTTPS→SSH). Changed to git+https:// so CI can fetch the
|
|
137
|
+
public repo without an SSH key. The commit SHA is unchanged.
|
|
138
|
+
|
|
139
|
+
2. The lockfile has a vite@8/esbuild@0.25 peer dependency conflict that
|
|
140
|
+
requires --legacy-peer-deps to install (matches how the lockfile was
|
|
141
|
+
originally generated on the dev machine).
|
|
142
|
+
|
|
143
|
+
https://claude.ai/code/session_01NRmUt8KLPnuEYhBjsW6MLb
|
|
144
|
+
|
|
145
|
+
* fix(ci): use /bin/echo for busybox ECHO harness var
|
|
146
|
+
|
|
147
|
+
brsh-cmd.js appends \n to every stdOut line; when echo -e interprets
|
|
148
|
+
escape sequences the output already contains \n, resulting in a double
|
|
149
|
+
newline. testing.sh uses ECHO to write expected files via "echo -ne",
|
|
150
|
+
so every cmp check failed (0/59 passing).
|
|
151
|
+
|
|
152
|
+
Use coreutils /bin/echo which handles -ne correctly. The commands under
|
|
153
|
+
test (cat, grep, cp, …) remain as brsh wrappers via PATH.
|
|
154
|
+
|
|
155
|
+
https://claude.ai/code/session_01NRmUt8KLPnuEYhBjsW6MLb
|
|
156
|
+
|
|
157
|
+
* chore: ignore brsh-bin/ runtime artifact directory
|
|
158
|
+
|
|
159
|
+
brsh-bin/ contains symlinks created locally when running the busybox
|
|
160
|
+
CI setup step manually; it should not be tracked.
|
|
161
|
+
|
|
162
|
+
https://claude.ai/code/session_01NRmUt8KLPnuEYhBjsW6MLb
|
|
163
|
+
|
|
164
|
+
* fix(cat): read piped stdin and fix trailing-newline double-output
|
|
165
|
+
|
|
166
|
+
Two bugs caused all cat tests to fail:
|
|
167
|
+
|
|
168
|
+
1. cat with no file arguments returned an error instead of reading stdin.
|
|
169
|
+
The busybox tests pipe all input via stdin (no file args). Added stdin
|
|
170
|
+
support: brsh-cmd.js reads process.stdin before running the command,
|
|
171
|
+
stores it on the Shell, and _runCommand injects it onto each command
|
|
172
|
+
instance as instance.stdin. cat now uses this.stdin when no paths
|
|
173
|
+
are given.
|
|
174
|
+
|
|
175
|
+
2. Splitting file/stdin content on '\n' produces a trailing '' for any
|
|
176
|
+
POSIX text file that ends with '\n'. Each element becomes a separate
|
|
177
|
+
stdOut event and brsh-cmd.js appends '\n' to each, so the trailing ''
|
|
178
|
+
became a spurious blank final line. Fixed by stripping a trailing '\n'
|
|
179
|
+
from content before splitting.
|
|
180
|
+
|
|
181
|
+
https://claude.ai/code/session_01NRmUt8KLPnuEYhBjsW6MLb
|
|
182
|
+
|
|
183
|
+
* fix(grep): add stdin support, -L/-o/-w/-x/-s/-f flags, multi-pattern OR
|
|
184
|
+
|
|
185
|
+
Key fixes:
|
|
186
|
+
- No file args now reads from stdin (same pipe model as cat)
|
|
187
|
+
- '-' arg treated as stdin specifier, labeled '(standard input)'
|
|
188
|
+
- Multiple -e patterns OR'd together instead of overwriting
|
|
189
|
+
- -L (list non-matching files): success = printed something, not found a match
|
|
190
|
+
- -o (only matching): emit each match segment; skip zero-length matches
|
|
191
|
+
- -w (word boundary): wrap pattern in (?:^|\W)...(?:\W|$)
|
|
192
|
+
- -x (whole line): wrap pattern in ^(?:...)$
|
|
193
|
+
- -s (suppress errors): silence stderr on missing files
|
|
194
|
+
- -f file (pattern file): read patterns from file or stdin (-)
|
|
195
|
+
- -a (binary as text): accepted silently
|
|
196
|
+
- (standard input) label in multi-source mode
|
|
197
|
+
- SUSv3: -q with a match exits 0 even if there were file errors
|
|
198
|
+
- Strip trailing empty element from split lines (same fix as cat)
|
|
199
|
+
|
|
200
|
+
https://claude.ai/code/session_01NRmUt8KLPnuEYhBjsW6MLb
|
|
201
|
+
|
|
202
|
+
* fix(cp): full symlink handling for all -R/-d/-P/-L/-H combinations
|
|
203
|
+
|
|
204
|
+
NodeFileSystem gains isSymlink/readSymlink/createSymlink (lstat/readlink/
|
|
205
|
+
symlink wrappers) to support symlink-aware copies.
|
|
206
|
+
|
|
207
|
+
cp rewritten with a two-mode model (thisMode + childMode):
|
|
208
|
+
- No flags: dereference all symlinks ('follow')
|
|
209
|
+
- -d / -P: preserve symlinks ('preserve')
|
|
210
|
+
- -L: dereference all ('follow')
|
|
211
|
+
- -H: dereference command-line symlinks, preserve recursive children
|
|
212
|
+
('follow_cl' → clItemMode=follow, childMode=preserve)
|
|
213
|
+
- -R alone: default to preserve; explicit -L/-H/-d/-P override
|
|
214
|
+
- Last symlink flag wins (-RHL → follow all, -RLH → follow_cl)
|
|
215
|
+
|
|
216
|
+
Error message changed to busybox format:
|
|
217
|
+
'cp: omitting directory' (was 'cp: -r not specified; omitting directory')
|
|
218
|
+
|
|
219
|
+
Guards added so cp works on virtual filesystem too (isSymlink guarded
|
|
220
|
+
with ?. so the browser shell is unaffected).
|
|
221
|
+
|
|
222
|
+
https://claude.ai/code/session_01NRmUt8KLPnuEYhBjsW6MLb
|
|
223
|
+
|
|
224
|
+
* feat: add busybox individual test suites (pwd, rm, mkdir, mv, cat, echo, cp)
|
|
225
|
+
|
|
226
|
+
The busybox testsuite has per-command directories (testsuite/pwd/,
|
|
227
|
+
testsuite/mv/, etc.) with individual shell scripts that call
|
|
228
|
+
'busybox <cmd>'. This commit adds support for running them.
|
|
229
|
+
|
|
230
|
+
Changes:
|
|
231
|
+
- brsh-cmd.js: 'busybox' is now a recognised multi-call name alongside
|
|
232
|
+
'brsh-cmd', so a symlink named 'busybox' dispatches to brsh builtins
|
|
233
|
+
- cat.js: '-' in a path list now reads from stdin (cat foo - bar)
|
|
234
|
+
- mv.js: use fs.renameSync on real filesystem so symlinks and hard links
|
|
235
|
+
are preserved atomically; add -t <dest> flag (destination first)
|
|
236
|
+
- cp.js: add -a flag (alias for -Rdp: recursive + preserve symlinks)
|
|
237
|
+
- busybox-compat.yml: new steps download individual test files via the
|
|
238
|
+
GitHub API and run each with 'sh -e' in an isolated temp dir;
|
|
239
|
+
tests with '# FEATURE:' guards are skipped (require .config knowledge);
|
|
240
|
+
busybox symlink added to brsh-bin
|
|
241
|
+
|
|
242
|
+
https://claude.ai/code/session_01NRmUt8KLPnuEYhBjsW6MLb
|
|
243
|
+
|
|
244
|
+
* fix(grep): handle -f/-e with empty pattern source correctly
|
|
245
|
+
|
|
246
|
+
When -f reads an empty file (or -e '' is given), patterns[] stays
|
|
247
|
+
empty but a pattern source was explicitly provided. The old code would
|
|
248
|
+
hit the "no pattern given" early-exit, rejecting valid invocations like
|
|
249
|
+
`grep -v -f EMPTY_FILE` (which should print all lines and exit 0).
|
|
250
|
+
|
|
251
|
+
Track patternSourceGiven; only promote first positional arg to pattern
|
|
252
|
+
when neither -e nor -f has been specified.
|
|
253
|
+
|
|
254
|
+
https://claude.ai/code/session_01NRmUt8KLPnuEYhBjsW6MLb
|
|
255
|
+
|
|
256
|
+
* fix(busybox): pass all busybox cp, rm, and grep test suites
|
|
257
|
+
|
|
258
|
+
- grep: split newline-delimited patterns from -e and positional args;
|
|
259
|
+
always show filenames when -r is used (multiSource); skip dir-symlinks
|
|
260
|
+
during recursion but follow them at top level (-r semantics)
|
|
261
|
+
- rm: use readdirSync for real fs to catch dangling symlinks; check
|
|
262
|
+
isSymlink before recursing to avoid following symlinks as dirs;
|
|
263
|
+
use lstatSync in deleteFileByPath so dangling symlinks can be unlinked
|
|
264
|
+
- cp: track childSymlinkModeOverride for last -L/-P flag; always use
|
|
265
|
+
follow mode for CL-level items when -H is present (clItemMode);
|
|
266
|
+
derive child mode from override or 'preserve' when -H is involved
|
|
267
|
+
|
|
268
|
+
https://claude.ai/code/session_01NRmUt8KLPnuEYhBjsW6MLb
|
|
269
|
+
|
|
270
|
+
* feat: add busybox individual test suites (cat, cp, grep)
|
|
271
|
+
|
|
272
|
+
https://claude.ai/code/session_01NRmUt8KLPnuEYhBjsW6MLb
|
|
273
|
+
|
|
274
|
+
* fix(cat): join file parts without separator to avoid extra blank lines
|
|
275
|
+
|
|
276
|
+
cat concatenates files byte-by-byte with no separator. Using join('\n')
|
|
277
|
+
was adding a spurious newline between parts whose content already ends
|
|
278
|
+
with \n, causing extra blank lines in the output. Changed to join('').
|
|
279
|
+
Updated the unit test to use proper POSIX text files (trailing \n) so
|
|
280
|
+
the behaviour is consistent.
|
|
281
|
+
|
|
282
|
+
https://claude.ai/code/session_01NRmUt8KLPnuEYhBjsW6MLb
|
|
283
|
+
|
|
284
|
+
* fix(ci): prevent premature bash -e exit on test failure; add explicit fail check
|
|
285
|
+
|
|
286
|
+
With bash -e (default for GitHub Actions run steps), a subshell exiting
|
|
287
|
+
non-zero causes the outer script to exit immediately before result=$? runs,
|
|
288
|
+
making the step fail silently on the first test failure with no diagnostic.
|
|
289
|
+
|
|
290
|
+
Add set +e/set -e around the subshell to capture the result correctly.
|
|
291
|
+
Use /bin/rm instead of brsh rm for tmpdir cleanup (avoids PATH confusion).
|
|
292
|
+
Add [ "$total_fail" -eq 0 ] || exit 1 at the end of both test steps so
|
|
293
|
+
failures are reported explicitly after the full summary is printed.
|
|
294
|
+
|
|
295
|
+
https://claude.ai/code/session_01NRmUt8KLPnuEYhBjsW6MLb
|
|
296
|
+
|
|
297
|
+
* fix(ci): add diagnostics - show failing test output and verify brsh loads
|
|
298
|
+
|
|
299
|
+
Add a 'Verify brsh-cmd.js loads' step that prints the Node.js version,
|
|
300
|
+
checks whether index.js loads, and does a smoke-test run of brsh-cmd.js.
|
|
301
|
+
|
|
302
|
+
In the individual-test runner, capture stdout+stderr with sh -xe so each
|
|
303
|
+
failing command is traced; print the last 20 lines for the first 5
|
|
304
|
+
failures so the root cause is visible in CI logs.
|
|
305
|
+
|
|
306
|
+
https://claude.ai/code/session_01NRmUt8KLPnuEYhBjsW6MLb
|
|
307
|
+
|
|
308
|
+
* fix(mv,cat): use lstatSync for real-fs existence; handle empty stdin in cat; upgrade CI to Node 22
|
|
309
|
+
|
|
310
|
+
mv: getFileByPath calls readFileSync which throws EACCES for unreadable
|
|
311
|
+
files (e.g. chmod a-r foo), making it return null — mv then reports
|
|
312
|
+
'No such file or directory'. Switch the real-fs path to lstatSync which
|
|
313
|
+
succeeds regardless of read permission and also handles dangling symlinks.
|
|
314
|
+
Split real-fs and virtual-fs loops cleanly so each uses the right API.
|
|
315
|
+
|
|
316
|
+
cat: 'if (!stdinContent)' rejected an empty string, causing cat with
|
|
317
|
+
empty stdin and no file args to error instead of outputting nothing.
|
|
318
|
+
Changed to 'if (stdinContent == null)' so cat passes for empty pipes.
|
|
319
|
+
|
|
320
|
+
CI: upgrade node-version from '20' to '22' so the Node.js version
|
|
321
|
+
matches the dev environment and eliminates any 20 vs 22 incompatibility.
|
|
322
|
+
|
|
323
|
+
https://claude.ai/code/session_01NRmUt8KLPnuEYhBjsW6MLb
|
|
324
|
+
|
|
325
|
+
* feat: run .wasm and .wat files as shell binaries
|
|
326
|
+
|
|
327
|
+
Add WasmCommand (extends ScriptCommand so the bound-constructor
|
|
328
|
+
instanceof check in _runCommand works) that handles WebAssembly
|
|
329
|
+
execution:
|
|
330
|
+
|
|
331
|
+
- .wasm files: read as binary (fs.readFileSync without encoding on the
|
|
332
|
+
real filesystem; charCode-based conversion for the virtual one),
|
|
333
|
+
compile with WebAssembly.compile, then instantiate with a full WASI
|
|
334
|
+
snapshot_preview1 import object (fd_write, fd_read, proc_exit,
|
|
335
|
+
args_sizes_get/args_get, environ_*, clock_time_get, random_get, …).
|
|
336
|
+
A Proxy on each import namespace silently returns 0 for any
|
|
337
|
+
unrecognised imports so modules that use extra WASI calls don't crash.
|
|
338
|
+
Simple non-WASI modules can also use env.print / env.eprint.
|
|
339
|
+
|
|
340
|
+
- .wat files: decode bytes to text, compile via the optional 'wabt'
|
|
341
|
+
npm package (require('wabt')), then run as WASM. A clear error with
|
|
342
|
+
install instructions is shown if wabt is not available.
|
|
343
|
+
|
|
344
|
+
Entry-point detection order: _start → __wasi_command → main → run.
|
|
345
|
+
stdin is passed through fd_read; stdout/stderr are line-buffered and
|
|
346
|
+
emitted as stdOut/stdErr events.
|
|
347
|
+
|
|
348
|
+
index.js changes:
|
|
349
|
+
- require WasmCommand
|
|
350
|
+
- _isWasmFile(path, content) detects by extension (.wasm/.wat), WASM
|
|
351
|
+
magic bytes (\0asm), or WAT preamble (trimmed '(module')
|
|
352
|
+
- _parseCommand: after the #! script branch, check _isWasmFile and
|
|
353
|
+
return WasmCommand.bind(null, command) for matches
|
|
354
|
+
|
|
355
|
+
https://claude.ai/code/session_01NRmUt8KLPnuEYhBjsW6MLb
|
package/bin/brsh-cmd.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
// Multi-call CLI for brsh builtins.
|
|
5
|
+
// Symlink this file as the command name (echo, cat, grep, …) and it will
|
|
6
|
+
// run that command through brsh with useRealFilesystem enabled.
|
|
7
|
+
//
|
|
8
|
+
// Usage (via symlink): echo hello world
|
|
9
|
+
// Usage (direct): brsh-cmd.js echo hello world
|
|
10
|
+
|
|
11
|
+
const Shell = require('../index.js');
|
|
12
|
+
const nodePath = require('path');
|
|
13
|
+
|
|
14
|
+
const scriptName = nodePath.basename(process.argv[1]).replace(/\.js$/, '');
|
|
15
|
+
const isMultiCall = scriptName === 'brsh-cmd' || scriptName === 'busybox';
|
|
16
|
+
|
|
17
|
+
const cmdName = isMultiCall ? process.argv[2] : scriptName;
|
|
18
|
+
const args = isMultiCall ? process.argv.slice(3) : process.argv.slice(2);
|
|
19
|
+
|
|
20
|
+
if (!cmdName) {
|
|
21
|
+
process.stderr.write('usage: brsh-cmd <command> [args...]\n');
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function shellQuote(s) {
|
|
26
|
+
return "'" + s.replace(/'/g, "'\\''") + "'";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const commandLine = cmdName + (args.length ? ' ' + args.map(shellQuote).join(' ') : '');
|
|
30
|
+
|
|
31
|
+
const shell = new Shell({
|
|
32
|
+
useRealFilesystem: true,
|
|
33
|
+
cwd: process.cwd(),
|
|
34
|
+
hostname: 'brsh'
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
let exitCode = 0;
|
|
38
|
+
let ran = false;
|
|
39
|
+
let shellReady = false;
|
|
40
|
+
let stdinReady = false;
|
|
41
|
+
let stdinData = '';
|
|
42
|
+
|
|
43
|
+
shell.on('stdOut', line => process.stdout.write(line + '\n'));
|
|
44
|
+
shell.on('stdErr', line => process.stderr.write(line + '\n'));
|
|
45
|
+
shell.on('exitCode', code => { exitCode = code; });
|
|
46
|
+
|
|
47
|
+
function maybeRun() {
|
|
48
|
+
if (shellReady && stdinReady && !ran) {
|
|
49
|
+
ran = true;
|
|
50
|
+
shell.stdin = stdinData;
|
|
51
|
+
shell.onCommand(commandLine)
|
|
52
|
+
.then(() => process.exit(exitCode))
|
|
53
|
+
.catch(() => process.exit(1));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
shell.on('status', status => {
|
|
58
|
+
if (status === Shell.STATUS_READY) {
|
|
59
|
+
shellReady = true;
|
|
60
|
+
maybeRun();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (process.stdin.isTTY) {
|
|
65
|
+
stdinReady = true;
|
|
66
|
+
} else {
|
|
67
|
+
const chunks = [];
|
|
68
|
+
process.stdin.on('data', chunk => chunks.push(chunk));
|
|
69
|
+
process.stdin.on('end', () => {
|
|
70
|
+
stdinData = Buffer.concat(chunks).toString();
|
|
71
|
+
stdinReady = true;
|
|
72
|
+
maybeRun();
|
|
73
|
+
});
|
|
74
|
+
process.stdin.on('error', () => {
|
|
75
|
+
stdinReady = true;
|
|
76
|
+
maybeRun();
|
|
77
|
+
});
|
|
78
|
+
}
|