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