brsh 2.7.0 → 2.8.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/CHANGELOG.md +13 -0
- package/Readme.md +33 -16
- package/bin/brsh-shell.js +15 -1
- package/dist/shell.es.js +83 -28
- package/dist/shell.es.js.map +1 -1
- package/dist/shell.min.js +3 -3
- package/dist/shell.min.js.map +1 -1
- package/dist/terminal.cjs.js +101 -0
- package/dist/terminal.cjs.js.map +1 -0
- package/dist/terminal.es.js +290 -8107
- package/dist/terminal.es.js.map +1 -1
- package/dist/terminal.min.js +4 -32
- package/dist/terminal.min.js.map +1 -1
- package/dist/wbt.es.js +346 -5821
- package/dist/wbt.es.js.map +1 -1
- package/dist/wbt.min.js +4 -18
- package/dist/wbt.min.js.map +1 -1
- package/index.js +29 -0
- package/lib/Terminal.js +45 -10
- package/lib/local/curl.js +60 -2
- package/lib/wbt/index.js +27 -50
- package/lib/wbt/packages/wllama.js +1051 -0
- package/lib/wbt/registry.js +20 -17
- package/package.json +3 -2
- package/test/curl.test.js +166 -0
- package/test/terminal.test.js +113 -0
- package/test/wasm-cli.test.js +127 -0
- package/test/wbt.test.js +322 -231
- package/vite.config.terminal.js +16 -12
- package/vitest.config.js +6 -0
- package/lib/wbt/daemon.js +0 -264
- package/lib/wbt/packages/pglite.js +0 -590
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
# [2.8.0](https://github.com/eliotstocker/Brsh-JS/compare/v2.7.0...v2.8.0) (2026-11-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **ci:** add pretest build and ensure dist/terminal.cjs.js exists for tests ([cb88ea4](https://github.com/eliotstocker/Brsh-JS/commit/cb88ea45f338db25efc0d7c65953f101d990be07))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **terminal:** externalize Shell dependency to reduce bundle size ([d2f8dd9](https://github.com/eliotstocker/Brsh-JS/commit/d2f8dd93155d55f1c843192a0d195032c7db95e3))
|
|
12
|
+
* **wbt:** add wllama v3 WebAssembly and WebGPU LLM inference adapter ([#26](https://github.com/eliotstocker/Brsh-JS/issues/26)) ([b7f647d](https://github.com/eliotstocker/Brsh-JS/commit/b7f647d703b4b0f67232f2a234737889e04c0689))
|
|
13
|
+
|
|
1
14
|
# [2.7.0](https://github.com/eliotstocker/Brsh-JS/compare/v2.6.0...v2.7.0) (2026-11-07)
|
|
2
15
|
|
|
3
16
|
|
package/Readme.md
CHANGED
|
@@ -26,11 +26,14 @@ You may also use it as a node module. Install via npm:
|
|
|
26
26
|
npm i brsh
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
Import
|
|
29
|
+
Import both Shell and Terminal in your code:
|
|
30
30
|
```js
|
|
31
31
|
// ESM
|
|
32
|
+
import Shell from 'brsh';
|
|
32
33
|
import Terminal from 'brsh/terminal';
|
|
34
|
+
|
|
33
35
|
// CJS
|
|
36
|
+
const Shell = require('brsh');
|
|
34
37
|
const Terminal = require('brsh/terminal');
|
|
35
38
|
```
|
|
36
39
|
|
|
@@ -56,6 +59,8 @@ All [Shell options](#shell-options) are also accepted and forwarded directly to
|
|
|
56
59
|
| option | required | default | description |
|
|
57
60
|
| ------ | -------- | ------- | ----------- |
|
|
58
61
|
| el | Yes | | A HTMLElement to fill with the terminal emulator |
|
|
62
|
+
| cli | No | | An existing `Shell` instance to attach the terminal emulator to |
|
|
63
|
+
| Shell | No | | A custom `Shell` class constructor to use when creating the underlying shell |
|
|
59
64
|
| font | No | `Roboto Mono` | Name of a Google Webfont to use for the console font; a monospace font is recommended |
|
|
60
65
|
| cursor | No | `none` | One of: `none`, `block`, `blink`. If `block` or `blink`, a cursor block character is shown at the end of the current line |
|
|
61
66
|
| outputAnimation | No | `none` | One of: `none`, `type`. If `type`, each character is appended in order for a retro typing effect |
|
|
@@ -210,7 +215,7 @@ Scripts run in a sub-shell and do not share context with the parent. To persist
|
|
|
210
215
|
|
|
211
216
|
## Web Binary Tool (`wbt`) — Optional WASM Binary Manager
|
|
212
217
|
|
|
213
|
-
`wbt` is an optional, APT-style binary manager for `brsh` that lets users install and run WebAssembly binaries (such as `
|
|
218
|
+
`wbt` is an optional, APT-style binary manager for `brsh` that lets users install and run WebAssembly binaries (such as `wllama`, `sqlite3`, `assemblyscript` / `asc`, `jq`, `python3`, `duckdb`, `graphviz`, `ffmpeg`, `wabt`, `quickjs`, `lua`, or custom `.wasm`/`.wat` URLs). It is **not** included in the default shell bundle unless you explicitly register it.
|
|
214
219
|
|
|
215
220
|
### Enabling `wbt`
|
|
216
221
|
|
|
@@ -232,6 +237,24 @@ const shell = new Shell({ filesystem: {} });
|
|
|
232
237
|
shell.context.setCommand(Wbt);
|
|
233
238
|
```
|
|
234
239
|
|
|
240
|
+
### Loading WASM CLI Tools without `wbt` (Base Shell)
|
|
241
|
+
|
|
242
|
+
You can also register WASM CLI binaries directly into any `Shell` instance without `wbt`:
|
|
243
|
+
|
|
244
|
+
```js
|
|
245
|
+
import Shell from 'brsh';
|
|
246
|
+
|
|
247
|
+
// 1. From a WASM URL or bytes
|
|
248
|
+
const MyTool = Shell.createWasmCommand({
|
|
249
|
+
name: 'mytool',
|
|
250
|
+
wasmUrl: 'https://example.com/mytool.wasm'
|
|
251
|
+
});
|
|
252
|
+
shell.context.setCommand(MyTool);
|
|
253
|
+
|
|
254
|
+
// 2. Or place any raw .wasm / .wat binary into /bin in your virtual filesystem:
|
|
255
|
+
shell.onCommand('tool.wasm --help');
|
|
256
|
+
```
|
|
257
|
+
|
|
235
258
|
### Usage in the shell
|
|
236
259
|
|
|
237
260
|
```sh
|
|
@@ -240,22 +263,16 @@ wbt list
|
|
|
240
263
|
wbt list --installed
|
|
241
264
|
|
|
242
265
|
# Search and inspect packages
|
|
243
|
-
wbt search
|
|
244
|
-
wbt show
|
|
266
|
+
wbt search sql
|
|
267
|
+
wbt show sqlite3
|
|
245
268
|
|
|
246
269
|
# Install curated WASM packages into /bin
|
|
247
|
-
wbt install
|
|
248
|
-
|
|
249
|
-
# Run
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
# Start a PGlite background daemon on localhost:5432 and query it via HTTP (curl / fetch) or psql
|
|
254
|
-
pg_ctl start -D /home/pgdata -p 5432
|
|
255
|
-
wbt services
|
|
256
|
-
curl -s -X POST -d "SELECT * FROM users;" http://localhost:5432/query
|
|
257
|
-
psql -p 5432 -c "SELECT * FROM users;"
|
|
258
|
-
pg_ctl stop -p 5432
|
|
270
|
+
wbt install wllama sqlite3 assemblyscript jq python3 duckdb graphviz ffmpeg
|
|
271
|
+
|
|
272
|
+
# Run Wllama v3 (llama.cpp WASM + WebGPU) for one-shot completions or interactive chat REPL!
|
|
273
|
+
wllama -m /home/model.gguf -p "Explain WebGPU in one sentence."
|
|
274
|
+
wllama pull https://huggingface.co/ggml-org/models/resolve/main/tinyllamas/stories15M.gguf -o /home/model.gguf
|
|
275
|
+
wllama -m /home/model.gguf # launches interactive multi-turn chat REPL
|
|
259
276
|
|
|
260
277
|
# Run SQLite3 (persists database files directly in the brsh filesystem)
|
|
261
278
|
sqlite3 /home/app.db "CREATE TABLE notes (id INT, body TEXT); INSERT INTO notes VALUES (1, 'Hello WASM');"
|
package/bin/brsh-shell.js
CHANGED
|
@@ -113,14 +113,28 @@ function reportSize() {
|
|
|
113
113
|
|
|
114
114
|
process.stdout.on('resize', () => { if (inInteractiveApp) reportSize(); });
|
|
115
115
|
|
|
116
|
+
let inProgressLine = false;
|
|
116
117
|
shell.on('stdOut', line => {
|
|
117
118
|
if (inInteractiveApp) {
|
|
118
119
|
process.stdout.write(line);
|
|
120
|
+
} else if (typeof line === 'string' && line.startsWith('\r')) {
|
|
121
|
+
inProgressLine = true;
|
|
122
|
+
process.stdout.write('\r\x1b[K' + line.slice(1));
|
|
119
123
|
} else {
|
|
124
|
+
if (inProgressLine) {
|
|
125
|
+
process.stdout.write('\n');
|
|
126
|
+
inProgressLine = false;
|
|
127
|
+
}
|
|
120
128
|
process.stdout.write(line + '\n');
|
|
121
129
|
}
|
|
122
130
|
});
|
|
123
|
-
shell.on('stdErr', line =>
|
|
131
|
+
shell.on('stdErr', line => {
|
|
132
|
+
if (inProgressLine) {
|
|
133
|
+
process.stdout.write('\n');
|
|
134
|
+
inProgressLine = false;
|
|
135
|
+
}
|
|
136
|
+
process.stderr.write(line + '\n');
|
|
137
|
+
});
|
|
124
138
|
|
|
125
139
|
shell.on('exit', code => {
|
|
126
140
|
destroyed = true;
|
package/dist/shell.es.js
CHANGED
|
@@ -5157,6 +5157,9 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
5157
5157
|
};
|
|
5158
5158
|
})), Be = /* @__PURE__ */ t(((e, t) => {
|
|
5159
5159
|
var n = K();
|
|
5160
|
+
function r(e) {
|
|
5161
|
+
return e >= 1048576 ? (e / 1048576).toFixed(1) + " MB" : e >= 1024 ? (e / 1024).toFixed(1) + " KB" : e + " B";
|
|
5162
|
+
}
|
|
5160
5163
|
t.exports = class extends n {
|
|
5161
5164
|
static get name() {
|
|
5162
5165
|
return "curl";
|
|
@@ -5165,75 +5168,108 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
5165
5168
|
return !0;
|
|
5166
5169
|
}
|
|
5167
5170
|
run() {
|
|
5168
|
-
let e = [...this.arguments], t = null, n = {},
|
|
5169
|
-
for (;
|
|
5170
|
-
let
|
|
5171
|
-
switch (
|
|
5171
|
+
let e = [...this.arguments], t = null, n = {}, i = null, a = !1, o = !1, s = null, c = null, l = 0;
|
|
5172
|
+
for (; l < e.length;) {
|
|
5173
|
+
let r = e[l];
|
|
5174
|
+
switch (r) {
|
|
5172
5175
|
case "-X":
|
|
5173
5176
|
case "--request":
|
|
5174
|
-
t = e[++
|
|
5177
|
+
t = e[++l];
|
|
5175
5178
|
break;
|
|
5176
5179
|
case "-H":
|
|
5177
5180
|
case "--header": {
|
|
5178
|
-
let t = e[++
|
|
5181
|
+
let t = e[++l] || "", r = t.indexOf(":");
|
|
5179
5182
|
r > 0 && (n[t.slice(0, r).trim()] = t.slice(r + 1).trim());
|
|
5180
5183
|
break;
|
|
5181
5184
|
}
|
|
5182
5185
|
case "-d":
|
|
5183
5186
|
case "--data":
|
|
5184
5187
|
case "--data-raw":
|
|
5185
|
-
|
|
5188
|
+
i = e[++l], t ||= "POST";
|
|
5186
5189
|
break;
|
|
5187
5190
|
case "-u":
|
|
5188
5191
|
case "--user": {
|
|
5189
|
-
let t = e[++
|
|
5192
|
+
let t = e[++l] || "";
|
|
5190
5193
|
n.Authorization = "Basic " + btoa(t);
|
|
5191
5194
|
break;
|
|
5192
5195
|
}
|
|
5193
5196
|
case "-o":
|
|
5194
5197
|
case "--output":
|
|
5195
|
-
|
|
5198
|
+
s = e[++l];
|
|
5196
5199
|
break;
|
|
5197
5200
|
case "-i":
|
|
5198
5201
|
case "--include":
|
|
5199
|
-
|
|
5202
|
+
a = !0;
|
|
5200
5203
|
break;
|
|
5201
5204
|
case "-s":
|
|
5202
5205
|
case "--silent":
|
|
5203
|
-
|
|
5206
|
+
o = !0;
|
|
5204
5207
|
break;
|
|
5208
|
+
case "-#":
|
|
5209
|
+
case "--progress-bar": break;
|
|
5205
5210
|
case "-L":
|
|
5206
5211
|
case "--location": break;
|
|
5207
|
-
default:
|
|
5212
|
+
default: r.startsWith("-") ? o || (this.stdErr = `curl: unknown option '${r}'`) : c = r;
|
|
5208
5213
|
}
|
|
5209
|
-
|
|
5214
|
+
l++;
|
|
5210
5215
|
}
|
|
5211
|
-
if (!
|
|
5212
|
-
if (!/^https?:\/\//i.test(
|
|
5213
|
-
let
|
|
5216
|
+
if (!c) return this.stdErr = "curl: no URL specified", this.exitCode = 1, Promise.resolve();
|
|
5217
|
+
if (!/^https?:\/\//i.test(c)) return this.stdErr = `curl: unsupported protocol in URL: ${c}`, this.exitCode = 1, Promise.resolve();
|
|
5218
|
+
let u = {
|
|
5214
5219
|
method: t || "GET",
|
|
5215
5220
|
headers: n
|
|
5216
5221
|
};
|
|
5217
|
-
return
|
|
5218
|
-
|
|
5222
|
+
return i !== null && (u.body = i), fetch(c, u).then(async (e) => {
|
|
5223
|
+
a && (this.stdOut = `HTTP/1.1 ${e.status} ${e.statusText}`, e.headers.forEach((e, t) => {
|
|
5219
5224
|
this.stdOut = `${t}: ${e}`;
|
|
5220
5225
|
}), this.stdOut = "");
|
|
5221
|
-
let t =
|
|
5222
|
-
if (
|
|
5223
|
-
|
|
5226
|
+
let t = null, n = Number(e.headers.get("content-length") || 0);
|
|
5227
|
+
if (e.body && typeof e.body.getReader == "function") {
|
|
5228
|
+
let i = e.body.getReader(), a = [], c = 0;
|
|
5229
|
+
for (;;) {
|
|
5230
|
+
let { done: e, value: t } = await i.read();
|
|
5231
|
+
if (e) break;
|
|
5232
|
+
if (a.push(t), c += t.length, s && !o) {
|
|
5233
|
+
if (n > 0) {
|
|
5234
|
+
let e = Math.min(100, Math.floor(c / n * 100)), t = Math.min(20, Math.round(c / n * 20)), i = "=".repeat(Math.max(0, t - 1)) + (t > 0 ? ">" : "") + " ".repeat(Math.max(0, 20 - t));
|
|
5235
|
+
this.stdOut = `\r[${i}] ${e}% (${r(c)} / ${r(n)})`;
|
|
5236
|
+
} else this.stdOut = `\rDownloading: ${r(c)}`;
|
|
5237
|
+
this.flush();
|
|
5238
|
+
}
|
|
5239
|
+
}
|
|
5240
|
+
t = new Uint8Array(c);
|
|
5241
|
+
let l = 0;
|
|
5242
|
+
for (let e of a) t.set(e, l), l += e.length;
|
|
5243
|
+
if (s && !o && c > 0) {
|
|
5244
|
+
let e = n || c;
|
|
5245
|
+
this.stdOut = `\r[${"=".repeat(20)}] 100% (${r(c)} / ${r(e)})`, this.flush();
|
|
5246
|
+
}
|
|
5247
|
+
} else {
|
|
5248
|
+
let n = await e.arrayBuffer();
|
|
5249
|
+
t = new Uint8Array(n);
|
|
5250
|
+
}
|
|
5251
|
+
if (s) try {
|
|
5252
|
+
let n = e.headers.get("content-type") || "";
|
|
5253
|
+
if (/^text\/|application\/(json|javascript|xml|x-sh)/i.test(n)) {
|
|
5254
|
+
let e = new TextDecoder().decode(t);
|
|
5255
|
+
this.fs.setFileByPath(s, e, !0);
|
|
5256
|
+
} else {
|
|
5257
|
+
let { BinaryFile: e } = ie(), r = e ? new e(t.buffer, n || "application/octet-stream") : t;
|
|
5258
|
+
this.fs.setFileByPath(s, r, !0);
|
|
5259
|
+
}
|
|
5224
5260
|
} catch (e) {
|
|
5225
|
-
this.stdErr = `curl: cannot write to '${
|
|
5261
|
+
this.stdErr = `curl: cannot write to '${s}': ${e.message}`, this.exitCode = 1;
|
|
5226
5262
|
}
|
|
5227
|
-
else t.split(/\r?\n/).forEach((e) => {
|
|
5263
|
+
else new TextDecoder().decode(t).split(/\r?\n/).forEach((e) => {
|
|
5228
5264
|
this.stdOut = e;
|
|
5229
5265
|
});
|
|
5230
5266
|
e.ok || (this.exitCode = 22);
|
|
5231
5267
|
}).catch((e) => {
|
|
5232
|
-
if (!
|
|
5268
|
+
if (!o) {
|
|
5233
5269
|
let t = e && e.message ? e.message : String(e);
|
|
5234
5270
|
if (e instanceof TypeError && /failed to fetch|networkerror|load failed|fetch is aborted/i.test(t)) {
|
|
5235
|
-
let e = /^https:\/\//i.test(
|
|
5236
|
-
!e && t ? this.stdErr = "curl: (35) Mixed content blocked — the page is served over HTTPS but the target URL is HTTP. Browsers block insecure requests from secure pages." : (this.stdErr = `curl: (6) Network request failed — this is likely a CORS error. The server at ${
|
|
5271
|
+
let e = /^https:\/\//i.test(c), t = typeof location < "u" && location.protocol === "https:";
|
|
5272
|
+
!e && t ? this.stdErr = "curl: (35) Mixed content blocked — the page is served over HTTPS but the target URL is HTTP. Browsers block insecure requests from secure pages." : (this.stdErr = `curl: (6) Network request failed — this is likely a CORS error. The server at ${c} did not include the required 'Access-Control-Allow-Origin' response header. You can only fetch cross-origin resources that explicitly allow it.`, this.stdErr = " Hint: try a public CORS proxy, or ensure the server sends 'Access-Control-Allow-Origin: *'.");
|
|
5237
5273
|
} else this.stdErr = `curl: (6) Could not connect: ${t}`;
|
|
5238
5274
|
}
|
|
5239
5275
|
this.exitCode = 6;
|
|
@@ -7711,7 +7747,11 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
7711
7747
|
let t = this.context.getCommand(e), r = e;
|
|
7712
7748
|
if (!t && !e.endsWith(".wasm") && (t = this.context.getCommand(`${e}.wasm`), t && (r = `${e}.wasm`)), !t) throw Error(`${e}: Command not found`);
|
|
7713
7749
|
let i = `${this.path}/${r}`;
|
|
7714
|
-
|
|
7750
|
+
if (this._isWasmFile(i, t)) {
|
|
7751
|
+
if (!this.context.fs.isExecutable(i)) throw Error(`${e}: permission denied`);
|
|
7752
|
+
return o.bind(null, i);
|
|
7753
|
+
}
|
|
7754
|
+
return typeof t == "string" && t.startsWith("#!") ? a.bind(this, t) : t;
|
|
7715
7755
|
}
|
|
7716
7756
|
async _parseCommandLine(t) {
|
|
7717
7757
|
let n = e._splitCommand(t);
|
|
@@ -7838,8 +7878,23 @@ var j, M, N, P, F, I, L, R, ee, z, B = e((() => {
|
|
|
7838
7878
|
static _escapeRegExp(e) {
|
|
7839
7879
|
return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
7840
7880
|
}
|
|
7881
|
+
static async create(t = {}) {
|
|
7882
|
+
let { filesystem: n, permissions: r, ...i } = t;
|
|
7883
|
+
if (p(n) || n && typeof n == "object" && p(n.filesystem)) {
|
|
7884
|
+
let e = await m(n, r);
|
|
7885
|
+
n = e.filesystem, r = e.permissions;
|
|
7886
|
+
}
|
|
7887
|
+
let a = new e(Object.assign({}, i, {
|
|
7888
|
+
filesystem: n,
|
|
7889
|
+
permissions: r
|
|
7890
|
+
}));
|
|
7891
|
+
return await a.ready, a;
|
|
7892
|
+
}
|
|
7893
|
+
static async fromContainer(t, n = {}) {
|
|
7894
|
+
return e.create(Object.assign({}, n, { filesystem: t }));
|
|
7895
|
+
}
|
|
7841
7896
|
};
|
|
7842
|
-
_.STATUS_READY = "READY", _.STATUS_WORKING = "WORKING", _.STATUS_DESTROYED = "DESTROYED", _.Command = s, _.InteractiveCommand = c, _.WasmCommand = o, _.ReplCommand = or(), _.FS = f, _.BinaryContainer = re(), _.Storage = _.BinaryContainer.FilesystemStorage, globalThis.shell = _, t.exports = _;
|
|
7897
|
+
_.STATUS_READY = "READY", _.STATUS_WORKING = "WORKING", _.STATUS_DESTROYED = "DESTROYED", _.Command = s, _.InteractiveCommand = c, _.WasmCommand = o, _.createWasmCommand = o.createGenericWasmCommand || o.createCommand, _.ReplCommand = or(), _.FS = f, _.BinaryContainer = re(), _.Storage = _.BinaryContainer.FilesystemStorage, globalThis.shell = _, globalThis.Shell = _, t.exports = _;
|
|
7843
7898
|
}));
|
|
7844
7899
|
//#endregion
|
|
7845
7900
|
export default sr();
|