@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.
Files changed (145) hide show
  1. package/README.md +47 -26
  2. package/dist/_shared/byte-stream.d.ts +5 -4
  3. package/dist/_shared/byte-stream.d.ts.map +1 -1
  4. package/dist/_shared/cache-stats.d.ts +23 -1
  5. package/dist/_shared/cache-stats.d.ts.map +1 -1
  6. package/dist/_shared/cache-stats.js +13 -1
  7. package/dist/_shared/exports-resolver.d.ts +1 -1
  8. package/dist/_shared/exports-resolver.js +1 -1
  9. package/dist/_shared/real-node-imports.d.ts +7 -0
  10. package/dist/_shared/real-node-imports.d.ts.map +1 -1
  11. package/dist/_shared/real-node-imports.js +8 -0
  12. package/dist/_shared/retry.js +1 -1
  13. package/dist/_shared/tarball.d.ts +23 -5
  14. package/dist/_shared/tarball.d.ts.map +1 -1
  15. package/dist/_shared/tarball.js +38 -5
  16. package/dist/_shared/vfs-write-ledger.d.ts.map +1 -1
  17. package/dist/_shared/vfs-write-ledger.js +22 -16
  18. package/dist/constants.d.ts +5 -11
  19. package/dist/constants.d.ts.map +1 -1
  20. package/dist/constants.js +16 -56
  21. package/dist/runtime/assets-loader.js +1 -1
  22. package/dist/runtime/comment-strip.d.ts +0 -35
  23. package/dist/runtime/comment-strip.d.ts.map +1 -1
  24. package/dist/runtime/comment-strip.js +48 -20
  25. package/dist/runtime/esbuild-service.d.ts +38 -42
  26. package/dist/runtime/esbuild-service.d.ts.map +1 -1
  27. package/dist/runtime/esbuild-service.js +494 -197
  28. package/dist/runtime/javascript-ast.d.ts.map +1 -1
  29. package/dist/runtime/javascript-ast.js +45 -7
  30. package/dist/runtime/opentui-wasm-backend.d.ts.map +1 -1
  31. package/dist/runtime/opentui-wasm-backend.js +18 -16
  32. package/dist/runtime/port-registry.d.ts +4 -2
  33. package/dist/runtime/port-registry.d.ts.map +1 -1
  34. package/dist/runtime/port-registry.js +60 -8
  35. package/dist/runtime/virtual-socket-kernel.generated.d.ts +1 -1
  36. package/dist/runtime/virtual-socket-kernel.generated.js +1 -1
  37. package/dist/shell/stdin-adapter.d.ts +11 -0
  38. package/dist/shell/stdin-adapter.d.ts.map +1 -0
  39. package/dist/shell/stdin-adapter.js +59 -0
  40. package/dist/shell/unix-commands.d.ts +2 -1
  41. package/dist/shell/unix-commands.d.ts.map +1 -1
  42. package/dist/shell/unix-commands.js +1078 -50
  43. package/dist/substrate/lifo/commands/io/dd.js +1 -1
  44. package/dist/substrate/lifo/commands/net/curl.d.ts.map +1 -1
  45. package/dist/substrate/lifo/commands/net/curl.js +270 -54
  46. package/dist/substrate/lifo/commands/system/npm.d.ts +18 -1
  47. package/dist/substrate/lifo/commands/system/npm.d.ts.map +1 -1
  48. package/dist/substrate/lifo/commands/system/npm.js +26 -43
  49. package/dist/substrate/lifo/commands/text/head.d.ts.map +1 -1
  50. package/dist/substrate/lifo/commands/text/head.js +2 -1
  51. package/dist/substrate/lifo/commands/text/sed.d.ts.map +1 -1
  52. package/dist/substrate/lifo/commands/text/sed.js +499 -117
  53. package/dist/substrate/lifo/commands/types.d.ts +8 -4
  54. package/dist/substrate/lifo/commands/types.d.ts.map +1 -1
  55. package/dist/substrate/lifo/node-compat/zlib.d.ts +37 -18
  56. package/dist/substrate/lifo/node-compat/zlib.d.ts.map +1 -1
  57. package/dist/substrate/lifo/node-compat/zlib.js +122 -23
  58. package/dist/substrate/lifo/shell/interpreter.d.ts +9 -1
  59. package/dist/substrate/lifo/shell/interpreter.d.ts.map +1 -1
  60. package/dist/substrate/lifo/shell/interpreter.js +79 -29
  61. package/dist/substrate/lifo/shell/pipe.d.ts +16 -0
  62. package/dist/substrate/lifo/shell/pipe.d.ts.map +1 -1
  63. package/dist/substrate/lifo/shell/pipe.js +62 -18
  64. package/dist/substrate/lifo/shell/terminal-stdin.d.ts +20 -3
  65. package/dist/substrate/lifo/shell/terminal-stdin.d.ts.map +1 -1
  66. package/dist/substrate/lifo/shell/terminal-stdin.js +60 -24
  67. package/dist/vfs/seed-project.d.ts.map +1 -1
  68. package/dist/vfs/seed-project.js +1 -1
  69. package/dist/vfs/sqlite-vfs.d.ts +21 -30
  70. package/dist/vfs/sqlite-vfs.d.ts.map +1 -1
  71. package/dist/vfs/sqlite-vfs.js +113 -29
  72. package/dist/workspace/nimbus-workspace.d.ts +15 -0
  73. package/dist/workspace/nimbus-workspace.d.ts.map +1 -1
  74. package/dist/workspace/nimbus-workspace.js +20 -3
  75. package/dist/workspace/supervisor-op.d.ts +23 -0
  76. package/dist/workspace/supervisor-op.d.ts.map +1 -0
  77. package/dist/workspace/supervisor-op.js +92 -0
  78. package/package.json +3 -2
  79. package/src/_shared/byte-stream.ts +5 -4
  80. package/src/_shared/cache-stats.ts +27 -1
  81. package/src/_shared/exports-resolver.ts +1 -1
  82. package/src/_shared/real-node-imports.ts +8 -0
  83. package/src/_shared/retry.ts +1 -1
  84. package/src/_shared/tarball.ts +56 -5
  85. package/src/_shared/vfs-write-ledger.ts +22 -16
  86. package/src/constants.ts +30 -60
  87. package/src/runtime/assets-loader.ts +1 -1
  88. package/src/runtime/comment-strip.ts +42 -23
  89. package/src/runtime/esbuild-service.ts +566 -217
  90. package/src/runtime/javascript-ast.ts +40 -9
  91. package/src/runtime/opentui-wasm-backend.ts +19 -17
  92. package/src/runtime/port-registry.ts +66 -8
  93. package/src/runtime/virtual-socket-kernel.generated.ts +1 -1
  94. package/src/shell/stdin-adapter.ts +58 -0
  95. package/src/shell/unix-commands.ts +1054 -50
  96. package/src/substrate/lifo/commands/io/dd.ts +2 -2
  97. package/src/substrate/lifo/commands/net/curl.ts +310 -58
  98. package/src/substrate/lifo/commands/system/npm.ts +58 -38
  99. package/src/substrate/lifo/commands/text/head.ts +2 -1
  100. package/src/substrate/lifo/commands/text/sed.ts +519 -109
  101. package/src/substrate/lifo/commands/types.ts +8 -5
  102. package/src/substrate/lifo/node-compat/zlib.ts +155 -26
  103. package/src/substrate/lifo/shell/interpreter.ts +74 -27
  104. package/src/substrate/lifo/shell/pipe.ts +65 -24
  105. package/src/substrate/lifo/shell/terminal-stdin.ts +66 -30
  106. package/src/vfs/seed-project.ts +3 -3
  107. package/src/vfs/sqlite-vfs.ts +128 -64
  108. package/src/workspace/nimbus-workspace.ts +26 -2
  109. package/src/workspace/supervisor-op.ts +117 -0
  110. package/dist/_shared/install-phase.d.ts +0 -47
  111. package/dist/_shared/install-phase.d.ts.map +0 -1
  112. package/dist/_shared/install-phase.js +0 -1
  113. package/dist/_shared/rpc-dispose.d.ts +0 -4
  114. package/dist/_shared/rpc-dispose.d.ts.map +0 -1
  115. package/dist/_shared/rpc-dispose.js +0 -30
  116. package/dist/_shared/w7-frame.d.ts +0 -79
  117. package/dist/_shared/w7-frame.d.ts.map +0 -1
  118. package/dist/_shared/w7-frame.js +0 -840
  119. package/dist/_shared/weighted-credit-pool.d.ts +0 -61
  120. package/dist/_shared/weighted-credit-pool.d.ts.map +0 -1
  121. package/dist/_shared/weighted-credit-pool.js +0 -196
  122. package/dist/observability/diag-counters.d.ts +0 -236
  123. package/dist/observability/diag-counters.d.ts.map +0 -1
  124. package/dist/observability/diag-counters.js +0 -195
  125. package/dist/observability/heap-estimate.d.ts +0 -225
  126. package/dist/observability/heap-estimate.d.ts.map +0 -1
  127. package/dist/observability/heap-estimate.js +0 -185
  128. package/dist/observability/heavy-alloc-coord.d.ts +0 -93
  129. package/dist/observability/heavy-alloc-coord.d.ts.map +0 -1
  130. package/dist/observability/heavy-alloc-coord.js +0 -181
  131. package/dist/observability/oom-classify.d.ts +0 -138
  132. package/dist/observability/oom-classify.d.ts.map +0 -1
  133. package/dist/observability/oom-classify.js +0 -268
  134. package/dist/observability/oom-discriminator.d.ts +0 -176
  135. package/dist/observability/oom-discriminator.d.ts.map +0 -1
  136. package/dist/observability/oom-discriminator.js +0 -272
  137. package/src/_shared/install-phase.ts +0 -56
  138. package/src/_shared/rpc-dispose.ts +0 -31
  139. package/src/_shared/w7-frame.ts +0 -1013
  140. package/src/_shared/weighted-credit-pool.ts +0 -244
  141. package/src/observability/diag-counters.ts +0 -343
  142. package/src/observability/heap-estimate.ts +0 -331
  143. package/src/observability/heavy-alloc-coord.ts +0 -241
  144. package/src/observability/oom-classify.ts +0 -260
  145. package/src/observability/oom-discriminator.ts +0 -405
