@nimbus-sh/worker 0.1.1 → 0.1.3
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/LICENSE +21 -0
- package/NOTICE.md +6 -0
- package/README.md +38 -3
- package/dist/_shared/cache-stats.d.ts +1 -1
- package/dist/_shared/cache-stats.js +1 -1
- package/dist/_shared/exports-resolver.d.ts +0 -2
- package/dist/_shared/exports-resolver.d.ts.map +1 -1
- package/dist/_shared/exports-resolver.js +0 -2
- package/dist/_shared/session-id.d.ts +10 -8
- package/dist/_shared/session-id.d.ts.map +1 -1
- package/dist/_shared/session-id.js +13 -12
- package/dist/_shared/session-router.d.ts +0 -1
- package/dist/_shared/session-router.d.ts.map +1 -1
- package/dist/_shared/session-router.js +0 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +1 -1
- package/dist/auth/types.d.ts +2 -1
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/auth/types.js +4 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +0 -1
- package/dist/facets/cirrus-real.d.ts +1 -1
- package/dist/facets/cirrus-real.js +1 -1
- package/dist/facets/manager.d.ts +0 -1
- package/dist/facets/manager.d.ts.map +1 -1
- package/dist/facets/manager.js +3 -15
- package/dist/facets/process.d.ts +2 -2
- package/dist/facets/process.js +2 -2
- package/dist/facets/vite-dev-server.d.ts +3 -3
- package/dist/facets/vite-dev-server.d.ts.map +1 -1
- package/dist/facets/vite-dev-server.js +6 -8
- package/dist/facets/wasm-swap-registry.d.ts +15 -21
- package/dist/facets/wasm-swap-registry.d.ts.map +1 -1
- package/dist/facets/wasm-swap-registry.js +41 -54
- package/dist/facets/ws-terminal.d.ts +4 -5
- package/dist/facets/ws-terminal.d.ts.map +1 -1
- package/dist/facets/ws-terminal.js +7 -8
- package/dist/git/commands.d.ts.map +1 -1
- package/dist/git/commands.js +0 -1
- package/dist/git/network-facet.d.ts.map +1 -1
- package/dist/git/network-facet.js +0 -2
- package/dist/git-bundle.generated.d.ts +0 -1
- package/dist/git-bundle.generated.d.ts.map +1 -1
- package/dist/git-bundle.generated.js +0 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/loaders/child-process/spawn-facet.d.ts +7 -52
- package/dist/loaders/child-process/spawn-facet.d.ts.map +1 -1
- package/dist/loaders/child-process/spawn-facet.js +7 -49
- package/dist/loaders/child-process/spawn-pool.d.ts +5 -44
- package/dist/loaders/child-process/spawn-pool.d.ts.map +1 -1
- package/dist/loaders/child-process/spawn-pool.js +5 -44
- package/dist/loaders/fanout-pool.d.ts +18 -65
- package/dist/loaders/fanout-pool.d.ts.map +1 -1
- package/dist/loaders/fanout-pool.js +25 -87
- package/dist/loaders/generated-workers.d.ts +1 -2
- package/dist/loaders/generated-workers.d.ts.map +1 -1
- package/dist/loaders/generated-workers.js +3 -4
- package/dist/loaders/loader-pool.d.ts +1 -2
- package/dist/loaders/loader-pool.d.ts.map +1 -1
- package/dist/loaders/loader-pool.js +1 -1
- package/dist/loaders/npm-resolve-preamble.d.ts +4 -5
- package/dist/loaders/npm-resolve-preamble.d.ts.map +1 -1
- package/dist/loaders/npm-resolve-preamble.js +14 -21
- package/dist/loaders/pre-bundle-preamble.d.ts.map +1 -1
- package/dist/loaders/pre-bundle-preamble.js +0 -1
- package/dist/npm/cache.js +1 -1
- package/dist/npm/install-batch-facet.d.ts.map +1 -1
- package/dist/npm/install-batch-facet.js +7 -12
- package/dist/npm/installer.d.ts +5 -7
- package/dist/npm/installer.d.ts.map +1 -1
- package/dist/npm/installer.js +20 -101
- package/dist/npm/r2-cache.d.ts +17 -29
- package/dist/npm/r2-cache.d.ts.map +1 -1
- package/dist/npm/r2-cache.js +16 -27
- package/dist/npm/resolve-facet.d.ts +11 -17
- package/dist/npm/resolve-facet.d.ts.map +1 -1
- package/dist/npm/resolve-facet.js +14 -28
- package/dist/npm/resolve-one-facet.d.ts +10 -13
- package/dist/npm/resolve-one-facet.d.ts.map +1 -1
- package/dist/npm/resolve-one-facet.js +8 -10
- package/dist/npm/resolver.d.ts +0 -2
- package/dist/npm/resolver.d.ts.map +1 -1
- package/dist/npm/resolver.js +0 -12
- package/dist/observability/oom-discriminator.d.ts +0 -2
- package/dist/observability/oom-discriminator.d.ts.map +1 -1
- package/dist/observability/oom-discriminator.js +0 -2
- package/dist/replica/routing.js +1 -1
- package/dist/router/index.d.ts +6 -2
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +4 -0
- package/dist/router/remote-api.d.ts +44 -0
- package/dist/router/remote-api.d.ts.map +1 -0
- package/dist/router/remote-api.js +333 -0
- package/dist/runtime/barrel-synthesizer.js +1 -1
- package/dist/runtime/clang-runner.d.ts +5 -6
- package/dist/runtime/clang-runner.d.ts.map +1 -1
- package/dist/runtime/clang-runner.js +5 -6
- package/dist/runtime/esbuild-service.d.ts.map +1 -1
- package/dist/runtime/esbuild-service.js +0 -3
- package/dist/runtime/framework-detect.d.ts +0 -1
- package/dist/runtime/framework-detect.d.ts.map +1 -1
- package/dist/runtime/framework-detect.js +0 -1
- package/dist/runtime/node-runner.d.ts +1 -1
- package/dist/runtime/node-runner.js +1 -1
- package/dist/runtime/node-shims.d.ts.map +1 -1
- package/dist/runtime/node-shims.js +0 -22
- package/dist/runtime/package-manager.d.ts +2 -7
- package/dist/runtime/package-manager.d.ts.map +1 -1
- package/dist/runtime/package-manager.js +2 -7
- package/dist/runtime/process-logs-api.js +1 -1
- package/dist/runtime/process-logs.d.ts +0 -1
- package/dist/runtime/process-logs.d.ts.map +1 -1
- package/dist/runtime/process-table.d.ts +2 -2
- package/dist/runtime/process-table.d.ts.map +1 -1
- package/dist/runtime/process-table.js +1 -1
- package/dist/runtime/python-repl.d.ts +0 -1
- package/dist/runtime/python-repl.d.ts.map +1 -1
- package/dist/runtime/python-repl.js +0 -1
- package/dist/runtime/python-runner.d.ts +1 -2
- package/dist/runtime/python-runner.d.ts.map +1 -1
- package/dist/runtime/python-runner.js +1 -3
- package/dist/runtime/repl-session.d.ts +0 -1
- package/dist/runtime/repl-session.d.ts.map +1 -1
- package/dist/runtime/repl-session.js +1 -2
- package/dist/runtime/require-resolver.d.ts.map +1 -1
- package/dist/runtime/require-resolver.js +1 -4
- package/dist/runtime/ruby-runner.d.ts +0 -1
- package/dist/runtime/ruby-runner.d.ts.map +1 -1
- package/dist/runtime/ruby-runner.js +0 -1
- package/dist/runtime/runtime-catalog.d.ts +2 -4
- package/dist/runtime/runtime-catalog.d.ts.map +1 -1
- package/dist/runtime/runtime-catalog.js +2 -4
- package/dist/runtime/runtime-registry.d.ts +1 -1
- package/dist/runtime/runtime-registry.js +1 -1
- package/dist/runtime/streams.d.ts.map +1 -1
- package/dist/runtime/streams.js +0 -1
- package/dist/runtime/wasi-instance.d.ts +35 -45
- package/dist/runtime/wasi-instance.d.ts.map +1 -1
- package/dist/runtime/wasi-instance.js +87 -103
- package/dist/runtime/wasm-runner.d.ts +9 -15
- package/dist/runtime/wasm-runner.d.ts.map +1 -1
- package/dist/runtime/wasm-runner.js +23 -29
- package/dist/session/bindings.d.ts +2 -7
- package/dist/session/bindings.d.ts.map +1 -1
- package/dist/session/bindings.js +3 -8
- package/dist/session/helpers.d.ts +2 -9
- package/dist/session/helpers.d.ts.map +1 -1
- package/dist/session/helpers.js +2 -10
- package/dist/session/init.d.ts +3 -6
- package/dist/session/init.d.ts.map +1 -1
- package/dist/session/init.js +25 -30
- package/dist/session/nimbus-session.d.ts +1 -1
- package/dist/session/nimbus-session.js +5 -5
- package/dist/session/routes.d.ts.map +1 -1
- package/dist/session/routes.js +9 -16
- package/dist/session/rpc.d.ts +2 -2
- package/dist/session/rpc.js +6 -6
- package/dist/session/supervisor-rpc.d.ts +1 -2
- package/dist/session/supervisor-rpc.d.ts.map +1 -1
- package/dist/session/supervisor-rpc.js +1 -5
- package/dist/shell/features.d.ts +5 -5
- package/dist/shell/features.js +6 -6
- package/dist/shell/unix-commands.js +15 -15
- package/dist/vfs/dev-provider.d.ts +1 -1
- package/dist/vfs/dev-provider.js +1 -1
- package/dist/vfs/sqlite-vfs.d.ts +3 -3
- package/dist/vfs/sqlite-vfs.d.ts.map +1 -1
- package/dist/vfs/sqlite-vfs.js +10 -11
- package/package.json +13 -2
- package/public/s/index.html +44 -75
- package/scripts/bundle-facet-workers.mjs +1 -1
- package/scripts/bundle-git.mjs +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oom-discriminator.d.ts","sourceRoot":"","sources":["../../src/observability/oom-discriminator.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"oom-discriminator.d.ts","sourceRoot":"","sources":["../../src/observability/oom-discriminator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAOlD,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,WAAW;IAC1B,eAAe;IACf,EAAE,EAAE,MAAM,CAAC;IACX,yEAAyE;IACzE,KAAK,EAAE,MAAM,CAAC;IACd,gDAAgD;IAChD,KAAK,EAAE,QAAQ,CAAC;IAChB,yDAAyD;IACzD,gBAAgB,EAAE,MAAM,CAAC;IACzB,qEAAqE;IACrE,aAAa,EAAE,MAAM,CAAC;IACtB,kDAAkD;IAClD,QAAQ,EAAE,MAAM,CAAC;IACjB,wDAAwD;IACxD,aAAa,EAAE,MAAM,CAAC;IACtB,qDAAqD;IACrD,YAAY,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC9B,0DAA0D;IAC1D,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CAOtE;AAED,wBAAgB,cAAc,IAAI,OAAO,GAAG,IAAI,CAE/C;AAUD;0BAC0B;AAC1B,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAyB9D;AAED,0DAA0D;AAC1D,wBAAgB,iBAAiB,IAAI,iBAAiB,EAAE,CAEvD;AAED,iEAAiE;AACjE,wBAAgB,mBAAmB,IAAI,IAAI,CAE1C;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,YAAY;IAC3B,+CAA+C;IAC/C,CAAC,EAAE,MAAM,CAAC;IACV,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,cAAc,EAAE,iBAAiB,EAAE,CAAC;IACpC,YAAY,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC9B,WAAW,EAAE,OAAO,GAAG,IAAI,CAAC;CAC7B;AAED,wBAAgB,kBAAkB,IAAI,YAAY,CASjD;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAoCxD"}
|
|
@@ -33,8 +33,6 @@
|
|
|
33
33
|
* - per-facet-id: single slot, one object.
|
|
34
34
|
*
|
|
35
35
|
* Snapshot ≤40 KB even with both rings full. Verified by
|
|
36
|
-
* audit/probes/w5/functional/ring-persistence.mjs (failures) and
|
|
37
|
-
* audit/probes/c-prime/recovery-events/ (recovery — Phase 1 C'.2).
|
|
38
36
|
*/
|
|
39
37
|
const KEY = '__NIMBUS_W5_OOM_DISC__';
|
|
40
38
|
const RING_SIZE = 50;
|
package/dist/replica/routing.js
CHANGED
|
@@ -55,7 +55,7 @@ export function classifyReplicaPolicy(pathname, method) {
|
|
|
55
55
|
// ── Worker / port routes — facets are owned by the primary; no
|
|
56
56
|
// replica representation. Always primary-only.
|
|
57
57
|
//
|
|
58
|
-
//
|
|
58
|
+
// runtime primitive support: `/__nimbus/worker/*` is the canonical route;
|
|
59
59
|
// `/worker/*` is the deprecated legacy form, kept here for back-
|
|
60
60
|
// compat (one release sunset; see routes.ts for the Deprecation
|
|
61
61
|
// header). Both classify the same way.
|
package/dist/router/index.d.ts
CHANGED
|
@@ -31,6 +31,8 @@
|
|
|
31
31
|
* - The default `createNimbusHandler()` (zero args) is the
|
|
32
32
|
* "ship-Nimbus-as-is" case — exactly what `apps/dogfood/` does.
|
|
33
33
|
*/
|
|
34
|
+
import { type NimbusSdkRouterConfig } from './remote-api.js';
|
|
35
|
+
export type { NimbusConfig as NimbusSdkConfig, NimbusRemoteApiConfig, NimbusRuntimePolicy, NimbusSandboxProfile, NimbusSdkRouterConfig, } from './remote-api.js';
|
|
34
36
|
/**
|
|
35
37
|
* Lifecycle event a hook receives. Hooks should treat this as read-only.
|
|
36
38
|
*/
|
|
@@ -50,8 +52,8 @@ export interface NimbusHookContext {
|
|
|
50
52
|
* NOT short-circuit the request.
|
|
51
53
|
*
|
|
52
54
|
* `onSessionStart` fires on the first WebSocket upgrade for a session
|
|
53
|
-
* (not on every HTTP API call). `onSessionEnd`
|
|
54
|
-
* session
|
|
55
|
+
* (not on every HTTP API call). `onSessionEnd` is reserved for future
|
|
56
|
+
* session lifecycle events.
|
|
55
57
|
*/
|
|
56
58
|
export interface NimbusHooks {
|
|
57
59
|
/**
|
|
@@ -110,6 +112,8 @@ export interface CreateNimbusHandlerOptions {
|
|
|
110
112
|
routes?: CustomRoutes;
|
|
111
113
|
/** Auth-mode selector. Default `'auto'`. */
|
|
112
114
|
auth?: NimbusAuthConfig;
|
|
115
|
+
/** Programmatic SDK HTTP surface. Disabled unless explicitly enabled. */
|
|
116
|
+
sdk?: NimbusSdkRouterConfig;
|
|
113
117
|
}
|
|
114
118
|
/**
|
|
115
119
|
* The shape every `default export` Workers handler must satisfy.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/router/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;
|
|
1
|
+
{"version":3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M,WAAW,0BAA0B;IACzC,oCAAoC;IACpC,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,qDAAqD;IACrD,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,4CAA4C;IAC5C,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB,yEAAyE;IACzE,GAAG,CAAC,EAAE,qBAAqB,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC7E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,0BAA+B,GACvC,aAAa,CAkHf"}
|
package/dist/router/index.js
CHANGED
|
@@ -35,6 +35,7 @@ import { generateSessionId, isValidSessionId, } from '../_shared/session-id.js';
|
|
|
35
35
|
import { parseSessionRoute, forwardToSession, renderInvalidSessionHtml, SESSION_ROUTE_PREFIX, LEGACY_PUBLIC_DO_SEGMENT, } from '../_shared/session-router.js';
|
|
36
36
|
import { verifyRequestToken, authErrorResponse, NimbusAuthError, NimbusTokenMalformedError, } from '../auth/index.js';
|
|
37
37
|
import { setCtxExports } from '../session/ctx-exports.js';
|
|
38
|
+
import { handleNimbusRemoteApi, } from './remote-api.js';
|
|
38
39
|
/**
|
|
39
40
|
* Build a Nimbus default-export handler. The returned object is exactly
|
|
40
41
|
* what `export default` expects in a Workers entry module.
|
|
@@ -94,6 +95,9 @@ export function createNimbusHandler(options = {}) {
|
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
const url = new URL(request.url);
|
|
98
|
+
const sdkResponse = await handleNimbusRemoteApi(request, env, options.sdk);
|
|
99
|
+
if (sdkResponse)
|
|
100
|
+
return sdkResponse;
|
|
97
101
|
// ── /new — spawn a fresh session and redirect ───────────────────
|
|
98
102
|
if (url.pathname === '/new') {
|
|
99
103
|
if (request.method !== 'POST' && request.method !== 'GET') {
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type NimbusRuntimeName = 'node' | 'bun' | 'npm' | 'git' | 'python' | 'ruby' | 'clang' | 'shell' | (string & {});
|
|
2
|
+
export interface NimbusRuntimePolicy {
|
|
3
|
+
preinstall?: string[];
|
|
4
|
+
onDemand?: boolean;
|
|
5
|
+
allow?: NimbusRuntimeName[];
|
|
6
|
+
}
|
|
7
|
+
export interface NimbusSandboxProfile {
|
|
8
|
+
root?: string;
|
|
9
|
+
runtimes?: NimbusRuntimePolicy;
|
|
10
|
+
tools?: {
|
|
11
|
+
namespace?: string;
|
|
12
|
+
kind?: string;
|
|
13
|
+
};
|
|
14
|
+
preview?: {
|
|
15
|
+
baseUrl?: string;
|
|
16
|
+
pathStyle?: boolean;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export interface NimbusConfig {
|
|
20
|
+
endpoint?: string;
|
|
21
|
+
sandboxes?: Record<string, NimbusSandboxProfile>;
|
|
22
|
+
}
|
|
23
|
+
export interface NimbusRemoteApiConfig {
|
|
24
|
+
/** Enable the remote programmatic sandbox API. */
|
|
25
|
+
enabled?: boolean;
|
|
26
|
+
/** Route prefix. Defaults to `/api/nimbus/v1`. */
|
|
27
|
+
basePath?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Permit unauthenticated remote calls when JWT_SECRET is absent. This is
|
|
30
|
+
* intended only for private development deployments.
|
|
31
|
+
*/
|
|
32
|
+
allowLegacy?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Required token scopes. Tokens without an explicit `scopes` claim keep the
|
|
35
|
+
* existing full-trust semantics.
|
|
36
|
+
*/
|
|
37
|
+
requiredScopes?: string[];
|
|
38
|
+
}
|
|
39
|
+
export interface NimbusSdkRouterConfig {
|
|
40
|
+
remote?: boolean | NimbusRemoteApiConfig;
|
|
41
|
+
config?: NimbusConfig;
|
|
42
|
+
}
|
|
43
|
+
export declare function handleNimbusRemoteApi(request: Request, env: any, sdk: NimbusSdkRouterConfig | undefined): Promise<Response | null>;
|
|
44
|
+
//# sourceMappingURL=remote-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-api.d.ts","sourceRoot":"","sources":["../../src/router/remote-api.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,iBAAiB,GACzB,MAAM,GACN,KAAK,GACL,KAAK,GACL,KAAK,GACL,QAAQ,GACR,MAAM,GACN,OAAO,GACP,OAAO,GACP,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAElB,MAAM,WAAW,mBAAmB;IAClC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,iBAAiB,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IAC/B,KAAK,CAAC,EAAE;QACN,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;IACF,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,OAAO,CAAC;KACrB,CAAC;CACH;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;CAClD;AAED,MAAM,WAAW,qBAAqB;IACpC,kDAAkD;IAClD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,EAAE,OAAO,GAAG,qBAAqB,CAAC;IACzC,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;AAqBD,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,qBAAqB,GAAG,SAAS,GACrC,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CA8D1B"}
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import { LEGACY_PUBLIC_DO_SEGMENT, } from '../_shared/session-router.js';
|
|
2
|
+
import { requireScopes, requireSessionPin, verifyRequestToken, NimbusAuthError, NimbusTokenMalformedError, isNimbusIdComponent, } from '../auth/index.js';
|
|
3
|
+
const DEFAULT_REMOTE_BASE_PATH = '/api/nimbus/v1';
|
|
4
|
+
export async function handleNimbusRemoteApi(request, env, sdk) {
|
|
5
|
+
const remote = normalizeRemoteConfig(sdk?.remote);
|
|
6
|
+
if (!remote.enabled)
|
|
7
|
+
return null;
|
|
8
|
+
const url = new URL(request.url);
|
|
9
|
+
const match = matchRemoteRpc(url.pathname, remote.basePath);
|
|
10
|
+
if (!match)
|
|
11
|
+
return null;
|
|
12
|
+
if (request.method === 'OPTIONS')
|
|
13
|
+
return corsResponse(null, 204);
|
|
14
|
+
if (request.method !== 'POST') {
|
|
15
|
+
return remoteJson({ ok: false, error: 'Method not allowed', code: 'E_METHOD_NOT_ALLOWED' }, 405);
|
|
16
|
+
}
|
|
17
|
+
if (!env?.NIMBUS_SESSION) {
|
|
18
|
+
return remoteJson({ ok: false, error: 'NIMBUS_SESSION binding is missing', code: 'E_NIMBUS_BINDING_MISSING' }, 500);
|
|
19
|
+
}
|
|
20
|
+
if (!isNimbusIdComponent(match.sandboxId)) {
|
|
21
|
+
return remoteJson({ ok: false, error: 'Invalid sandbox id', code: 'E_SANDBOX_ID' }, 400);
|
|
22
|
+
}
|
|
23
|
+
let body;
|
|
24
|
+
try {
|
|
25
|
+
body = decodeWire(await request.json());
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
return remoteJson({ ok: false, error: `Invalid JSON body: ${e?.message || e}`, code: 'E_BAD_JSON' }, 400);
|
|
29
|
+
}
|
|
30
|
+
const tenantSegment = await resolveRemoteTenantSegment(request, env, remote, match.sandboxId);
|
|
31
|
+
if (tenantSegment instanceof Response)
|
|
32
|
+
return tenantSegment;
|
|
33
|
+
const profileName = body.profile ?? 'default';
|
|
34
|
+
const profile = sdk?.config?.sandboxes?.[profileName]
|
|
35
|
+
?? sdk?.config?.sandboxes?.default
|
|
36
|
+
?? {};
|
|
37
|
+
const root = body.root ?? profile.root ?? '/home/user';
|
|
38
|
+
const doName = `${tenantSegment}:${match.sandboxId}`;
|
|
39
|
+
const id = env.NIMBUS_SESSION.idFromName(doName);
|
|
40
|
+
const stub = env.NIMBUS_SESSION.get(id);
|
|
41
|
+
const ctx = {
|
|
42
|
+
env,
|
|
43
|
+
stub,
|
|
44
|
+
body,
|
|
45
|
+
profileName,
|
|
46
|
+
profile,
|
|
47
|
+
root,
|
|
48
|
+
};
|
|
49
|
+
try {
|
|
50
|
+
const result = await dispatchRemoteRpc(ctx);
|
|
51
|
+
return remoteJson({ ok: true, result });
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
return remoteJson({
|
|
55
|
+
ok: false,
|
|
56
|
+
error: e?.message || String(e),
|
|
57
|
+
code: e?.code || 'E_NIMBUS_REMOTE_RPC',
|
|
58
|
+
}, e?.httpStatus || 500);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function normalizeRemoteConfig(remote) {
|
|
62
|
+
const value = typeof remote === 'object' ? remote : {};
|
|
63
|
+
return {
|
|
64
|
+
enabled: remote === true || value.enabled === true,
|
|
65
|
+
basePath: normalizeBasePath(value.basePath ?? DEFAULT_REMOTE_BASE_PATH),
|
|
66
|
+
allowLegacy: value.allowLegacy === true,
|
|
67
|
+
requiredScopes: value.requiredScopes ?? ['sandbox:use'],
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function matchRemoteRpc(pathname, basePath) {
|
|
71
|
+
const prefix = `${basePath}/sandboxes/`;
|
|
72
|
+
if (!pathname.startsWith(prefix) || !pathname.endsWith('/rpc'))
|
|
73
|
+
return null;
|
|
74
|
+
const raw = pathname.slice(prefix.length, -'/rpc'.length);
|
|
75
|
+
if (!raw || raw.includes('/'))
|
|
76
|
+
return null;
|
|
77
|
+
try {
|
|
78
|
+
return { sandboxId: decodeURIComponent(raw) };
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async function resolveRemoteTenantSegment(request, env, remote, sandboxId) {
|
|
85
|
+
const hasSecret = typeof env?.JWT_SECRET === 'string' && env.JWT_SECRET.length > 0;
|
|
86
|
+
if (!hasSecret) {
|
|
87
|
+
if (remote.allowLegacy)
|
|
88
|
+
return LEGACY_PUBLIC_DO_SEGMENT;
|
|
89
|
+
return remoteJson({
|
|
90
|
+
ok: false,
|
|
91
|
+
error: 'Remote Nimbus sandbox API requires JWT_SECRET',
|
|
92
|
+
code: 'E_AUTH_CONFIG_MISSING',
|
|
93
|
+
}, 500);
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
const verified = await verifyRequestToken(request, env);
|
|
97
|
+
requireScopes(verified, remote.requiredScopes);
|
|
98
|
+
requireSessionPin(verified, sandboxId);
|
|
99
|
+
return verified.doInstanceName;
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
if (e instanceof NimbusAuthError || e instanceof NimbusTokenMalformedError) {
|
|
103
|
+
return remoteJson({ ok: false, error: e.message, code: e.code }, e.httpStatus);
|
|
104
|
+
}
|
|
105
|
+
console.error('[nimbus] remote API auth error:', e);
|
|
106
|
+
return remoteJson({ ok: false, error: 'Internal auth error', code: 'E_AUTH_UNKNOWN' }, 500);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async function dispatchRemoteRpc(ctx) {
|
|
110
|
+
const op = ctx.body.op;
|
|
111
|
+
const args = Array.isArray(ctx.body.args) ? ctx.body.args : [];
|
|
112
|
+
switch (op) {
|
|
113
|
+
case 'ready': {
|
|
114
|
+
const options = objectArg(args[0]);
|
|
115
|
+
const preinstall = configuredPreinstall(ctx.profile, options.preinstall);
|
|
116
|
+
for (const spec of preinstall)
|
|
117
|
+
assertRuntimeAllowed(ctx, spec, 'preinstall');
|
|
118
|
+
return ctx.stub._rpcReady({ preinstall });
|
|
119
|
+
}
|
|
120
|
+
case 'exec':
|
|
121
|
+
return ctx.stub._rpcExec(stringArg(args[0], 'command'), execOptions(ctx, args[1]));
|
|
122
|
+
case 'startProcess':
|
|
123
|
+
return ctx.stub._rpcStartProcess(stringArg(args[0], 'command'), execOptions(ctx, args[1]));
|
|
124
|
+
case 'runCode': {
|
|
125
|
+
const options = execOptions(ctx, args[1]);
|
|
126
|
+
const language = typeof options.language === 'string' ? options.language : 'javascript';
|
|
127
|
+
assertRuntimeForLanguage(ctx, language, options.install);
|
|
128
|
+
return ctx.stub._rpcRunCode(stringArg(args[0], 'code'), options);
|
|
129
|
+
}
|
|
130
|
+
case 'readFile':
|
|
131
|
+
return ctx.stub._rpcReadFile(stringArg(args[0], 'path'));
|
|
132
|
+
case 'readFileBytes':
|
|
133
|
+
return ctx.stub._rpcReadFileBytes(stringArg(args[0], 'path'));
|
|
134
|
+
case 'writeFile':
|
|
135
|
+
return ctx.stub._rpcWriteFile(stringArg(args[0], 'path'), args[1]);
|
|
136
|
+
case 'readdir':
|
|
137
|
+
return ctx.stub._rpcReaddir(stringArg(args[0], 'path'));
|
|
138
|
+
case 'exists':
|
|
139
|
+
return ctx.stub._rpcExists(stringArg(args[0], 'path'));
|
|
140
|
+
case 'mkdir':
|
|
141
|
+
return ctx.stub._rpcMkdir(stringArg(args[0], 'path'));
|
|
142
|
+
case 'deleteFile':
|
|
143
|
+
return ctx.stub._rpcDeleteFile(stringArg(args[0], 'path'), objectArg(args[1]));
|
|
144
|
+
case 'installRuntime': {
|
|
145
|
+
const spec = stringArg(args[0], 'spec');
|
|
146
|
+
assertRuntimeAllowed(ctx, spec, 'onDemand');
|
|
147
|
+
return ctx.stub._rpcInstallRuntime(spec, objectArg(args[1]));
|
|
148
|
+
}
|
|
149
|
+
case 'ensureRuntimes': {
|
|
150
|
+
const specs = arrayArg(args[0], 'specs').map((s) => String(s));
|
|
151
|
+
for (const spec of specs)
|
|
152
|
+
assertRuntimeAllowed(ctx, spec, 'onDemand');
|
|
153
|
+
return ctx.stub._rpcEnsureRuntimes(specs, objectArg(args[1]));
|
|
154
|
+
}
|
|
155
|
+
case 'listRuntimes':
|
|
156
|
+
return ctx.stub._rpcListRuntimes();
|
|
157
|
+
case 'listProcesses':
|
|
158
|
+
return ctx.stub._rpcListProcesses();
|
|
159
|
+
case 'killProcess':
|
|
160
|
+
return ctx.stub._rpcKillProcess(numberArg(args[0], 'pid'));
|
|
161
|
+
case 'processLogs':
|
|
162
|
+
return ctx.stub._rpcProcessLogs(numberArg(args[0], 'pid'), objectArg(args[1]));
|
|
163
|
+
case 'listPorts':
|
|
164
|
+
return ctx.stub._rpcListPorts();
|
|
165
|
+
case 'exposePort':
|
|
166
|
+
return ctx.stub._rpcExposePort(numberArg(args[0], 'port'));
|
|
167
|
+
case 'unexposePort':
|
|
168
|
+
return ctx.stub._rpcUnexposePort(numberArg(args[0], 'port'));
|
|
169
|
+
default:
|
|
170
|
+
throw apiError(`Unknown Nimbus sandbox operation: ${String(op)}`, 'E_REMOTE_OP', 400);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function execOptions(ctx, value) {
|
|
174
|
+
const options = objectArg(value);
|
|
175
|
+
return {
|
|
176
|
+
...options,
|
|
177
|
+
cwd: typeof options.cwd === 'string' ? options.cwd : ctx.root,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function configuredPreinstall(profile, requested) {
|
|
181
|
+
if (Array.isArray(profile.runtimes?.preinstall))
|
|
182
|
+
return profile.runtimes.preinstall;
|
|
183
|
+
return Array.isArray(requested) ? requested.map((s) => String(s)) : [];
|
|
184
|
+
}
|
|
185
|
+
function assertRuntimeForLanguage(ctx, language, install) {
|
|
186
|
+
if (language === 'python' || language === 'ruby') {
|
|
187
|
+
assertRuntimeAllowed(ctx, language, install === 'ifMissing' ? 'onDemand' : 'use');
|
|
188
|
+
}
|
|
189
|
+
else if (language === 'shell') {
|
|
190
|
+
assertRuntimeAllowed(ctx, 'shell', 'use');
|
|
191
|
+
}
|
|
192
|
+
else if (language === 'javascript' || language === 'typescript') {
|
|
193
|
+
assertRuntimeAllowed(ctx, 'node', 'use');
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function assertRuntimeAllowed(ctx, spec, action) {
|
|
197
|
+
const policy = ctx.profile.runtimes;
|
|
198
|
+
const name = runtimeName(spec);
|
|
199
|
+
if (policy?.allow && !policy.allow.includes(name)) {
|
|
200
|
+
throw apiError(`Nimbus runtime '${name}' is not allowed by sandbox profile '${ctx.profileName}'`, 'E_RUNTIME_NOT_ALLOWED', 403);
|
|
201
|
+
}
|
|
202
|
+
if (action !== 'onDemand' || policy?.onDemand !== false)
|
|
203
|
+
return;
|
|
204
|
+
const preinstalled = new Set((policy.preinstall ?? []).map(runtimeName));
|
|
205
|
+
if (!preinstalled.has(name)) {
|
|
206
|
+
throw apiError(`Nimbus runtime '${name}' is not preinstalled and on-demand runtime installs are disabled by sandbox profile '${ctx.profileName}'`, 'E_RUNTIME_ON_DEMAND_DISABLED', 403);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function runtimeName(spec) {
|
|
210
|
+
return String(spec).split('@')[0];
|
|
211
|
+
}
|
|
212
|
+
function objectArg(value) {
|
|
213
|
+
return value && typeof value === 'object' && !Array.isArray(value)
|
|
214
|
+
? value
|
|
215
|
+
: {};
|
|
216
|
+
}
|
|
217
|
+
function arrayArg(value, name) {
|
|
218
|
+
if (!Array.isArray(value))
|
|
219
|
+
throw apiError(`${name} must be an array`, 'E_ARG_SHAPE', 400);
|
|
220
|
+
return value;
|
|
221
|
+
}
|
|
222
|
+
function stringArg(value, name) {
|
|
223
|
+
if (typeof value !== 'string')
|
|
224
|
+
throw apiError(`${name} must be a string`, 'E_ARG_SHAPE', 400);
|
|
225
|
+
return value;
|
|
226
|
+
}
|
|
227
|
+
function numberArg(value, name) {
|
|
228
|
+
const number = Number(value);
|
|
229
|
+
if (!Number.isFinite(number))
|
|
230
|
+
throw apiError(`${name} must be a number`, 'E_ARG_SHAPE', 400);
|
|
231
|
+
return number;
|
|
232
|
+
}
|
|
233
|
+
function apiError(message, code, status) {
|
|
234
|
+
const err = new Error(message);
|
|
235
|
+
err.code = code;
|
|
236
|
+
err.httpStatus = status;
|
|
237
|
+
return err;
|
|
238
|
+
}
|
|
239
|
+
function normalizeBasePath(path) {
|
|
240
|
+
const trimmed = trimSlashes(String(path || DEFAULT_REMOTE_BASE_PATH));
|
|
241
|
+
return `/${trimmed}`;
|
|
242
|
+
}
|
|
243
|
+
function trimSlashes(value) {
|
|
244
|
+
let start = 0;
|
|
245
|
+
let end = value.length;
|
|
246
|
+
while (start < end && value[start] === '/')
|
|
247
|
+
start++;
|
|
248
|
+
while (end > start && value[end - 1] === '/')
|
|
249
|
+
end--;
|
|
250
|
+
return value.slice(start, end);
|
|
251
|
+
}
|
|
252
|
+
function remoteJson(value, status = 200) {
|
|
253
|
+
return corsResponse(JSON.stringify(encodeWire(value)), status, {
|
|
254
|
+
'Content-Type': 'application/json',
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
function corsResponse(body, status, headers = {}) {
|
|
258
|
+
return new Response(body, {
|
|
259
|
+
status,
|
|
260
|
+
headers: {
|
|
261
|
+
...headers,
|
|
262
|
+
'Cache-Control': 'no-store',
|
|
263
|
+
'Access-Control-Allow-Origin': '*',
|
|
264
|
+
'Access-Control-Allow-Methods': 'POST, OPTIONS',
|
|
265
|
+
'Access-Control-Allow-Headers': 'Authorization, Content-Type',
|
|
266
|
+
},
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
function encodeWire(value) {
|
|
270
|
+
if (value instanceof Uint8Array) {
|
|
271
|
+
return {
|
|
272
|
+
__nimbusWireType: 'bytes',
|
|
273
|
+
base64: bytesToBase64(value),
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
if (value instanceof ArrayBuffer) {
|
|
277
|
+
return {
|
|
278
|
+
__nimbusWireType: 'bytes',
|
|
279
|
+
base64: bytesToBase64(new Uint8Array(value)),
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
if (ArrayBuffer.isView(value)) {
|
|
283
|
+
const view = value;
|
|
284
|
+
return {
|
|
285
|
+
__nimbusWireType: 'bytes',
|
|
286
|
+
base64: bytesToBase64(new Uint8Array(view.buffer, view.byteOffset, view.byteLength)),
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
if (Array.isArray(value))
|
|
290
|
+
return value.map(encodeWire);
|
|
291
|
+
if (value && typeof value === 'object') {
|
|
292
|
+
const out = {};
|
|
293
|
+
for (const [key, item] of Object.entries(value)) {
|
|
294
|
+
if (item !== undefined)
|
|
295
|
+
out[key] = encodeWire(item);
|
|
296
|
+
}
|
|
297
|
+
return out;
|
|
298
|
+
}
|
|
299
|
+
return value;
|
|
300
|
+
}
|
|
301
|
+
function decodeWire(value) {
|
|
302
|
+
if (value
|
|
303
|
+
&& typeof value === 'object'
|
|
304
|
+
&& value.__nimbusWireType === 'bytes'
|
|
305
|
+
&& typeof value.base64 === 'string') {
|
|
306
|
+
return base64ToBytes(value.base64);
|
|
307
|
+
}
|
|
308
|
+
if (Array.isArray(value))
|
|
309
|
+
return value.map(decodeWire);
|
|
310
|
+
if (value && typeof value === 'object') {
|
|
311
|
+
const out = {};
|
|
312
|
+
for (const [key, item] of Object.entries(value)) {
|
|
313
|
+
out[key] = decodeWire(item);
|
|
314
|
+
}
|
|
315
|
+
return out;
|
|
316
|
+
}
|
|
317
|
+
return value;
|
|
318
|
+
}
|
|
319
|
+
function bytesToBase64(bytes) {
|
|
320
|
+
let binary = '';
|
|
321
|
+
const chunk = 0x8000;
|
|
322
|
+
for (let i = 0; i < bytes.length; i += chunk) {
|
|
323
|
+
binary += String.fromCharCode(...bytes.subarray(i, i + chunk));
|
|
324
|
+
}
|
|
325
|
+
return btoa(binary);
|
|
326
|
+
}
|
|
327
|
+
function base64ToBytes(base64) {
|
|
328
|
+
const binary = atob(base64);
|
|
329
|
+
const bytes = new Uint8Array(binary.length);
|
|
330
|
+
for (let i = 0; i < binary.length; i++)
|
|
331
|
+
bytes[i] = binary.charCodeAt(i);
|
|
332
|
+
return bytes;
|
|
333
|
+
}
|
|
@@ -222,7 +222,7 @@ export function buildSyntheticEntry(vfs, nmDir, pkgName, names) {
|
|
|
222
222
|
// `default` (default re-export with no rename) is rare; skip.
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
|
-
//
|
|
225
|
+
// barrel fallback support — `export * from './x.js'` support.
|
|
226
226
|
//
|
|
227
227
|
// Many barrel packages (date-fns, several utility libraries, some
|
|
228
228
|
// icon kits) use `export *` aggregation instead of per-name
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* clang-runner.ts —
|
|
2
|
+
* clang-runner.ts — compile, link, and execute C programs as wasm32-wasi.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Architecture (compile-link-run, two facet calls):
|
|
5
5
|
*
|
|
6
6
|
* compile : clang.wasm + memfs.wasm + sysroot subset for C includes
|
|
7
7
|
* + user .c → produces .o bytes (returned to supervisor).
|
|
@@ -11,8 +11,7 @@
|
|
|
11
11
|
* write : final .wasm flushed to user VFS at the requested path.
|
|
12
12
|
*
|
|
13
13
|
* Splitting compile and link into separate LOADER calls keeps each
|
|
14
|
-
* call under the empirical
|
|
15
|
-
* path B). Each ships:
|
|
14
|
+
* call under the empirical loader payload ceiling. Each ships:
|
|
16
15
|
*
|
|
17
16
|
* - compile: 31 MiB clang.wasm + 0.35 MiB memfs + ~1.3 MiB sysroot
|
|
18
17
|
* subset (C includes) = ~32.6 MiB.
|
|
@@ -23,8 +22,8 @@
|
|
|
23
22
|
* parser. The full 9.3 MiB sysroot.tar is parsed once per compile;
|
|
24
23
|
* only the files matching the role's prefix-allowlist are forwarded.
|
|
25
24
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
25
|
+
* Dispatch stays direct: no sleeps, no caller-side retries, and no
|
|
26
|
+
* catch-and-continue around loader failures.
|
|
28
27
|
*/
|
|
29
28
|
import type { RuntimeManifest } from './runtime-catalog.js';
|
|
30
29
|
import type { SqliteVFS } from '../vfs/sqlite-vfs.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clang-runner.d.ts","sourceRoot":"","sources":["../../src/runtime/clang-runner.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"clang-runner.d.ts","sourceRoot":"","sources":["../../src/runtime/clang-runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD,4DAA4D;AAC5D,wBAAgB,sBAAsB,CAAC,IAAI,EAAE;IAC3C,QAAQ,EAAE,YAAY,CAAC;IACvB,GAAG,EAAE,SAAS,CAAC;CAChB,GAAG,CAAC,QAAQ,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,KAC7F,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,MAAM,CAAC,CAqShC;AAqZD,eAAO,MAAM,qBAAqB,imXA4UjC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* clang-runner.ts —
|
|
2
|
+
* clang-runner.ts — compile, link, and execute C programs as wasm32-wasi.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Architecture (compile-link-run, two facet calls):
|
|
5
5
|
*
|
|
6
6
|
* compile : clang.wasm + memfs.wasm + sysroot subset for C includes
|
|
7
7
|
* + user .c → produces .o bytes (returned to supervisor).
|
|
@@ -11,8 +11,7 @@
|
|
|
11
11
|
* write : final .wasm flushed to user VFS at the requested path.
|
|
12
12
|
*
|
|
13
13
|
* Splitting compile and link into separate LOADER calls keeps each
|
|
14
|
-
* call under the empirical
|
|
15
|
-
* path B). Each ships:
|
|
14
|
+
* call under the empirical loader payload ceiling. Each ships:
|
|
16
15
|
*
|
|
17
16
|
* - compile: 31 MiB clang.wasm + 0.35 MiB memfs + ~1.3 MiB sysroot
|
|
18
17
|
* subset (C includes) = ~32.6 MiB.
|
|
@@ -23,8 +22,8 @@
|
|
|
23
22
|
* parser. The full 9.3 MiB sysroot.tar is parsed once per compile;
|
|
24
23
|
* only the files matching the role's prefix-allowlist are forwarded.
|
|
25
24
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
25
|
+
* Dispatch stays direct: no sleeps, no caller-side retries, and no
|
|
26
|
+
* catch-and-continue around loader failures.
|
|
28
27
|
*/
|
|
29
28
|
/** Build the runner factory. Closes over facetMgr + vfs. */
|
|
30
29
|
export function makeClangRunnerFactory(deps) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"esbuild-service.d.ts","sourceRoot":"","sources":["../../src/runtime/esbuild-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAItD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,eAAe,OAAO,CAAC;AAIpC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wB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AChC,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC/B,SAAS,CAAC,EAAE,OAAO,CAAC;KACrB,GACA,OAAO,CAAC,WAAW,CAAC;IA0CvB;;;;OAIG;IACH,OAAO,CAAC,aAAa;IA4UrB,IAAI,aAAa,YAA+B;CACjD"}
|
|
@@ -537,7 +537,6 @@ function convertEsmImportsToRequire(src) {
|
|
|
537
537
|
// CLASSIFY (is this an import line?) and the original line to
|
|
538
538
|
// EXTRACT the actual import shape (specifier, bindings).
|
|
539
539
|
//
|
|
540
|
-
// See .seal-internal/2026-05-11-sk-mjs-fix/audit.md.
|
|
541
540
|
const strippedLines = stripCommentsAndStrings(src).split('\n');
|
|
542
541
|
const requires = [];
|
|
543
542
|
const bodyLines = [];
|
|
@@ -629,7 +628,6 @@ function convertEsmImportsToRequire(src) {
|
|
|
629
628
|
// SyntaxError "Unexpected token 'export'" at facet pre-compile.
|
|
630
629
|
//
|
|
631
630
|
// Rewrite each top-level export to a CJS-compatible equivalent (see
|
|
632
|
-
// .seal-internal/2026-05-11-sk-exports-fix/audit.md for shape table).
|
|
633
631
|
// Same defences as imports:
|
|
634
632
|
// - String-content masking (template-literal exports don't trigger)
|
|
635
633
|
// - $-aware identifier regex ([\w$]+, esbuild emits foo$1 ids)
|
|
@@ -1003,7 +1001,6 @@ export class EsbuildService {
|
|
|
1003
1001
|
// user code has no .catch() (e.g. create-astro.mjs's
|
|
1004
1002
|
// `import('./dist/index.js').then(({main}) => main())`), the
|
|
1005
1003
|
// rejection is unhandled and the facet exits silently
|
|
1006
|
-
// exitCode=0. See .seal-internal/2026-05-11-astro-silent-exit/audit.md.
|
|
1007
1004
|
supported: { 'dynamic-import': false },
|
|
1008
1005
|
});
|
|
1009
1006
|
const { requires, body } = convertEsmImportsToRequire(pass1.code);
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
* Bare `@remix-run/react` without `@remix-run/dev` falls through to step 7
|
|
29
29
|
* — it's a runtime dep alone, not a Remix v2 vite-plugin project.
|
|
30
30
|
*
|
|
31
|
-
* See audit/sections/W11-plan.md §4 for the full spec + rationale.
|
|
32
31
|
*/
|
|
33
32
|
export type Framework = 'next' | 'astro' | 'nuxt' | 'remix' | 'sveltekit' | 'vite' | 'wrangler' | 'unknown';
|
|
34
33
|
export type DevCommand = 'next-cli' | 'astro-cli' | 'nuxt-cli' | 'remix-cli' | 'sveltekit-vite' | 'vite-real' | 'wrangler-dev' | 'generic';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"framework-detect.d.ts","sourceRoot":"","sources":["../../src/runtime/framework-detect.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"framework-detect.d.ts","sourceRoot":"","sources":["../../src/runtime/framework-detect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,OAAO,GACP,MAAM,GACN,OAAO,GACP,WAAW,GACX,MAAM,GACN,UAAU,GACV,SAAS,CAAC;AAEd,MAAM,MAAM,UAAU,GAClB,UAAU,GACV,WAAW,GACX,UAAU,GACV,WAAW,GACX,gBAAgB,GAChB,WAAW,GACX,cAAc,GACd,SAAS,CAAC;AAEd,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE;QACH,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACtC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACzC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAClC,CAAC;IACF,2EAA2E;IAC3E,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACnB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvC;AAED,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,SAAS,CAAC;IACrB,mDAAmD;IACnD,UAAU,EAAE,MAAM,CAAC;IACnB,wEAAwE;IACxE,MAAM,EAAE,MAAM,CAAC;IACf,yDAAyD;IACzD,UAAU,EAAE,UAAU,CAAC;CACxB;AA2BD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,WAAW,GAAG,YAAY,CAsBhE;AAwGD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAK3D"}
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
* Bare `@remix-run/react` without `@remix-run/dev` falls through to step 7
|
|
29
29
|
* — it's a runtime dep alone, not a Remix v2 vite-plugin project.
|
|
30
30
|
*
|
|
31
|
-
* See audit/sections/W11-plan.md §4 for the full spec + rationale.
|
|
32
31
|
*/
|
|
33
32
|
const WRANGLER_CONFIG_FILES = ['wrangler.toml', 'wrangler.jsonc', 'wrangler.json'];
|
|
34
33
|
const VITE_CONFIG_FILES = ['vite.config.ts', 'vite.config.js', 'vite.config.mjs', 'vite.config.cjs'];
|
|
@@ -103,7 +103,7 @@ export interface RunFreshOpts {
|
|
|
103
103
|
*/
|
|
104
104
|
export declare function runFresh(facetMgr: FacetManager, code: string, opts: RunFreshOpts): Promise<RunFreshResult>;
|
|
105
105
|
/**
|
|
106
|
-
* BACKWARD-COMPAT shim. The
|
|
106
|
+
* BACKWARD-COMPAT shim. The child-process isolation design's `runNodeScript` is now an
|
|
107
107
|
* alias for `runFresh` so the call sites in src/session/init.ts don't
|
|
108
108
|
* need to change in this commit.
|
|
109
109
|
*/
|
|
@@ -187,7 +187,7 @@ export async function runFresh(facetMgr, code, opts) {
|
|
|
187
187
|
};
|
|
188
188
|
}
|
|
189
189
|
/**
|
|
190
|
-
* BACKWARD-COMPAT shim. The
|
|
190
|
+
* BACKWARD-COMPAT shim. The child-process isolation design's `runNodeScript` is now an
|
|
191
191
|
* alias for `runFresh` so the call sites in src/session/init.ts don't
|
|
192
192
|
* need to change in this commit.
|
|
193
193
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-shims.d.ts","sourceRoot":"","sources":["../../src/runtime/node-shims.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AA2BH,wBAAgB,iBAAiB,IAAI,MAAM,
|
|
1
|
+
{"version":3,"file":"node-shims.d.ts","sourceRoot":"","sources":["../../src/runtime/node-shims.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AA2BH,wBAAgB,iBAAiB,IAAI,MAAM,CAu4F1C"}
|