@nimbus-sh/core 0.5.0 → 0.7.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/README.md +47 -26
- package/dist/_shared/byte-stream.d.ts +5 -4
- package/dist/_shared/byte-stream.d.ts.map +1 -1
- package/dist/_shared/cache-stats.d.ts +23 -1
- package/dist/_shared/cache-stats.d.ts.map +1 -1
- package/dist/_shared/cache-stats.js +13 -1
- package/dist/_shared/exports-resolver.d.ts +1 -1
- package/dist/_shared/exports-resolver.js +1 -1
- package/dist/_shared/real-node-imports.d.ts +7 -0
- package/dist/_shared/real-node-imports.d.ts.map +1 -1
- package/dist/_shared/real-node-imports.js +8 -0
- package/dist/_shared/retry.js +1 -1
- package/dist/_shared/tarball.d.ts +23 -5
- package/dist/_shared/tarball.d.ts.map +1 -1
- package/dist/_shared/tarball.js +38 -5
- package/dist/_shared/vfs-write-ledger.d.ts.map +1 -1
- package/dist/_shared/vfs-write-ledger.js +22 -16
- package/dist/constants.d.ts +5 -11
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +16 -56
- package/dist/runtime/assets-loader.js +1 -1
- package/dist/runtime/comment-strip.d.ts +0 -35
- package/dist/runtime/comment-strip.d.ts.map +1 -1
- package/dist/runtime/comment-strip.js +48 -20
- package/dist/runtime/esbuild-service.d.ts +38 -42
- package/dist/runtime/esbuild-service.d.ts.map +1 -1
- package/dist/runtime/esbuild-service.js +494 -197
- package/dist/runtime/javascript-ast.d.ts.map +1 -1
- package/dist/runtime/javascript-ast.js +45 -7
- package/dist/runtime/opentui-wasm-backend.d.ts.map +1 -1
- package/dist/runtime/opentui-wasm-backend.js +18 -16
- package/dist/runtime/port-registry.d.ts +4 -2
- package/dist/runtime/port-registry.d.ts.map +1 -1
- package/dist/runtime/port-registry.js +60 -8
- package/dist/runtime/virtual-socket-kernel.generated.d.ts +1 -1
- package/dist/runtime/virtual-socket-kernel.generated.js +1 -1
- package/dist/shell/stdin-adapter.d.ts +11 -0
- package/dist/shell/stdin-adapter.d.ts.map +1 -0
- package/dist/shell/stdin-adapter.js +59 -0
- package/dist/shell/unix-commands.d.ts +2 -1
- package/dist/shell/unix-commands.d.ts.map +1 -1
- package/dist/shell/unix-commands.js +1078 -50
- package/dist/substrate/lifo/commands/io/dd.js +1 -1
- package/dist/substrate/lifo/commands/net/curl.d.ts.map +1 -1
- package/dist/substrate/lifo/commands/net/curl.js +270 -54
- package/dist/substrate/lifo/commands/system/npm.d.ts +18 -1
- package/dist/substrate/lifo/commands/system/npm.d.ts.map +1 -1
- package/dist/substrate/lifo/commands/system/npm.js +26 -43
- package/dist/substrate/lifo/commands/text/head.d.ts.map +1 -1
- package/dist/substrate/lifo/commands/text/head.js +2 -1
- package/dist/substrate/lifo/commands/text/sed.d.ts.map +1 -1
- package/dist/substrate/lifo/commands/text/sed.js +499 -117
- package/dist/substrate/lifo/commands/types.d.ts +8 -4
- package/dist/substrate/lifo/commands/types.d.ts.map +1 -1
- package/dist/substrate/lifo/node-compat/zlib.d.ts +37 -18
- package/dist/substrate/lifo/node-compat/zlib.d.ts.map +1 -1
- package/dist/substrate/lifo/node-compat/zlib.js +122 -23
- package/dist/substrate/lifo/shell/interpreter.d.ts +9 -1
- package/dist/substrate/lifo/shell/interpreter.d.ts.map +1 -1
- package/dist/substrate/lifo/shell/interpreter.js +79 -29
- package/dist/substrate/lifo/shell/pipe.d.ts +16 -0
- package/dist/substrate/lifo/shell/pipe.d.ts.map +1 -1
- package/dist/substrate/lifo/shell/pipe.js +62 -18
- package/dist/substrate/lifo/shell/terminal-stdin.d.ts +20 -3
- package/dist/substrate/lifo/shell/terminal-stdin.d.ts.map +1 -1
- package/dist/substrate/lifo/shell/terminal-stdin.js +60 -24
- package/dist/vfs/seed-project.d.ts.map +1 -1
- package/dist/vfs/seed-project.js +1 -1
- package/dist/vfs/sqlite-vfs.d.ts +21 -30
- package/dist/vfs/sqlite-vfs.d.ts.map +1 -1
- package/dist/vfs/sqlite-vfs.js +113 -29
- package/dist/workspace/nimbus-workspace.d.ts +15 -0
- package/dist/workspace/nimbus-workspace.d.ts.map +1 -1
- package/dist/workspace/nimbus-workspace.js +20 -3
- package/dist/workspace/supervisor-op.d.ts +23 -0
- package/dist/workspace/supervisor-op.d.ts.map +1 -0
- package/dist/workspace/supervisor-op.js +92 -0
- package/package.json +3 -2
- package/src/_shared/byte-stream.ts +5 -4
- package/src/_shared/cache-stats.ts +27 -1
- package/src/_shared/exports-resolver.ts +1 -1
- package/src/_shared/real-node-imports.ts +8 -0
- package/src/_shared/retry.ts +1 -1
- package/src/_shared/tarball.ts +56 -5
- package/src/_shared/vfs-write-ledger.ts +22 -16
- package/src/constants.ts +30 -60
- package/src/runtime/assets-loader.ts +1 -1
- package/src/runtime/comment-strip.ts +42 -23
- package/src/runtime/esbuild-service.ts +566 -217
- package/src/runtime/javascript-ast.ts +40 -9
- package/src/runtime/opentui-wasm-backend.ts +19 -17
- package/src/runtime/port-registry.ts +66 -8
- package/src/runtime/virtual-socket-kernel.generated.ts +1 -1
- package/src/shell/stdin-adapter.ts +58 -0
- package/src/shell/unix-commands.ts +1054 -50
- package/src/substrate/lifo/commands/io/dd.ts +2 -2
- package/src/substrate/lifo/commands/net/curl.ts +310 -58
- package/src/substrate/lifo/commands/system/npm.ts +58 -38
- package/src/substrate/lifo/commands/text/head.ts +2 -1
- package/src/substrate/lifo/commands/text/sed.ts +519 -109
- package/src/substrate/lifo/commands/types.ts +8 -5
- package/src/substrate/lifo/node-compat/zlib.ts +155 -26
- package/src/substrate/lifo/shell/interpreter.ts +74 -27
- package/src/substrate/lifo/shell/pipe.ts +65 -24
- package/src/substrate/lifo/shell/terminal-stdin.ts +66 -30
- package/src/vfs/seed-project.ts +3 -3
- package/src/vfs/sqlite-vfs.ts +128 -64
- package/src/workspace/nimbus-workspace.ts +26 -2
- package/src/workspace/supervisor-op.ts +117 -0
- package/dist/_shared/install-phase.d.ts +0 -47
- package/dist/_shared/install-phase.d.ts.map +0 -1
- package/dist/_shared/install-phase.js +0 -1
- package/dist/_shared/rpc-dispose.d.ts +0 -4
- package/dist/_shared/rpc-dispose.d.ts.map +0 -1
- package/dist/_shared/rpc-dispose.js +0 -30
- package/dist/_shared/w7-frame.d.ts +0 -79
- package/dist/_shared/w7-frame.d.ts.map +0 -1
- package/dist/_shared/w7-frame.js +0 -840
- package/dist/_shared/weighted-credit-pool.d.ts +0 -61
- package/dist/_shared/weighted-credit-pool.d.ts.map +0 -1
- package/dist/_shared/weighted-credit-pool.js +0 -196
- package/dist/observability/diag-counters.d.ts +0 -236
- package/dist/observability/diag-counters.d.ts.map +0 -1
- package/dist/observability/diag-counters.js +0 -195
- package/dist/observability/heap-estimate.d.ts +0 -225
- package/dist/observability/heap-estimate.d.ts.map +0 -1
- package/dist/observability/heap-estimate.js +0 -185
- package/dist/observability/heavy-alloc-coord.d.ts +0 -93
- package/dist/observability/heavy-alloc-coord.d.ts.map +0 -1
- package/dist/observability/heavy-alloc-coord.js +0 -181
- package/dist/observability/oom-classify.d.ts +0 -138
- package/dist/observability/oom-classify.d.ts.map +0 -1
- package/dist/observability/oom-classify.js +0 -268
- package/dist/observability/oom-discriminator.d.ts +0 -176
- package/dist/observability/oom-discriminator.d.ts.map +0 -1
- package/dist/observability/oom-discriminator.js +0 -272
- package/src/_shared/install-phase.ts +0 -56
- package/src/_shared/rpc-dispose.ts +0 -31
- package/src/_shared/w7-frame.ts +0 -1013
- package/src/_shared/weighted-credit-pool.ts +0 -244
- package/src/observability/diag-counters.ts +0 -343
- package/src/observability/heap-estimate.ts +0 -331
- package/src/observability/heavy-alloc-coord.ts +0 -241
- package/src/observability/oom-classify.ts +0 -260
- package/src/observability/oom-discriminator.ts +0 -405
|
@@ -3,9 +3,8 @@ import type { VfsCred } from '../../../runtime/os-contracts.js';
|
|
|
3
3
|
export interface CommandOutputStream {
|
|
4
4
|
write(text: string): void;
|
|
5
5
|
/**
|
|
6
|
-
* Present on sinks that store bytes verbatim
|
|
7
|
-
*
|
|
8
|
-
* they have no way to carry a byte that is not text.
|
|
6
|
+
* Present on sinks that store bytes verbatim — files, `/dev/null`, and
|
|
7
|
+
* byte-capable shell pipes. Sinks without it take decoded text instead.
|
|
9
8
|
*/
|
|
10
9
|
writeBytes?(bytes: Uint8Array): void;
|
|
11
10
|
/**
|
|
@@ -20,7 +19,12 @@ export interface CommandInputStream {
|
|
|
20
19
|
read(): Promise<string | null>;
|
|
21
20
|
readAll(): Promise<string>;
|
|
22
21
|
readLine?(): Promise<string | null>;
|
|
23
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Bounded raw-byte read. Byte-capable sources (shell pipes, dumps) return
|
|
24
|
+
* the original bytes; text-only sources encode what they hold. Null means
|
|
25
|
+
* EOF with nothing returned.
|
|
26
|
+
*/
|
|
27
|
+
readBytes?(maxLength: number): Promise<Uint8Array | null>;
|
|
24
28
|
}
|
|
25
29
|
export interface TerminalInputStream extends CommandInputStream {
|
|
26
30
|
rawMode: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/substrate/lifo/commands/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAEhE,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/substrate/lifo/commands/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAEhE,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B;;;OAGG;IACH,UAAU,CAAC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AAC,CAAC;IACtD,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,MAAM,gBAAgB,GAAG,CAC7B,MAAM,EAAE,cAAc,EACtB,IAAI,EAAE,OAAO,EACb,IAAI,EAAE,MAAM,EAAE,KACX,OAAO,CAAC,MAAM,CAAC,CAAC;AAErB,MAAM,MAAM,OAAO,GAAG,CAAC,GAAG,EAAE,cAAc,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -1,16 +1,32 @@
|
|
|
1
1
|
import { Buffer } from './buffer.js';
|
|
2
2
|
type ZlibCallback = (err: Error | null, result?: Buffer) => void;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Node's async surface: the callback is required, with options optional in
|
|
5
|
+
* front of it. There is no promise return to fall back on.
|
|
6
|
+
*/
|
|
7
|
+
interface ZlibAsync {
|
|
8
|
+
(data: ZlibInput, callback: ZlibCallback): void;
|
|
9
|
+
(data: ZlibInput, options: object, callback: ZlibCallback): void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Everything a zlib entry point accepts: strings encode to UTF-8;
|
|
13
|
+
* ArrayBuffers and every ArrayBufferView carry their own bytes.
|
|
14
|
+
*/
|
|
15
|
+
type ZlibInput = string | ArrayBufferView | ArrayBuffer;
|
|
16
|
+
export declare const gzip: ZlibAsync;
|
|
17
|
+
export declare const gunzip: ZlibAsync;
|
|
18
|
+
export declare const deflate: ZlibAsync;
|
|
19
|
+
export declare const inflate: ZlibAsync;
|
|
20
|
+
export declare const deflateRaw: ZlibAsync;
|
|
21
|
+
export declare const inflateRaw: ZlibAsync;
|
|
22
|
+
export declare const unzip: ZlibAsync;
|
|
23
|
+
export declare function gzipSync(buffer?: ZlibInput, options?: object): never;
|
|
24
|
+
export declare function gunzipSync(buffer?: ZlibInput, options?: object): never;
|
|
25
|
+
export declare function deflateSync(buffer?: ZlibInput, options?: object): never;
|
|
26
|
+
export declare function inflateSync(buffer?: ZlibInput, options?: object): never;
|
|
27
|
+
export declare function deflateRawSync(buffer?: ZlibInput, options?: object): never;
|
|
28
|
+
export declare function inflateRawSync(buffer?: ZlibInput, options?: object): never;
|
|
29
|
+
export declare function unzipSync(buffer?: ZlibInput, options?: object): never;
|
|
14
30
|
export declare const constants: {
|
|
15
31
|
Z_NO_FLUSH: number;
|
|
16
32
|
Z_PARTIAL_FLUSH: number;
|
|
@@ -31,17 +47,20 @@ export declare const constants: {
|
|
|
31
47
|
Z_DEFAULT_COMPRESSION: number;
|
|
32
48
|
};
|
|
33
49
|
declare const _default: {
|
|
34
|
-
gzip:
|
|
35
|
-
gunzip:
|
|
36
|
-
deflate:
|
|
37
|
-
inflate:
|
|
38
|
-
deflateRaw:
|
|
39
|
-
inflateRaw:
|
|
40
|
-
unzip:
|
|
50
|
+
gzip: ZlibAsync;
|
|
51
|
+
gunzip: ZlibAsync;
|
|
52
|
+
deflate: ZlibAsync;
|
|
53
|
+
inflate: ZlibAsync;
|
|
54
|
+
deflateRaw: ZlibAsync;
|
|
55
|
+
inflateRaw: ZlibAsync;
|
|
56
|
+
unzip: ZlibAsync;
|
|
41
57
|
gzipSync: typeof gzipSync;
|
|
42
58
|
gunzipSync: typeof gunzipSync;
|
|
43
59
|
deflateSync: typeof deflateSync;
|
|
44
60
|
inflateSync: typeof inflateSync;
|
|
61
|
+
deflateRawSync: typeof deflateRawSync;
|
|
62
|
+
inflateRawSync: typeof inflateRawSync;
|
|
63
|
+
unzipSync: typeof unzipSync;
|
|
45
64
|
constants: {
|
|
46
65
|
Z_NO_FLUSH: number;
|
|
47
66
|
Z_PARTIAL_FLUSH: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zlib.d.ts","sourceRoot":"","sources":["../../../../src/substrate/lifo/node-compat/zlib.ts"],"names":[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C,EAAE,MAAM,GAAG,KAAK,CAEvE;AACD,wBAAgB,WAAW,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,CAEvE;AACD,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,CAE1E;AACD,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,CAE1E;AACD,wBAAgB,SAAS,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,CAErE;AAED,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;CAkBrB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEF,wBAKE"}
|
|
@@ -1,18 +1,90 @@
|
|
|
1
1
|
import { Buffer } from './buffer.js';
|
|
2
|
+
/**
|
|
3
|
+
* One funnel for every entry point. The result views the caller's exact
|
|
4
|
+
* byte region — byteOffset and byteLength preserved, element values never
|
|
5
|
+
* reinterpreted — so sniffing and the codec see identical bytes for a
|
|
6
|
+
* Uint8Array, a Uint16Array, an offset DataView, or a bare ArrayBuffer.
|
|
7
|
+
*/
|
|
8
|
+
function toBytes(data) {
|
|
9
|
+
if (typeof data === 'string')
|
|
10
|
+
return new TextEncoder().encode(data);
|
|
11
|
+
if (data instanceof Uint8Array)
|
|
12
|
+
return data;
|
|
13
|
+
if (ArrayBuffer.isView(data)) {
|
|
14
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
15
|
+
}
|
|
16
|
+
return new Uint8Array(data);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Node splits decompression failures two ways, and the engine's own failure
|
|
20
|
+
* is the only thing that can tell them apart: an input that ran out is
|
|
21
|
+
* Z_BUF_ERROR / errno -5, while everything else — bad header, bad block, and
|
|
22
|
+
* a checksum or length trailer that can only fail once the member is
|
|
23
|
+
* complete — is Z_DATA_ERROR / errno -3 carrying the engine's message. Which
|
|
24
|
+
* side of a write or a close the failure lands on says nothing about that,
|
|
25
|
+
* so it is not consulted.
|
|
26
|
+
*/
|
|
27
|
+
function isUnexpectedEnd(cause) {
|
|
28
|
+
const message = cause instanceof Error && typeof cause.message === 'string' ? cause.message : String(cause);
|
|
29
|
+
return /unexpected end|end of (?:file|input|stream)|premature|truncated|\bEOF\b/i.test(message);
|
|
30
|
+
}
|
|
31
|
+
function zDataError(cause) {
|
|
32
|
+
const message = cause instanceof Error && cause.message ? cause.message : String(cause);
|
|
33
|
+
return Object.assign(new Error(message), { code: 'Z_DATA_ERROR', errno: -3, cause });
|
|
34
|
+
}
|
|
35
|
+
function zBufError(cause) {
|
|
36
|
+
return Object.assign(new Error('unexpected end of file'), {
|
|
37
|
+
code: 'Z_BUF_ERROR',
|
|
38
|
+
errno: -5,
|
|
39
|
+
cause,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Node throws this synchronously rather than deferring a callback that does
|
|
44
|
+
* not exist.
|
|
45
|
+
*/
|
|
46
|
+
function invalidCallback(value) {
|
|
47
|
+
const received = value === undefined ? 'undefined'
|
|
48
|
+
: value === null ? 'null'
|
|
49
|
+
: typeof value === 'object' ? `an instance of ${value.constructor?.name ?? 'Object'}`
|
|
50
|
+
: `type ${typeof value} (${String(value)})`;
|
|
51
|
+
return Object.assign(new TypeError(`The "callback" argument must be of type function. Received ${received}`), { code: 'ERR_INVALID_ARG_TYPE' });
|
|
52
|
+
}
|
|
2
53
|
async function processStream(data, format, type) {
|
|
3
54
|
const stream = type === 'compress'
|
|
4
55
|
? new CompressionStream(format)
|
|
5
56
|
: new DecompressionStream(format);
|
|
6
57
|
const writer = stream.writable.getWriter();
|
|
7
|
-
writer.write(data);
|
|
8
|
-
writer.close();
|
|
9
58
|
const reader = stream.readable.getReader();
|
|
10
59
|
const chunks = [];
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
60
|
+
// Feeding and draining run together: a single write large enough to fill
|
|
61
|
+
// the codec's output queue only completes while somebody reads. Both sides
|
|
62
|
+
// are contained so neither rejection surfaces unhandled, and the first
|
|
63
|
+
// failure is the one reported.
|
|
64
|
+
const failures = [];
|
|
65
|
+
const record = (reason) => {
|
|
66
|
+
if (failures.length === 0)
|
|
67
|
+
failures.push(reason);
|
|
68
|
+
};
|
|
69
|
+
const drain = (async () => {
|
|
70
|
+
for (;;) {
|
|
71
|
+
const { done, value } = await reader.read();
|
|
72
|
+
if (done)
|
|
73
|
+
return;
|
|
74
|
+
chunks.push(value);
|
|
75
|
+
}
|
|
76
|
+
})().catch(record);
|
|
77
|
+
const feed = (async () => {
|
|
78
|
+
await writer.write(data);
|
|
79
|
+
await writer.close();
|
|
80
|
+
})().catch(record);
|
|
81
|
+
await Promise.all([drain, feed]);
|
|
82
|
+
if (failures.length > 0) {
|
|
83
|
+
const reason = failures[0];
|
|
84
|
+
if (type === 'decompress') {
|
|
85
|
+
throw isUnexpectedEnd(reason) ? zBufError(reason) : zDataError(reason);
|
|
86
|
+
}
|
|
87
|
+
throw reason instanceof Error ? reason : new Error(String(reason));
|
|
16
88
|
}
|
|
17
89
|
let totalLength = 0;
|
|
18
90
|
for (const c of chunks)
|
|
@@ -25,14 +97,22 @@ async function processStream(data, format, type) {
|
|
|
25
97
|
}
|
|
26
98
|
return result;
|
|
27
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Node's Unzip sniffs the wrapper itself: the gzip magic bytes mean gunzip,
|
|
102
|
+
* anything else is treated as zlib-wrapped deflate.
|
|
103
|
+
*/
|
|
104
|
+
function looksLikeGzip(data) {
|
|
105
|
+
return data.length >= 2 && data[0] === 0x1f && data[1] === 0x8b;
|
|
106
|
+
}
|
|
28
107
|
function wrapAsync(format, type) {
|
|
29
108
|
return function (data, optionsOrCb, cb) {
|
|
30
109
|
const callback = typeof optionsOrCb === 'function' ? optionsOrCb : cb;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
110
|
+
if (typeof callback !== 'function')
|
|
111
|
+
throw invalidCallback(callback);
|
|
112
|
+
const bytes = toBytes(data);
|
|
113
|
+
// Two arms, not .then().catch(): a callback that throws on success must
|
|
114
|
+
// not be handed its own exception as a second, failed invocation.
|
|
115
|
+
processStream(bytes, typeof format === 'function' ? format(bytes) : format, type).then((result) => callback(null, result), (err) => callback(err instanceof Error ? err : new Error(String(err))));
|
|
36
116
|
};
|
|
37
117
|
}
|
|
38
118
|
export const gzip = wrapAsync('gzip', 'compress');
|
|
@@ -41,19 +121,36 @@ export const deflate = wrapAsync('deflate', 'compress');
|
|
|
41
121
|
export const inflate = wrapAsync('deflate', 'decompress');
|
|
42
122
|
export const deflateRaw = wrapAsync('deflate-raw', 'compress');
|
|
43
123
|
export const inflateRaw = wrapAsync('deflate-raw', 'decompress');
|
|
44
|
-
export const unzip = wrapAsync('gzip', 'decompress');
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
124
|
+
export const unzip = wrapAsync((data) => (looksLikeGzip(data) ? 'gzip' : 'deflate'), 'decompress');
|
|
125
|
+
/**
|
|
126
|
+
* The Sync surface needs a synchronous compress primitive; browser-class
|
|
127
|
+
* runtimes only offer the async CompressionStream. Each Sync name refuses
|
|
128
|
+
* with the working async replacement spelled out instead of failing as a
|
|
129
|
+
* missing export or a vague "not supported".
|
|
130
|
+
*/
|
|
131
|
+
function syncUnavailable(name, asyncName) {
|
|
132
|
+
throw Object.assign(new Error(`zlib.${name}: synchronous compression is not available on this runtime. Use the async zlib.${asyncName}(data, callback) form instead.`), { code: 'ERR_ZLIB_SYNC_UNAVAILABLE' });
|
|
133
|
+
}
|
|
134
|
+
export function gzipSync(buffer, options) {
|
|
135
|
+
syncUnavailable('gzipSync', 'gzip');
|
|
136
|
+
}
|
|
137
|
+
export function gunzipSync(buffer, options) {
|
|
138
|
+
syncUnavailable('gunzipSync', 'gunzip');
|
|
139
|
+
}
|
|
140
|
+
export function deflateSync(buffer, options) {
|
|
141
|
+
syncUnavailable('deflateSync', 'deflate');
|
|
142
|
+
}
|
|
143
|
+
export function inflateSync(buffer, options) {
|
|
144
|
+
syncUnavailable('inflateSync', 'inflate');
|
|
48
145
|
}
|
|
49
|
-
export function
|
|
50
|
-
|
|
146
|
+
export function deflateRawSync(buffer, options) {
|
|
147
|
+
syncUnavailable('deflateRawSync', 'deflateRaw');
|
|
51
148
|
}
|
|
52
|
-
export function
|
|
53
|
-
|
|
149
|
+
export function inflateRawSync(buffer, options) {
|
|
150
|
+
syncUnavailable('inflateRawSync', 'inflateRaw');
|
|
54
151
|
}
|
|
55
|
-
export function
|
|
56
|
-
|
|
152
|
+
export function unzipSync(buffer, options) {
|
|
153
|
+
syncUnavailable('unzipSync', 'unzip');
|
|
57
154
|
}
|
|
58
155
|
export const constants = {
|
|
59
156
|
Z_NO_FLUSH: 0,
|
|
@@ -76,5 +173,7 @@ export const constants = {
|
|
|
76
173
|
};
|
|
77
174
|
export default {
|
|
78
175
|
gzip, gunzip, deflate, inflate, deflateRaw, inflateRaw, unzip,
|
|
79
|
-
gzipSync, gunzipSync, deflateSync, inflateSync,
|
|
176
|
+
gzipSync, gunzipSync, deflateSync, inflateSync,
|
|
177
|
+
deflateRawSync, inflateRawSync, unzipSync,
|
|
178
|
+
constants,
|
|
80
179
|
};
|
|
@@ -241,8 +241,16 @@ export declare class Interpreter {
|
|
|
241
241
|
*/
|
|
242
242
|
private withFdFlush;
|
|
243
243
|
private flushFds;
|
|
244
|
+
/**
|
|
245
|
+
* Byte-faithful redirected input: bounded range reads keep >64 KiB
|
|
246
|
+
* redirections intact and preserve bytes that are not valid UTF-8, while
|
|
247
|
+
* the text view still decodes progressively across chunk boundaries.
|
|
248
|
+
*
|
|
249
|
+
* Only a zero-length range means EOF. Devices and some mounts answer with
|
|
250
|
+
* fewer bytes than asked whenever their internal bound is hit; those short
|
|
251
|
+
* nonempty reads advance the offset and continue, exactly like read(2).
|
|
252
|
+
*/
|
|
244
253
|
private createFileReader;
|
|
245
|
-
private createStringReader;
|
|
246
254
|
private resolveOutputFd;
|
|
247
255
|
private resolveInputFd;
|
|
248
256
|
private parseFdTarget;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interpreter.d.ts","sourceRoot":"","sources":["../../../../src/substrate/lifo/shell/interpreter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAgBX,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EAElB,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAGhE,OAAO,EAEe,KAAK,eAAe,EACzC,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"interpreter.d.ts","sourceRoot":"","sources":["../../../../src/substrate/lifo/shell/interpreter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAgBX,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EAElB,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAGhE,OAAO,EAEe,K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AC,WAAW;IAYnB,OAAO,CAAC,UAAU;IAYlB,OAAO,CAAC,gBAAgB;IAqCxB,OAAO,CAAC,eAAe;IA4BvB;;;;;;;;;;;;;;OAcG;IACH,OAAO,CAAC,gBAAgB;IA+BxB;;;;;OAKG;YACW,WAAW;IAQzB,OAAO,CAAC,QAAQ;IAIhB;;;;;;;;OAQG;IACH,OAAO,CAAC,gBAAgB;IAkExB,OAAO,CAAC,eAAe;IAYvB,OAAO,CAAC,cAAc;IAWtB,OAAO,CAAC,aAAa;IAKrB,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,YAAY;IAKpB,OAAO,CAAC,cAAc;YAQR,qBAAqB;IASnC,OAAO,CAAC,aAAa;CAItB"}
|
|
@@ -7,6 +7,7 @@ import { exitCodeForAbortSignal } from './signals.js';
|
|
|
7
7
|
import { resolve } from '../utils/path.js';
|
|
8
8
|
import { encode } from '../utils/encoding.js';
|
|
9
9
|
import { globMatch } from '../utils/glob.js';
|
|
10
|
+
import { staticStdinReader } from '../../../shell/stdin-adapter.js';
|
|
10
11
|
/**
|
|
11
12
|
* Bytes a file-backed descriptor holds before committing. Matches the stream
|
|
12
13
|
* chunk size used elsewhere and keeps a line-at-a-time producer from paying a
|
|
@@ -1136,7 +1137,7 @@ export class Interpreter {
|
|
|
1136
1137
|
const body = heredoc.quoted
|
|
1137
1138
|
? heredoc.body
|
|
1138
1139
|
: await expandWord([{ text: heredoc.body, quoted: 'double' }], expandCtx);
|
|
1139
|
-
this.setInputFd(fds, redir.fd ?? 0, { stream:
|
|
1140
|
+
this.setInputFd(fds, redir.fd ?? 0, { stream: staticStdinReader(body), terminal: false });
|
|
1140
1141
|
continue;
|
|
1141
1142
|
}
|
|
1142
1143
|
const target = await expandWord(redir.target, expandCtx);
|
|
@@ -1275,11 +1276,17 @@ export class Interpreter {
|
|
|
1275
1276
|
}
|
|
1276
1277
|
if (target === '/dev/stdin')
|
|
1277
1278
|
return this.resolveInputFd('0', fds.inputFds, fds.terminalInputFds);
|
|
1279
|
+
const targetPath = resolve(this.config.getCwd(), target);
|
|
1280
|
+
const vfs = io.vfs ?? this.config.vfs;
|
|
1278
1281
|
try {
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1282
|
+
// Open-authorize before the command runs, the way open(2) would: a
|
|
1283
|
+
// missing, unreadable, or directory target fails the redirection even
|
|
1284
|
+
// when the command never reads a byte.
|
|
1285
|
+
if (vfs.stat(targetPath).type === 'directory') {
|
|
1286
|
+
throw Object.assign(new Error(`EISDIR: ${targetPath}`), { code: 'EISDIR' });
|
|
1287
|
+
}
|
|
1288
|
+
vfs.access(targetPath, 0o4);
|
|
1289
|
+
return { stream: this.createFileReader(vfs, targetPath), terminal: false };
|
|
1283
1290
|
}
|
|
1284
1291
|
catch (error) {
|
|
1285
1292
|
throw new RedirectionOpenError(target, error);
|
|
@@ -1347,39 +1354,82 @@ export class Interpreter {
|
|
|
1347
1354
|
for (const stream of fds.outputFds.values())
|
|
1348
1355
|
stream.flush?.();
|
|
1349
1356
|
}
|
|
1357
|
+
/**
|
|
1358
|
+
* Byte-faithful redirected input: bounded range reads keep >64 KiB
|
|
1359
|
+
* redirections intact and preserve bytes that are not valid UTF-8, while
|
|
1360
|
+
* the text view still decodes progressively across chunk boundaries.
|
|
1361
|
+
*
|
|
1362
|
+
* Only a zero-length range means EOF. Devices and some mounts answer with
|
|
1363
|
+
* fewer bytes than asked whenever their internal bound is hit; those short
|
|
1364
|
+
* nonempty reads advance the offset and continue, exactly like read(2).
|
|
1365
|
+
*/
|
|
1350
1366
|
createFileReader(vfs, path) {
|
|
1351
|
-
const
|
|
1352
|
-
return this.createStringReader(content);
|
|
1353
|
-
}
|
|
1354
|
-
createStringReader(content) {
|
|
1367
|
+
const decoder = new TextDecoder('utf-8');
|
|
1355
1368
|
let offset = 0;
|
|
1369
|
+
let eof = false;
|
|
1370
|
+
const pull = (max) => {
|
|
1371
|
+
if (eof)
|
|
1372
|
+
return null;
|
|
1373
|
+
const chunk = vfs.readRange(path, offset, max);
|
|
1374
|
+
if (chunk.length === 0) {
|
|
1375
|
+
eof = true;
|
|
1376
|
+
return null;
|
|
1377
|
+
}
|
|
1378
|
+
offset += chunk.length;
|
|
1379
|
+
return chunk;
|
|
1380
|
+
};
|
|
1356
1381
|
return {
|
|
1382
|
+
readBytes: async (maxLength) => {
|
|
1383
|
+
if (maxLength <= 0)
|
|
1384
|
+
return new Uint8Array(0);
|
|
1385
|
+
return pull(maxLength);
|
|
1386
|
+
},
|
|
1357
1387
|
read: async () => {
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1388
|
+
while (true) {
|
|
1389
|
+
const bytes = pull(65536);
|
|
1390
|
+
if (bytes === null) {
|
|
1391
|
+
const tail = decoder.decode();
|
|
1392
|
+
return tail.length > 0 ? tail : null;
|
|
1393
|
+
}
|
|
1394
|
+
const text = decoder.decode(bytes, { stream: true });
|
|
1395
|
+
if (text.length > 0)
|
|
1396
|
+
return text;
|
|
1397
|
+
}
|
|
1363
1398
|
},
|
|
1364
1399
|
readAll: async () => {
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1400
|
+
let out = '';
|
|
1401
|
+
while (true) {
|
|
1402
|
+
const bytes = pull(65536);
|
|
1403
|
+
if (bytes === null)
|
|
1404
|
+
break;
|
|
1405
|
+
out += decoder.decode(bytes, { stream: true });
|
|
1406
|
+
}
|
|
1407
|
+
out += decoder.decode();
|
|
1408
|
+
return out;
|
|
1370
1409
|
},
|
|
1371
1410
|
readLine: async () => {
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1411
|
+
let line = '';
|
|
1412
|
+
let sawAny = false;
|
|
1413
|
+
while (true) {
|
|
1414
|
+
const bytes = pull(65536);
|
|
1415
|
+
if (bytes === null)
|
|
1416
|
+
break;
|
|
1417
|
+
sawAny = true;
|
|
1418
|
+
// Split on the raw 0x0A byte so pushback returns ORIGINAL bytes;
|
|
1419
|
+
// decoded-text pushback would corrupt multibyte sequences that
|
|
1420
|
+
// straddle the chunk boundary or mis-measure invalid UTF-8.
|
|
1421
|
+
const newline = bytes.indexOf(0x0a);
|
|
1422
|
+
if (newline >= 0) {
|
|
1423
|
+
offset -= bytes.length - (newline + 1);
|
|
1424
|
+
eof = false;
|
|
1425
|
+
line += decoder.decode(bytes.subarray(0, newline), { stream: true });
|
|
1426
|
+
const flushed = decoder.decode();
|
|
1427
|
+
return line + flushed;
|
|
1428
|
+
}
|
|
1429
|
+
line += decoder.decode(bytes, { stream: true });
|
|
1379
1430
|
}
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
return line;
|
|
1431
|
+
line += decoder.decode();
|
|
1432
|
+
return sawAny || line.length > 0 ? line : null;
|
|
1383
1433
|
},
|
|
1384
1434
|
};
|
|
1385
1435
|
}
|
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
import type { CommandOutputStream, CommandInputStream } from '../commands/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* A shell pipe that carries the producer's exact bytes. Text writes are
|
|
4
|
+
* encoded once at the write side, `writeBytes` stores bytes verbatim, and
|
|
5
|
+
* the text view (`read`/`readAll`/`readLine`) decodes progressively so a
|
|
6
|
+
* multi-byte UTF-8 sequence split across chunks survives intact.
|
|
7
|
+
*/
|
|
2
8
|
export declare class PipeChannel {
|
|
3
9
|
private buffer;
|
|
4
10
|
private closed;
|
|
5
11
|
private waiting;
|
|
12
|
+
private decoder;
|
|
6
13
|
readonly writer: CommandOutputStream;
|
|
7
14
|
readonly reader: CommandInputStream;
|
|
15
|
+
/** Next queued chunk, a waiter's delivery, or null once closed and empty. */
|
|
16
|
+
private pull;
|
|
8
17
|
private read;
|
|
9
18
|
private readAll;
|
|
10
19
|
private readLine;
|
|
20
|
+
/**
|
|
21
|
+
* Bounded byte read: returns whatever the producer has already delivered,
|
|
22
|
+
* capped at maxLength. maxLength bounds the result, it is never a fill
|
|
23
|
+
* target — waiting to complete it would stall every consumer downstream of
|
|
24
|
+
* a live open producer. A larger chunk keeps only its first maxLength
|
|
25
|
+
* bytes; the remainder stays queued in original order.
|
|
26
|
+
*/
|
|
11
27
|
private readBytes;
|
|
12
28
|
close(): void;
|
|
13
29
|
private deliver;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipe.d.ts","sourceRoot":"","sources":["../../../../src/substrate/lifo/shell/pipe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"pipe.d.ts","sourceRoot":"","sources":["../../../../src/substrate/lifo/shell/pipe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAGpF;;;;;GAKG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAiD;IAChE,OAAO,CAAC,OAAO,CAA4B;IAE3C,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CASlC;IAEF,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAKjC;IAEF,6EAA6E;IAC7E,OAAO,CAAC,IAAI;YAYE,IAAI;YAYJ,OAAO;YAUP,QAAQ;IA0BtB;;;;;;OAMG;YACW,SAAS;IAUvB,KAAK,IAAI,IAAI;IAQb,OAAO,CAAC,OAAO;CAahB"}
|