package/README.md CHANGED
@@ -5,16 +5,23 @@
5
5
  > presented as-is.
6
6
 
7
7
  The backend-agnostic half of Nimbus: a durable POSIX-like filesystem, a shell
8
- with 60+ Unix commands, and the WASI runtime layer with no Cloudflare
9
- dependency. You hand it a SQLite and get back `.fs` and `.exec`. On
10
- Cloudflare that SQLite is `ctx.storage.sql` inside your Durable Object; in bun
11
- or node it is `bun:sqlite` or `node:sqlite`.
8
+ with 60+ Unix commands, and the WASI runtime layer. It has no Cloudflare
9
+ dependency.
12
10
 
13
- I extracted this package because I kept wanting Nimbus *inside* other
14
- projects a Durable Object that already does something else but needs a real
15
- workspace, or a local script that needs the same filesystem semantics the
16
- hosted product has. The whole of it runs on two narrow ports (`SqlDatabase`
17
- and `SqlTransactions`), so the same code serves both hosts.
11
+ You hand it a SQLite and get back `.fs` and `.exec`. On Cloudflare that
12
+ SQLite is `ctx.storage.sql` inside your Durable Object; in bun or node it is
13
+ `bun:sqlite` or `node:sqlite`. The whole package rests on two narrow ports
14
+ (`SqlDatabase` and `SqlTransactions`), so the same code serves both hosts.
15
+
16
+ Use it when something you already run needs a real workspace. A Durable
17
+ Object that does something else and needs somewhere to work. A local script
18
+ that needs the filesystem semantics the hosted product has.
19
+
20
+ ## Install
21
+
22
+ ```bash
23
+ npm install @nimbus-sh/core
24
+ ```
18
25
 
19
26
  ## Quick start
20
27
 
@@ -73,13 +80,13 @@ export class Workspace extends DurableObject {
73
80
  ```
74
81
 
75
82
  Files written through `.fs` are owned by the session user (uid 1000), not
76
- root, and the shell enforces the same permission model either way: a
77
- root-owned `/etc/passwd` refuses a write from `.fs`, and `id` resolves names
78
- through it.
83
+ root. The shell enforces the same permission model either way: a root-owned
84
+ `/etc/passwd` refuses a write from `.fs`, and `id` resolves names through
85
+ it.
79
86
 
80
87
  ## Real runtimes, off Cloudflare
81
88
 
82
- The wasm runtimes are separate npm packages so nobody downloads a Python
89
+ The wasm runtimes are separate npm packages, so nobody downloads a Python
83
90
  interpreter to get a filesystem. Install the ones you want and pass them in:
84
91
 
85
92
  ```bash
@@ -104,35 +111,49 @@ await ws.exec(`python -c "import sqlite3; print('live')"`); // CPython 3.13, re
104
111
  `@nimbus-sh/runtime-ruby` (Ruby 3.3) and `@nimbus-sh/runtime-clang` (clang →
105
112
  `wasm32-wasi`, compile and run C in the workspace) work the same way. Every
106
113
  package carries the same manifest and the same sha256-verified blobs the
107
- hosted product serves from R2 — one publisher, two transports.
114
+ hosted product serves from R2.
115
+
116
+ Without `facets` and `runtimes` you still get the full shell and coreutils.
117
+ The wasm runtimes are a dependency you add.
108
118
 
109
- Without `facets` and `runtimes` you still get the full shell and coreutils;
110
- the wasm runtimes are a dependency you add, not a mode you enable. One caveat:
111
- `localFacetHost()` covers bun and node only — on workerd the CSP forbids
119
+ `localFacetHost()` covers bun and node only. On workerd the CSP forbids
112
120
  request-time `WebAssembly.instantiate`, so wasm has to ride the Worker Loader
113
- module map, which is the machinery in `@nimbus-sh/worker` and
114
- `@nimbus-sh/fabric`; the shell, coreutils, and filesystem need none of it.
121
+ module map. That machinery lives in `@nimbus-sh/worker` and
122
+ `@nimbus-sh/fabric`. The shell, coreutils, and filesystem need none of it.
115
123
 
116
124
  ## Sharing a database with your own app
117
125
 
118
- The workspace is designed to be a tenant in a database you own, not the owner
119
- of it:
126
+ The workspace is a tenant in a database you own:
120
127
 
121
128
  - It creates and touches only its own tables (`inodes`, `file_chunks`,
122
129
  `content_lifecycle`, `vfs_*`).
123
- - `destroy()` drops exactly those tables. It never calls `deleteAll()`.
130
+ - `destroy()` drops those tables and does not call `deleteAll()`.
124
131
  - `transactionSync` must be a real transaction. An implementation that only
125
132
  calls the callback turns every atomic write into a torn one.
126
- - `generation` must never repeat across restarts of your host pids derive
133
+ - `generation` must never repeat across restarts of your host. Pids derive
127
134
  from it, and a repeated generation would hand a dead process live write
128
135
  authority.
129
136
 
130
- ## What needs the Worker package instead
137
+ When your own SQL rows must commit with filesystem bytes, use
138
+ `SqliteVFS.withTransaction(callback)` instead of an outer
139
+ `storage.transactionSync`. Use the credentialed synchronous VFS methods inside
140
+ the callback, not the workspace's asynchronous file methods. The callback can
141
+ read its writes; revisions and watch events publish only after commit. On
142
+ rollback, Nimbus clears cached chunks and reloads the always-resident inode
143
+ tree from SQLite before rethrowing with the original error as `cause`.
144
+
145
+ The method must own the outermost transaction on the same SQL host. Do not
146
+ nest it or start asynchronous work inside it. The host's transaction primitive
147
+ must support nested savepoints for individual VFS writes. If rollback reload
148
+ also fails, Nimbus throws an `AggregateError` carrying both failures; discard
149
+ that VFS instance and reopen it after storage recovers.
150
+
151
+ ## What the worker package adds
131
152
 
132
153
  Resident processes (long-running servers, attached TUIs), the session
133
154
  protocol, port routing to the public internet, and the hosted terminal all
134
- live in [`@nimbus-sh/worker`](https://www.npmjs.com/package/@nimbus-sh/worker),
135
- which composes on this package. If you want the full hosted product shape,
155
+ live in [`@nimbus-sh/worker`](https://www.npmjs.com/package/@nimbus-sh/worker).
156
+ That package composes on this one. If you want the full hosted product shape,
136
157
  start from `npx create-nimbus-app`.
137
158
 
138
159
  ## License
@@ -17,10 +17,11 @@
17
17
  /**
18
18
  * A command's output destination.
19
19
  *
20
- * `writeBytes` is present on sinks that store bytes verbatim (files). Sinks
21
- * that are inherently textual — the terminal, shell pipes omit it and
22
- * receive decoded text instead. This is a real capability difference, not a
23
- * fallback: a terminal has no way to hold a byte that is not text.
20
+ * `writeBytes` is present on sinks that store bytes verbatim files,
21
+ * `/dev/null`, and shell pipes, which carry the producer's exact bytes.
22
+ * Sinks without it take decoded text instead. This is a real capability
23
+ * difference, not a fallback: a terminal has no way to hold a byte that is
24
+ * not text.
24
25
  */
25
26
  export interface ByteSink {
26
27
  write(text: string): void;
@@ -1 +1 @@
1
- {"version":3,"file":"byte-stream.d.ts","sourceRoot":"","sources":["../../src/_shared/byte-stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;GAOG;AACH,MAAM,WAAW,QAAQ;IACvB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,CAAC,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;CACtC;AAED,2EAA2E;AAC3E,MAAM,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,UAAU,CAAC;AAEzE,uEAAuE;AACvE,eAAO,MAAM,kBAAkB,QAAY,CAAC;AAE5C;;;;GAIG;AACH,qBAAa,UAAU;IAIT,OAAO,CAAC,QAAQ,CAAC,IAAI;IAHjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,OAAO,CAAC,OAAO,CAAK;gBAES,IAAI,EAAE,QAAQ;IAI3C,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAO9B,GAAG,IAAI,IAAI;CAKZ;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,WAAW,EACjB,MAAM,EAAE,UAAU,EAClB,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAO,GACvE,MAAM,CAkBR"}
1
+ {"version":3,"file":"byte-stream.d.ts","sourceRoot":"","sources":["../../src/_shared/byte-stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;GAQG;AACH,MAAM,WAAW,QAAQ;IACvB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,CAAC,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;CACtC;AAED,2EAA2E;AAC3E,MAAM,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,UAAU,CAAC;AAEzE,uEAAuE;AACvE,eAAO,MAAM,kBAAkB,QAAY,CAAC;AAE5C;;;;GAIG;AACH,qBAAa,UAAU;IAIT,OAAO,CAAC,QAAQ,CAAC,IAAI;IAHjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,OAAO,CAAC,OAAO,CAAK;gBAES,IAAI,EAAE,QAAQ;IAI3C,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAO9B,GAAG,IAAI,IAAI;CAKZ;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,WAAW,EACjB,MAAM,EAAE,UAAU,EAClB,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAO,GACvE,MAAM,CAkBR"}
@@ -11,7 +11,7 @@
11
11
  * L4 — registry.npmjs.org origin ~100-300 ms cross-region
12
12
  *
13
13
  * Pre-cache metrics support: hit/miss counters lived in
14
- * src/observability/diag-counters.ts but only tracked the RPC-call
14
+ * @nimbus-sh/platform/diag-counters.js but only tracked the RPC-call
15
15
  * boundary, not per-tier. Those flat counters have since been removed.
16
16
  *
17
17
  * This module adds per-tier × per-kind counters. SAME singleton-per-
@@ -142,4 +142,26 @@ export declare function snapshot(): CacheStatsSnapshot;
142
142
  * were reset at Y" (the gap is intentional vs an isolate reboot).
143
143
  */
144
144
  export declare function reset(): void;
145
+ /**
146
+ * cache-obs-2: fold facet-collected per-tier cache events into the
147
+ * DO-side cache-stats singleton. Called from installer.ts after a
148
+ * batch-facet / resolve-facet returns — mirrors recordR2RaceCounters
149
+ * (the facet collects metrics in its result and the supervisor folds
150
+ * them into the DO isolate).
151
+ *
152
+ * Each event has shape:
153
+ * { kind: 'hit', tier: 'L2'|'L3'|'L4', cacheKind: 'tarball'|'packument'|'asset', bytes: number }
154
+ * { kind: 'miss', tier: ..., cacheKind: ... }
155
+ */
156
+ export type CacheStatEvent = {
157
+ kind: 'hit';
158
+ tier: CacheTier;
159
+ cacheKind: CacheKind;
160
+ bytes: number;
161
+ } | {
162
+ kind: 'miss';
163
+ tier: CacheTier;
164
+ cacheKind: CacheKind;
165
+ };
166
+ export declare function recordCacheStatEvents(events: readonly CacheStatEvent[] | undefined): void;
145
167
  //# sourceMappingURL=cache-stats.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cache-stats.d.ts","sourceRoot":"","sources":["../../src/_shared/cache-stats.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAElD;;;;;;;;;GASG;AACH,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,OAAO,CAAC;AAE1D;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,2EAA2E;IAC3E,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,kBAAkB;IACjC,qEAAqE;IACrE,MAAM,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;IACxD;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;;;;;OAMG;IACH,OAAO,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAA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IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAO/E;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,GAAG,IAAI,CAGjE;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,IAAI,kBAAkB,CAqB7C;AAED;;;;;;;GAOG;AACH,wBAAgB,KAAK,IAAI,IAAI,CAS5B;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,SAAS,CAAC;IAAC,SAAS,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACrE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,SAAS,CAAC;IAAC,SAAS,EAAE,SAAS,CAAA;CAAE,CAAC;AAE5D,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,GAAG,SAAS,GAAG,IAAI,CASzF"}
@@ -11,7 +11,7 @@
11
11
  * L4 — registry.npmjs.org origin ~100-300 ms cross-region
12
12
  *
13
13
  * Pre-cache metrics support: hit/miss counters lived in
14
- * src/observability/diag-counters.ts but only tracked the RPC-call
14
+ * @nimbus-sh/platform/diag-counters.js but only tracked the RPC-call
15
15
  * boundary, not per-tier. Those flat counters have since been removed.
16
16
  *
17
17
  * This module adds per-tier × per-kind counters. SAME singleton-per-
@@ -159,3 +159,15 @@ export function reset() {
159
159
  }
160
160
  _lastResetAt = Date.now();
161
161
  }
162
+ export function recordCacheStatEvents(events) {
163
+ if (!events || events.length === 0)
164
+ return;
165
+ for (const e of events) {
166
+ if (e.kind === 'hit') {
167
+ recordHit(e.tier, e.cacheKind, e.bytes);
168
+ }
169
+ else {
170
+ recordMiss(e.tier, e.cacheKind);
171
+ }
172
+ }
173
+ }
@@ -7,7 +7,7 @@
7
7
  * 1. Install-time supervisor (TS) — `src/npm-resolver.ts` re-exports the
8
8
  * typed functions for tree resolution.
9
9
  *
10
- * 2. LoaderPool isolates (JS string) — `src/loaders/pre-bundle-preamble.ts`
10
+ * 2. IsolatePool isolates (JS string) — `src/loaders/pre-bundle-preamble.ts`
11
11
  * embeds `getExportsResolverJS()` as part of the pool preamble so the
12
12
  * pre-bundle facet uses identical resolution semantics to the supervisor.
13
13
  *
@@ -7,7 +7,7 @@
7
7
  * 1. Install-time supervisor (TS) — `src/npm-resolver.ts` re-exports the
8
8
  * typed functions for tree resolution.
9
9
  *
10
- * 2. LoaderPool isolates (JS string) — `src/loaders/pre-bundle-preamble.ts`
10
+ * 2. IsolatePool isolates (JS string) — `src/loaders/pre-bundle-preamble.ts`
11
11
  * embeds `getExportsResolverJS()` as part of the pool preamble so the
12
12
  * pre-bundle facet uses identical resolution semantics to the supervisor.
13
13
  *
@@ -38,6 +38,13 @@
38
38
  * constructed Session's connect/post are inert.
39
39
  * Tools (e.g. nuxi) that open a Session purely
40
40
  * for optional profiling degrade cleanly.
41
+ * - node:zlib — full surface: every *Sync variant, brotli/zstd,
42
+ * crc32, constants, and streaming create* factories
43
+ * (probe-verified 2026-08-23 at compat date
44
+ * 2026-04-01). Forwarded verbatim by the zlib
45
+ * block in node-shims.ts; results are the host
46
+ * realm's own Buffers, which the widened
47
+ * __BufferMod.isBuffer recognizes.
41
48
  */
42
49
  export declare function getRealNodeImportsCode(): string;
43
50
  //# sourceMappingURL=real-node-imports.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"real-node-imports.d.ts","sourceRoot":"","sources":["../../src/_shared/real-node-imports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,wBAAgB,sBAAsB,IAAI,MAAM,CAU/C"}
1
+ {"version":3,"file":"real-node-imports.d.ts","sourceRoot":"","sources":["../../src/_shared/real-node-imports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAEH,wBAAgB,sBAAsB,IAAI,MAAM,CAW/C"}
@@ -38,6 +38,13 @@
38
38
  * constructed Session's connect/post are inert.
39
39
  * Tools (e.g. nuxi) that open a Session purely
40
40
  * for optional profiling degrade cleanly.
41
+ * - node:zlib — full surface: every *Sync variant, brotli/zstd,
42
+ * crc32, constants, and streaming create* factories
43
+ * (probe-verified 2026-08-23 at compat date
44
+ * 2026-04-01). Forwarded verbatim by the zlib
45
+ * block in node-shims.ts; results are the host
46
+ * realm's own Buffers, which the widened
47
+ * __BufferMod.isBuffer recognizes.
41
48
  */
42
49
  export function getRealNodeImportsCode() {
43
50
  return `
@@ -48,5 +55,6 @@ import * as __real_diagnostics_channel from 'node:diagnostics_channel';
48
55
  import * as __real_repl from 'node:repl';
49
56
  import * as __real_vm from 'node:vm';
50
57
  import * as __real_inspector from 'node:inspector';
58
+ import * as __real_zlib from 'node:zlib';
51
59
  `.trim();
52
60
  }
@@ -22,7 +22,7 @@
22
22
  * helper. resolve-one-facet.ts and install-batch-facet.ts therefore keep
23
23
  * equivalent retry loops inside their isolated function bodies.
24
24
  */
25
- import { disposeRpcResource } from './rpc-dispose.js';
25
+ import { disposeRpcResource } from '@nimbus-sh/platform/rpc-dispose.js';
26
26
  import { errorText } from './error-text.js';
27
27
  /** Default retry count AFTER the first attempt (3 = up to 4 total attempts). */
28
28
  export const DEFAULT_RETRIES = 3;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * tarball.ts a whole tarball, in memory, as a path→bytes map.
2
+ * Tarball extraction for streaming installers and buffered archive consumers.
3
3
  *
4
4
  * The streaming primitives it walks with (`parseTarHeader`, `streamTarEntries`,
5
5
  * `readableStreamToAsyncIterable`) live in `./tarball-stream.ts` — a
@@ -7,11 +7,29 @@
7
7
  * into a string the loader pool injects into dynamic workers, where an import
8
8
  * would not resolve.
9
9
  *
10
- * This half is for a caller that already holds the bytes: `gem install`, which
11
- * fetches a `.gem` (a tar holding a gzipped tar) and needs both layers open at
12
- * once. An installer streaming a tarball it is still downloading should drive
13
- * `streamTarEntries` itself and never hold the whole thing.
10
+ * Installers use writeTarballStream. extractTarball retains a map for callers
11
+ * such as gem install, which must open an archive nested inside another one.
14
12
  */
13
+ export interface TarballWriteTarget {
14
+ exists(path: string): boolean;
15
+ mkdir(path: string, options?: {
16
+ recursive?: boolean;
17
+ }): void;
18
+ writeFile(path: string, data: Uint8Array | string): unknown;
19
+ }
20
+ export interface TarballWriteResult {
21
+ /** Regular files written, including the manifest. */
22
+ files: number;
23
+ /** Total decompressed bytes written. */
24
+ bytes: number;
25
+ }
26
+ /**
27
+ * Stream a gzipped npm archive into a package directory. Entry names are
28
+ * already canonical and prefix-stripped by streamTarEntries. Hold only the
29
+ * current entry and the manifest; write the manifest last so a failed install
30
+ * is not mistaken for a complete package on retry. Filesystem failures reject.
31
+ */
32
+ export declare function writeTarballStream(body: ReadableStream<Uint8Array>, targetDir: string, vfs: TarballWriteTarget): Promise<TarballWriteResult>;
15
33
  /** Extract every regular file. Gzipped input is decompressed first. */
16
34
  export declare function extractTarball(tarball: ArrayBuffer): Promise<Map<string, Uint8Array>>;
17
35
  //# sourceMappingURL=tarball.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tarball.d.ts","sourceRoot":"","sources":["../../src/_shared/tarball.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAOH,uEAAuE;AACvE,wBAAsB,cAAc,CAClC,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAsBlC"}
1
+ {"version":3,"file":"tarball.d.ts","sourceRoot":"","sources":["../../src/_shared/tarball.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAOH,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAC9B,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IAC7D,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC;CAC7D;AAED,MAAM,WAAW,kBAAkB;IACjC,qDAAqD;IACrD,KAAK,EAAE,MAAM,CAAC;IACd,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAC;CACf;AAID;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,EAChC,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,kBAAkB,GACtB,OAAO,CAAC,kBAAkB,CAAC,CA0B7B;AAED,uEAAuE;AACvE,wBAAsB,cAAc,CAClC,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAsBlC"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * tarball.ts a whole tarball, in memory, as a path→bytes map.
2
+ * Tarball extraction for streaming installers and buffered archive consumers.
3
3
  *
4
4
  * The streaming primitives it walks with (`parseTarHeader`, `streamTarEntries`,
5
5
  * `readableStreamToAsyncIterable`) live in `./tarball-stream.ts` — a
@@ -7,12 +7,45 @@
7
7
  * into a string the loader pool injects into dynamic workers, where an import
8
8
  * would not resolve.
9
9
  *
10
- * This half is for a caller that already holds the bytes: `gem install`, which
11
- * fetches a `.gem` (a tar holding a gzipped tar) and needs both layers open at
12
- * once. An installer streaming a tarball it is still downloading should drive
13
- * `streamTarEntries` itself and never hold the whole thing.
10
+ * Installers use writeTarballStream. extractTarball retains a map for callers
11
+ * such as gem install, which must open an archive nested inside another one.
14
12
  */
15
13
  import { streamTarEntries, readableStreamToAsyncIterable, } from './tarball-stream.js';
14
+ const PACKAGE_MANIFEST = 'package.json';
15
+ /**
16
+ * Stream a gzipped npm archive into a package directory. Entry names are
17
+ * already canonical and prefix-stripped by streamTarEntries. Hold only the
18
+ * current entry and the manifest; write the manifest last so a failed install
19
+ * is not mistaken for a complete package on retry. Filesystem failures reject.
20
+ */
21
+ export async function writeTarballStream(body, targetDir, vfs) {
22
+ const ensureDir = (path) => {
23
+ if (!vfs.exists(path))
24
+ vfs.mkdir(path, { recursive: true });
25
+ };
26
+ ensureDir(targetDir);
27
+ let files = 0;
28
+ let bytes = 0;
29
+ let manifest = null;
30
+ const entries = streamTarEntries(readableStreamToAsyncIterable(body.pipeThrough(new DecompressionStream('gzip'))));
31
+ for await (const entry of entries) {
32
+ if (entry.name === PACKAGE_MANIFEST) {
33
+ manifest = entry.data;
34
+ continue;
35
+ }
36
+ const fullPath = `${targetDir}/${entry.name}`;
37
+ const cut = fullPath.lastIndexOf('/');
38
+ if (cut > 0)
39
+ ensureDir(fullPath.slice(0, cut));
40
+ await vfs.writeFile(fullPath, entry.data);
41
+ files++;
42
+ bytes += entry.data.length;
43
+ }
44
+ if (!manifest)
45
+ throw new Error(`tarball for ${targetDir} carried no ${PACKAGE_MANIFEST}`);
46
+ await vfs.writeFile(`${targetDir}/${PACKAGE_MANIFEST}`, manifest);
47
+ return { files: files + 1, bytes: bytes + manifest.length };
48
+ }
16
49
  /** Extract every regular file. Gzipped input is decompressed first. */
17
50
  export async function extractTarball(tarball) {
18
51
  const files = new Map();
@@ -1 +1 @@
1
- {"version":3,"file":"vfs-write-ledger.d.ts","sourceRoot":"","sources":["../../src/_shared/vfs-write-ledger.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,+BAA+B,QAqZpC,CAAC;AAET,eAAO,MAAM,uBAAuB,QAgC5B,CAAC"}
1
+ {"version":3,"file":"vfs-write-ledger.d.ts","sourceRoot":"","sources":["../../src/_shared/vfs-write-ledger.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,+BAA+B,QA2ZpC,CAAC;AAET,eAAO,MAAM,uBAAuB,QAgC5B,CAAC"}
@@ -317,26 +317,32 @@ async function __nimbusPersistVfsWrite(supervisor, path, content, snapshot) {
317
317
  }
318
318
 
319
319
  /**
320
- * Write back everything parked, keeping any failure for the exit drain.
320
+ * Write back the cells parked at THIS instant, and only those.
321
321
  *
322
- * The write-back sites that are not the exit drain — the debounce below and
323
- * the RELEASE barrier ahead of egress have no caller who could act on a
324
- * failure: there is no user frame to throw into, and rejecting the fetch that
325
- * happened to trigger the flush would blame the wrong operation. Retaining
326
- * the failure in the channel \`__nimbusDrainVfsMutations\` already drains means
327
- * the exit path still reports it, so a lost write is loud exactly once and
328
- * never silent.
322
+ * Bounded on purpose, and deliberately not routed through
323
+ * \`__nimbusDrainVfsWrites\`, whose \`while (pending > 0)\` waits for the mutation
324
+ * queue to be EMPTY. That wait is correct at process exit, where no new writes
325
+ * are coming. Anywhere else it is a livelock: a facet unpacking a tarball adds
326
+ * mutations faster than the loop retires them, so the loop never returns.
327
+ * Sited ahead of egress where it was that stopped the request from ever
328
+ * leaving the facet, and \`npx sv create\` ran, printed its intro, and then
329
+ * never reported an exit at all. A barrier may delay a request; it may not
330
+ * wait on a condition a busy process never reaches.
331
+ *
332
+ * Failures are retained rather than thrown. The two callers — the debounce
333
+ * below, and the RELEASE barrier ahead of egress — have no frame that could
334
+ * act on one: rejecting the fetch that happened to trigger the flush would
335
+ * blame the wrong operation. The exit drain reports what is retained, so a
336
+ * lost write is loud exactly once and never silent.
329
337
  */
330
338
  async function __nimbusFlushVfsWriteBack(supervisor) {
331
339
  if (!supervisor) return;
332
- try {
333
- await __nimbusDrainVfsWrites(supervisor);
334
- } catch (error) {
335
- if (!__nimbusHasPendingVfsMutationFailure) {
336
- __nimbusHasPendingVfsMutationFailure = true;
337
- __nimbusPendingVfsMutationFailure = error;
338
- }
339
- }
340
+ const paths = Object.keys(__vfsWrites);
341
+ if (paths.length === 0) return;
342
+ await Promise.allSettled(paths.map((path) => __nimbusFlushVfsWrite(
343
+ path,
344
+ (content, snapshot) => __nimbusPersistVfsWrite(supervisor, path, content, snapshot),
345
+ )));
340
346
  }
341
347
 
342
348
  /**
@@ -1,6 +1,11 @@
1
1
  /**
2
2
  * constants.ts — Single source of truth for all Nimbus configuration.
3
+ *
4
+ * Nimbus POLICY only. The measured platform limits these policies are
5
+ * derived from (tx bounds, the RPC envelope, supervisor budgets) live in
6
+ * `@nimbus-sh/platform/limits.js`.
3
7
  */
8
+ export { CHUNK_SIZE, MAX_GLOBAL_WRITE_STREAM_CREDIT_BYTES, MAX_RPC_SAFE_PAYLOAD_BYTES, MAX_TX_BLOB_BYTES, MAX_TX_LOGICAL_ROWS, MAX_TX_SQL_EXECS, PRE_BUNDLE_CONCURRENCY, PRE_BUNDLE_SLICE_CAP_BYTES, SUPERVISOR_HEAP_CEILING_BYTES, SUPERVISOR_IN_FLIGHT_ALLOCATION_BUDGET_BYTES, SUPERVISOR_READ_RESERVE_BYTES, } from '@nimbus-sh/platform/limits.js';
4
9
  export declare const NIMBUS_VERSION = "2.0.0";
5
10
  export declare const NODE_VERSION = "v22.19.0";
6
11
  export declare const NODE_VERSIONS: {
@@ -11,15 +16,9 @@ export declare const NODE_VERSIONS: {
11
16
  export declare const ESBUILD_VERSION = "0.24.2";
12
17
  export declare const SQLJS_VERSION = "1.14.1";
13
18
  export declare const OPENCODE_VERSION = "1.16.2";
14
- export declare const CHUNK_SIZE = 65536;
15
19
  export declare const LRU_MAX_ENTRIES = 512;
16
20
  export declare const BATCH_SIZE = 64;
17
21
  export declare const VFS_CAPACITY: number;
18
- export declare const MAX_TX_BLOB_BYTES: number;
19
- export declare const MAX_TX_LOGICAL_ROWS = 256;
20
- export declare const MAX_TX_SQL_EXECS = 64;
21
- export declare const MAX_GLOBAL_WRITE_STREAM_CREDIT_BYTES: number;
22
- export declare const MAX_RPC_SAFE_PAYLOAD_BYTES: number;
23
22
  export declare const FS_READ_BATCH_PATH_LIMIT = 1024;
24
23
  export declare const FS_READ_BATCH_REQUEST_BYTES: number;
25
24
  export declare const FS_LIST_PAGE_LIMIT = 8192;
@@ -43,17 +42,12 @@ export declare const CWD_SNAPSHOT_MAX_FILE_BYTES: number;
43
42
  export declare const NPM_REGISTRY = "https://registry.npmjs.org";
44
43
  export declare const NPM_CONCURRENCY = 12;
45
44
  export declare const NPM_DECOMPRESS_TIMEOUT = 15000;
46
- export declare const PRE_BUNDLE_SLICE_CAP_BYTES: number;
47
- export declare const PRE_BUNDLE_CONCURRENCY = 1;
48
45
  export declare const DEFAULT_VITE_PORT = 5173;
49
46
  export declare const DEFAULT_PREVIEW_BASE = "/preview";
50
47
  export declare const DEFAULT_WORKER_BASE = "/worker";
51
48
  export declare const WRANGLER_DEBOUNCE_MS = 250;
52
49
  export declare const NIMBUS_AI_GATEWAY_PORT = 8790;
53
50
  export declare const CF_COMPAT_DATE = "2026-04-01";
54
- export declare const SUPERVISOR_HEAP_CEILING_BYTES: number;
55
- export declare const SUPERVISOR_IN_FLIGHT_ALLOCATION_BUDGET_BYTES: number;
56
- export declare const SUPERVISOR_READ_RESERVE_BYTES: number;
57
51
  export declare const DEFAULT_HOSTNAME = "nimbus";
58
52
  export declare const DEFAULT_HOME = "/home/user";
59
53
  export declare const DEFAULT_USER = "user";
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,eAAO,MAAM,cAAc,UAAU,CAAC;AA+BtC,eAAO,MAAM,YAAY,aAAa,CAAC;AACvC,eAAO,MAAM,aAAa;;;;CAAyD,CAAC;AACpF,eAAO,MAAM,eAAe,WAAW,CAAC;AAQxC,eAAO,MAAM,aAAa,WAAW,CAAC;AAQtC,eAAO,MAAM,gBAAgB,WAAW,CAAC;AAGzC,eAAO,MAAM,UAAU,QAAS,CAAC;AACjC,eAAO,MAAM,eAAe,MAAM,CAAC;AACnC,eAAO,MAAM,UAAU,KAAK,CAAC;AAC7B,eAAO,MAAM,YAAY,QAA0B,CAAC;AACpD,eAAO,MAAM,iBAAiB,QAAkB,CAAC;AACj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C,eAAO,MAAM,oBAAoB,QAAmB,CAAC;AACrD,eAAO,MAAM,wBAAwB,QAAmB,CAAC;AAiBzD,eAAO,MAAM,wBAAwB,QAAmB,CAAC;AAoBzD,eAAO,MAAM,2BAA2B,QAAkB,CAAC;AAM3D,eAAO,MAAM,YAAY,+BAA+B,CAAC;AACzD,eAAO,MAAM,eAAe,KAAK,CAAC;AAClC,eAAO,MAAM,sBAAsB,QAAS,CAAC;AAG7C,eAAO,MAAM,iBAAiB,OAAO,CAAC;AACtC,eAAO,MAAM,oBAAoB,aAAa,CAAC;AAC/C,eAAO,MAAM,mBAAmB,YAAY,CAAC;AAC7C,eAAO,MAAM,oBAAoB,MAAM,CAAC;AASxC,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAG3C,eAAO,MAAM,cAAc,eAAe,CAAC;AAG3C,eAAO,MAAM,gBAAgB,WAAW,CAAC;AACzC,eAAO,MAAM,YAAY,eAAe,CAAC;AACzC,eAAO,MAAM,YAAY,SAAS,CAAC;AACnC,eAAO,MAAM,aAAa,YAAY,CAAC;AACvC,eAAO,MAAM,YAAY,2EAA2E,CAAC;AACrG,eAAO,MAAM,oBAAoB,UAAqD,CAAC;AAiBvF,eAAO,MAAM,uBAAuB,EAAE,SAAS,MAAM,EAAe,CAAC"}
package/dist/constants.js CHANGED
@@ -1,6 +1,17 @@
1
1
  /**
2
2
  * constants.ts — Single source of truth for all Nimbus configuration.
3
+ *
4
+ * Nimbus POLICY only. The measured platform limits these policies are
5
+ * derived from (tx bounds, the RPC envelope, supervisor budgets) live in
6
+ * `@nimbus-sh/platform/limits.js`.
3
7
  */
8
+ import { MAX_RPC_SAFE_PAYLOAD_BYTES } from '@nimbus-sh/platform/limits.js';
9
+ // Published-surface forwarding: @nimbus-sh/core@0.5.0 exports these from
10
+ // this module and real consumers import them here (Proteus merge-back.ts
11
+ // pulls CHUNK_SIZE and the MAX_TX_* set). The platform split moved the
12
+ // definitions to @nimbus-sh/platform/limits.js, which stays the single
13
+ // source of truth; core's own modules import platform directly.
14
+ export { CHUNK_SIZE, MAX_GLOBAL_WRITE_STREAM_CREDIT_BYTES, MAX_RPC_SAFE_PAYLOAD_BYTES, MAX_TX_BLOB_BYTES, MAX_TX_LOGICAL_ROWS, MAX_TX_SQL_EXECS, PRE_BUNDLE_CONCURRENCY, PRE_BUNDLE_SLICE_CAP_BYTES, SUPERVISOR_HEAP_CEILING_BYTES, SUPERVISOR_IN_FLIGHT_ALLOCATION_BUDGET_BYTES, SUPERVISOR_READ_RESERVE_BYTES, } from '@nimbus-sh/platform/limits.js';
4
15
  // ── Versions ────────────────────────────────────────────────────────────
5
16
  export const NIMBUS_VERSION = '2.0.0';
6
17
  //
@@ -52,18 +63,11 @@ export const SQLJS_VERSION = '1.14.1';
52
63
  // runtime/opencode-artifact.ts and served as the package's `opencode` bin.
53
64
  export const OPENCODE_VERSION = '1.16.2';
54
65
  // ── VFS Constants ───────────────────────────────────────────────────────
55
- export const CHUNK_SIZE = 65_536; // 64KB per content chunk
66
+ // The chunk size itself (CHUNK_SIZE) and the transaction bounds are
67
+ // platform limits — see @nimbus-sh/platform/limits.js.
56
68
  export const LRU_MAX_ENTRIES = 512; // 512 × 64KB = 32MB hot cache
57
69
  export const BATCH_SIZE = 64; // rows per batch INSERT
58
70
  export const VFS_CAPACITY = 10 * 1024 * 1024 * 1024; // 10 GB
59
- export const MAX_TX_BLOB_BYTES = 1 * 1024 * 1024;
60
- export const MAX_TX_LOGICAL_ROWS = 256;
61
- export const MAX_TX_SQL_EXECS = 64;
62
- export const MAX_GLOBAL_WRITE_STREAM_CREDIT_BYTES = 8 * 1024 * 1024;
63
- // Largest byte payload Nimbus sends through an ordinary Workers RPC value.
64
- // The platform limit is 32 MiB; 28 MiB leaves room for structured-clone
65
- // metadata and matches the proven on-demand facet transfer envelope.
66
- export const MAX_RPC_SAFE_PAYLOAD_BYTES = 28 * 1024 * 1024;
67
71
  // ── Batched filesystem reads ────────────────────────────────────────────
68
72
  // A round trip costs an order of magnitude more than the SQLite lookup
69
73
  // behind it, so a program that touches many files pays for round trips and
@@ -188,11 +192,12 @@ export const PREFETCH_CACHE_MAX_BYTES = 16 * 1024 * 1024;
188
192
  // it now raises ENOENT instead of costing the session.
189
193
  export const CWD_SNAPSHOT_MAX_FILE_BYTES = 2 * 1024 * 1024;
190
194
  // ── npm Constants ───────────────────────────────────────────────────────
195
+ // The pre-bundle admission envelope (PRE_BUNDLE_SLICE_CAP_BYTES,
196
+ // PRE_BUNDLE_CONCURRENCY) is a measured platform envelope — see
197
+ // @nimbus-sh/platform/limits.js.
191
198
  export const NPM_REGISTRY = 'https://registry.npmjs.org';
192
199
  export const NPM_CONCURRENCY = 12;
193
200
  export const NPM_DECOMPRESS_TIMEOUT = 15_000;
194
- export const PRE_BUNDLE_SLICE_CAP_BYTES = MAX_RPC_SAFE_PAYLOAD_BYTES;
195
- export const PRE_BUNDLE_CONCURRENCY = 1;
196
201
  // ── Dev Server Constants ────────────────────────────────────────────────
197
202
  export const DEFAULT_VITE_PORT = 5173;
198
203
  export const DEFAULT_PREVIEW_BASE = '/preview';
@@ -208,51 +213,6 @@ export const WRANGLER_DEBOUNCE_MS = 250;
208
213
  export const NIMBUS_AI_GATEWAY_PORT = 8790;
209
214
  // ── Compatibility ───────────────────────────────────────────────────────
210
215
  export const CF_COMPAT_DATE = '2026-04-01';
211
- // ── Supervisor heap budget [C'.1] ───────────────────────────────────────
212
- //
213
- // Three distinct memory regimes, not one shared pool:
214
- //
215
- // - Supervisor DO isolate: 128 MiB HARD platform ceiling ("Each isolate
216
- // can consume up to 128 MB of memory" —
217
- // https://developers.cloudflare.com/workers/platform/limits/).
218
- // - Facets: ~208-256 MiB EACH, measured — memory independent of the
219
- // supervisor and of each other (1,664 MiB live across 8 facets +
220
- // parent) but CPU SHARED across the actor thread. See
221
- // packages/worker/src/loaders/process-fabric.ts.
222
- // - Peer DOs: independent memory AND CPU budgets, measured 1.2 GiB
223
- // live across 8 peers.
224
- //
225
- // Nimbus targets HALF of the supervisor's 128 MiB as a self-imposed soft
226
- // ceiling so the supervisor always has runway when workerd LRU-evicts
227
- // neighbours or AIR (Asynchronous Isolate Recreation) folds growing
228
- // isolates.
229
- //
230
- // 64 MiB is a soft admission budget, not a measurement — the right value
231
- // is unmeasured — and nothing enforces it directly.
232
- // src/observability/heap-estimate.ts sums the INSTRUMENTED contributors —
233
- // the supervisor baseline, VFS LRU and in-flight writes, pre-bundle
234
- // slices, streaming RPC buffers, and the prefetch-bundle build lease and
235
- // cache gauge — which is a lower bound, not full coverage; allocation
236
- // sites known to be missing are listed in HEAP_BLIND_SPOTS. Read a low
237
- // percentOfCeiling accordingly.
238
- export const SUPERVISOR_HEAP_CEILING_BYTES = 64 * 1024 * 1024;
239
- // Shared allowance for transient allocations in the supervisor DO. With the
240
- // VFS LRU shrunk to 8 MiB during an active reservation, 40 MiB of admitted
241
- // payload plus the 9 MiB bundle baseline stays below the 64 MiB soft ceiling
242
- // with 7 MiB left for metadata, structured-clone overhead, and runtime state.
243
- // This is 31.25% of the platform's 128 MiB hard isolate ceiling.
244
- export const SUPERVISOR_IN_FLIGHT_ALLOCATION_BUDGET_BYTES = 40 * 1024 * 1024;
245
- // Reserved slice of that allowance for chunk-sized filesystem reads, so a
246
- // read is never queued behind a multi-megabyte owner for a wait that has
247
- // nothing to do with its own cost. A read only draws on this when the shared
248
- // budget is already contended — which is exactly when the VFS LRU is shrunk
249
- // to 8 MiB — so peak accounting is 40 + 1 admitted, 8 LRU, 9 bundle baseline:
250
- // 58 MiB, still under the 64 MiB soft ceiling.
251
- //
252
- // 1 MiB is 16 concurrent READ_STREAM_CHUNK_BYTES reads. The point is not
253
- // depth, it is that a read loop keeps moving while a heavy owner works
254
- // instead of stopping dead for the duration.
255
- export const SUPERVISOR_READ_RESERVE_BYTES = 1024 * 1024;
256
216
  // ── OS Defaults ─────────────────────────────────────────────────────────
257
217
  export const DEFAULT_HOSTNAME = 'nimbus';
258
218
  export const DEFAULT_HOME = '/home/user';
@@ -34,7 +34,7 @@
34
34
  * Within a single isolate's lifetime, the same path always returns the
35
35
  * same content.
36
36
  */
37
- import { disposeRpcResource } from '../_shared/rpc-dispose.js';
37
+ import { disposeRpcResource } from '@nimbus-sh/platform/rpc-dispose.js';
38
38
  /**
39
39
  * Per-isolate cache. Keys are asset paths (e.g. `/_assets/foo.js`).
40
40
  * Values are settled promises so concurrent callers share the same