@flowdular/sandbox 0.2.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 (139) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +696 -0
  3. package/bin/flowdular-sandbox.mjs +394 -0
  4. package/bin/register-types.mjs +53 -0
  5. package/dist/client/assets/App-ClMOrpyg.js +11 -0
  6. package/dist/client/assets/PreviewHost-BHiHrfbQ.js +1 -0
  7. package/dist/client/assets/auto-buGEq6de.js +3 -0
  8. package/dist/client/assets/ibm-plex-mono-cyrillic-400-normal-BSMlKf0J.woff2 +0 -0
  9. package/dist/client/assets/ibm-plex-mono-cyrillic-400-normal-CEL4l2ZJ.woff +0 -0
  10. package/dist/client/assets/ibm-plex-mono-cyrillic-500-normal-Ael50iVv.woff +0 -0
  11. package/dist/client/assets/ibm-plex-mono-cyrillic-500-normal-Bq9vWWag.woff2 +0 -0
  12. package/dist/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-DMdlQ8Kv.woff +0 -0
  13. package/dist/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-xuaO2J-f.woff2 +0 -0
  14. package/dist/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BIfNGwUT.woff +0 -0
  15. package/dist/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BqneJy0T.woff2 +0 -0
  16. package/dist/client/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
  17. package/dist/client/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
  18. package/dist/client/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
  19. package/dist/client/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
  20. package/dist/client/assets/ibm-plex-mono-latin-ext-400-normal-BmRBH3aV.woff2 +0 -0
  21. package/dist/client/assets/ibm-plex-mono-latin-ext-400-normal-D3D2R8hC.woff +0 -0
  22. package/dist/client/assets/ibm-plex-mono-latin-ext-500-normal-CAhNIIs5.woff2 +0 -0
  23. package/dist/client/assets/ibm-plex-mono-latin-ext-500-normal-CZ70TYgx.woff +0 -0
  24. package/dist/client/assets/ibm-plex-mono-vietnamese-400-normal-BulugwFq.woff2 +0 -0
  25. package/dist/client/assets/ibm-plex-mono-vietnamese-400-normal-DDuiU_S-.woff +0 -0
  26. package/dist/client/assets/ibm-plex-mono-vietnamese-500-normal-C8zxqsMH.woff +0 -0
  27. package/dist/client/assets/ibm-plex-mono-vietnamese-500-normal-DZ4AoWbu.woff2 +0 -0
  28. package/dist/client/assets/ibm-plex-sans-cyrillic-ext-wght-normal-d45eAU9y.woff2 +0 -0
  29. package/dist/client/assets/ibm-plex-sans-cyrillic-wght-normal-BAAhND-U.woff2 +0 -0
  30. package/dist/client/assets/ibm-plex-sans-greek-wght-normal-CmyJS8uq.woff2 +0 -0
  31. package/dist/client/assets/ibm-plex-sans-latin-ext-wght-normal-CIII54If.woff2 +0 -0
  32. package/dist/client/assets/ibm-plex-sans-latin-wght-normal-IvpUvPa2.woff2 +0 -0
  33. package/dist/client/assets/ibm-plex-sans-vietnamese-wght-normal-Dg1JeJN0.woff2 +0 -0
  34. package/dist/client/assets/index-CvwhlQ87.js +4 -0
  35. package/dist/client/assets/styles-BPWaGf55.js +3 -0
  36. package/dist/client/assets/styles-Dx1_KOag.css +1 -0
  37. package/dist/client/favicon.svg +1 -0
  38. package/dist/server/assets/auto-CVGNYyb3.js +12785 -0
  39. package/dist/server/assets/chunk-DDJLRBDX-3OUNo51g.js +4125 -0
  40. package/dist/server/assets/nodefs-DVSI7kG0.js +24 -0
  41. package/dist/server/assets/opfs-ahp-D56iokt1.js +388 -0
  42. package/dist/server/assets/token-Bvaq7Anz.js +55 -0
  43. package/dist/server/assets/token-util-BqSvdIPQ.js +3 -0
  44. package/dist/server/assets/token-util-CktFFT4z.js +494 -0
  45. package/dist/server/entry.js +91671 -0
  46. package/dist/server/favicon.svg +1 -0
  47. package/dist/server/index.html +161 -0
  48. package/index.html +159 -0
  49. package/internal/coding-agent/package.json +44 -0
  50. package/internal/coding-agent/src/drivers/byok.ts +322 -0
  51. package/internal/coding-agent/src/drivers/claude-code.ts +290 -0
  52. package/internal/coding-agent/src/drivers/codex.ts +281 -0
  53. package/internal/coding-agent/src/index.ts +56 -0
  54. package/internal/coding-agent/src/registry.ts +119 -0
  55. package/internal/coding-agent/src/roles/contract.ts +60 -0
  56. package/internal/coding-agent/src/roles/defaults.ts +134 -0
  57. package/internal/coding-agent/src/roles/handoff.ts +41 -0
  58. package/internal/coding-agent/src/roles/registry.ts +156 -0
  59. package/internal/coding-agent/src/roles/skills.ts +72 -0
  60. package/internal/coding-agent/src/roles/sync.ts +88 -0
  61. package/internal/coding-agent/src/types.ts +102 -0
  62. package/internal/coding-agent/src/workspace.ts +275 -0
  63. package/octane.config.ts +36 -0
  64. package/package.json +68 -0
  65. package/public/favicon.svg +1 -0
  66. package/public/og.png +0 -0
  67. package/src/App.tsrx +924 -0
  68. package/src/client/ApprovalHandoff.tsrx +39 -0
  69. package/src/client/ChatPane.tsrx +694 -0
  70. package/src/client/ConnectView.tsrx +86 -0
  71. package/src/client/DiffPane.tsrx +150 -0
  72. package/src/client/EjectModal.tsrx +571 -0
  73. package/src/client/GateResults.tsrx +60 -0
  74. package/src/client/GitHubSettingsModal.tsrx +219 -0
  75. package/src/client/NewSessionForm.tsrx +214 -0
  76. package/src/client/SessionBar.tsrx +151 -0
  77. package/src/client/SessionPicker.tsrx +472 -0
  78. package/src/client/SpecEditor.tsrx +109 -0
  79. package/src/client/SpecReviewCard.tsrx +321 -0
  80. package/src/client/WorkCard.tsrx +128 -0
  81. package/src/client/WorkbenchModal.tsrx +161 -0
  82. package/src/client/WorkspaceMenu.tsrx +100 -0
  83. package/src/client/api.ts +797 -0
  84. package/src/client/attachments.ts +73 -0
  85. package/src/client/dashboard.ts +46 -0
  86. package/src/client/github-settings.ts +48 -0
  87. package/src/client/highlight.ts +105 -0
  88. package/src/client/i18n.ts +32 -0
  89. package/src/client/locales/en.json +466 -0
  90. package/src/client/locales/pl.json +466 -0
  91. package/src/client/session-labels.ts +77 -0
  92. package/src/client/state.ts +108 -0
  93. package/src/index.ts +10 -0
  94. package/src/preview/PreviewHost.tsrx +373 -0
  95. package/src/preview/load-module.ts +16 -0
  96. package/src/server/attachments.ts +308 -0
  97. package/src/server/auto-review.ts +181 -0
  98. package/src/server/checkpoints.ts +90 -0
  99. package/src/server/config.ts +460 -0
  100. package/src/server/dashboard.ts +245 -0
  101. package/src/server/delivery/configuration.ts +193 -0
  102. package/src/server/delivery/git-pr.ts +1473 -0
  103. package/src/server/delivery/index.ts +83 -0
  104. package/src/server/delivery/local.ts +151 -0
  105. package/src/server/delivery/official-modules.ts +516 -0
  106. package/src/server/delivery/plan.ts +218 -0
  107. package/src/server/delivery/policies.ts +239 -0
  108. package/src/server/delivery/record.ts +41 -0
  109. package/src/server/delivery/steps.ts +464 -0
  110. package/src/server/delivery/types.ts +158 -0
  111. package/src/server/dependencies.ts +88 -0
  112. package/src/server/diff.ts +230 -0
  113. package/src/server/gates.ts +388 -0
  114. package/src/server/index.ts +139 -0
  115. package/src/server/path-guard.ts +282 -0
  116. package/src/server/planning.ts +749 -0
  117. package/src/server/platform-client.ts +189 -0
  118. package/src/server/preview-database-host.ts +340 -0
  119. package/src/server/preview-database-protocol.ts +163 -0
  120. package/src/server/preview-database-proxy.ts +356 -0
  121. package/src/server/preview-database.ts +109 -0
  122. package/src/server/preview-ipc.ts +15 -0
  123. package/src/server/preview-modules.ts +83 -0
  124. package/src/server/preview-revision.ts +44 -0
  125. package/src/server/preview-runtime.ts +467 -0
  126. package/src/server/preview-worker-manager.ts +477 -0
  127. package/src/server/preview-worker.ts +168 -0
  128. package/src/server/reference.ts +251 -0
  129. package/src/server/routes.ts +2258 -0
  130. package/src/server/runtime.ts +188 -0
  131. package/src/server/session-owner.ts +23 -0
  132. package/src/server/sessions.ts +849 -0
  133. package/src/server/spec.ts +471 -0
  134. package/src/server/turn-lifecycle.ts +56 -0
  135. package/src/server/turns.ts +993 -0
  136. package/src/server/workspace-install.ts +266 -0
  137. package/src/server/workspace-root.ts +73 -0
  138. package/src/styles.css +1573 -0
  139. package/vite.config.ts +134 -0
@@ -0,0 +1,394 @@
1
+ #!/usr/bin/env node
2
+
3
+ // ../sandbox/bin/flowdular-sandbox.mjs
4
+ import "./register-types.mjs";
5
+ import process2 from "node:process";
6
+ import { dirname, resolve } from "node:path";
7
+ import { fileURLToPath } from "node:url";
8
+ import { createServer } from "vite";
9
+
10
+ // ../dev-console/src/index.mjs
11
+ import { createLogger } from "vite";
12
+ var ansiPattern = /\u001B\[[0-?]*[ -/]*[@-~]/g;
13
+ var ansi = {
14
+ reset: "\x1B[0m",
15
+ brand: "\x1B[1;38;5;42m",
16
+ label: "\x1B[2;37m",
17
+ text: "\x1B[37m",
18
+ success: "\x1B[38;5;42m",
19
+ info: "\x1B[36m",
20
+ warning: "\x1B[33m",
21
+ error: "\x1B[31m",
22
+ muted: "\x1B[90m"
23
+ };
24
+ function shouldUseColor(environment = process.env, isTerminal = process.stdout.isTTY) {
25
+ if (Object.hasOwn(environment, "FORCE_COLOR") && environment.FORCE_COLOR !== "0") {
26
+ return true;
27
+ }
28
+ if (Object.hasOwn(environment, "NO_COLOR")) return false;
29
+ if (environment.TERM === "dumb") return false;
30
+ return Boolean(
31
+ isTerminal || environment.COLORTERM || environment.TERM_PROGRAM
32
+ );
33
+ }
34
+ function createTheme(enabled) {
35
+ const paint = (code) => enabled ? (value) => `${code}${String(value)}${ansi.reset}` : (value) => String(value);
36
+ return {
37
+ enabled,
38
+ brand: paint(ansi.brand),
39
+ label: paint(ansi.label),
40
+ text: paint(ansi.text),
41
+ success: paint(ansi.success),
42
+ info: paint(ansi.info),
43
+ warning: paint(ansi.warning),
44
+ error: paint(ansi.error),
45
+ muted: paint(ansi.muted)
46
+ };
47
+ }
48
+ function formatDevEvent(kind, message, useColor = shouldUseColor()) {
49
+ const theme = createTheme(useColor);
50
+ const label = kind === "process" ? "[octane]" : `[octane:${kind}]`;
51
+ const tone = kind === "error" ? theme.error : kind === "notice" ? theme.warning : kind === "routes" ? theme.success : kind === "reload" ? theme.info : theme.muted;
52
+ return `${tone(label)} ${tone(message)}`;
53
+ }
54
+ function clean(message) {
55
+ return String(message).replace(ansiPattern, "").trim();
56
+ }
57
+ function statusLine(theme, label, value, tone = "text") {
58
+ return ` ${theme.label(label.padEnd(12))}${theme[tone](value)}`;
59
+ }
60
+ function printReady({ title, subtitle, lines, theme }) {
61
+ console.log("");
62
+ console.log(` ${theme.brand(title)} ${theme.muted(subtitle)}`);
63
+ for (const [label, value, tone = "text"] of lines) {
64
+ if (value === null || value === void 0) continue;
65
+ console.log(statusLine(theme, label, value, tone));
66
+ }
67
+ console.log("");
68
+ }
69
+ function createOctaneLogger(verbose, useColor) {
70
+ const viteLogger = createLogger("info", { allowClearScreen: false });
71
+ const warnings = /* @__PURE__ */ new Set();
72
+ let hasWarned = false;
73
+ const warn = (message, options) => {
74
+ hasWarned = true;
75
+ if (verbose) {
76
+ viteLogger.warn(message, options);
77
+ return;
78
+ }
79
+ const normalized = clean(message);
80
+ if (warnings.has(normalized)) return;
81
+ warnings.add(normalized);
82
+ if (warnings.size === 1) {
83
+ console.warn(
84
+ formatDevEvent(
85
+ "notice",
86
+ "Tool warnings are hidden. Restart with --verbose to inspect them.",
87
+ useColor
88
+ )
89
+ );
90
+ }
91
+ };
92
+ return {
93
+ get hasWarned() {
94
+ return hasWarned;
95
+ },
96
+ info(message, options) {
97
+ if (verbose) viteLogger.info(message, options);
98
+ },
99
+ warn,
100
+ warnOnce(message, options) {
101
+ if (verbose) {
102
+ hasWarned = true;
103
+ viteLogger.warnOnce(message, options);
104
+ return;
105
+ }
106
+ if (!warnings.has(clean(message))) warn(message, options);
107
+ },
108
+ error(message, options) {
109
+ console.error(formatDevEvent("error", clean(message), useColor));
110
+ if (verbose && options?.error?.stack) {
111
+ console.error(options.error.stack);
112
+ }
113
+ },
114
+ clearScreen() {
115
+ },
116
+ hasErrorLogged(error) {
117
+ return viteLogger.hasErrorLogged(error);
118
+ }
119
+ };
120
+ }
121
+ function isClientDisconnectLog(values) {
122
+ if (typeof values[0] !== "string") return false;
123
+ if (!values[0].startsWith("[octane] SSR render error:")) return false;
124
+ return values.slice(1).some(
125
+ (value) => value instanceof Error && value.message.includes("client disconnected")
126
+ );
127
+ }
128
+ function installOctaneConsoleBridge(verbose, useColor) {
129
+ const originalLog = console.log.bind(console);
130
+ const originalError = console.error.bind(console);
131
+ console.log = (...values) => {
132
+ const message = values[0];
133
+ if (!verbose && typeof message === "string" && message.startsWith("[@octanejs/vite-plugin]")) {
134
+ const loaded = message.match(/Loaded (\d+) routes/);
135
+ const reloaded = message.match(/Reloaded (\d+) routes/);
136
+ if (loaded) {
137
+ originalLog(
138
+ formatDevEvent("routes", `${loaded[1]} routes loaded`, useColor)
139
+ );
140
+ } else if (reloaded) {
141
+ originalLog(
142
+ formatDevEvent("routes", `${reloaded[1]} routes reloaded`, useColor)
143
+ );
144
+ }
145
+ return;
146
+ }
147
+ originalLog(...values);
148
+ };
149
+ console.error = (...values) => {
150
+ const message = values[0];
151
+ if (!verbose && isClientDisconnectLog(values)) return;
152
+ if (typeof message === "string" && message.startsWith("[@octanejs/vite-plugin]")) {
153
+ originalError(
154
+ formatDevEvent(
155
+ "error",
156
+ message.slice("[@octanejs/vite-plugin]".length).trim(),
157
+ useColor
158
+ ),
159
+ ...values.slice(1)
160
+ );
161
+ return;
162
+ }
163
+ originalError(...values);
164
+ };
165
+ return () => {
166
+ console.log = originalLog;
167
+ console.error = originalError;
168
+ };
169
+ }
170
+ function watchReloads(server, root, useColor) {
171
+ let lastChange = "";
172
+ let lastChangeAt = 0;
173
+ server.watcher.on("change", (path) => {
174
+ const changed = path.startsWith(root) ? path.slice(root.length + 1) : path;
175
+ const now = Date.now();
176
+ if (changed === lastChange && now - lastChangeAt < 100) return;
177
+ lastChange = changed;
178
+ lastChangeAt = now;
179
+ console.log(formatDevEvent("reload", changed, useColor));
180
+ });
181
+ }
182
+
183
+ // ../sandbox/bin/flowdular-sandbox.mjs
184
+ var appRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
185
+ function parseSandboxArguments(argv = []) {
186
+ const options = {
187
+ host: "127.0.0.1",
188
+ port: 4320,
189
+ mode: "loopback",
190
+ workspace: process2.cwd(),
191
+ verbose: process2.env.FD_SANDBOX_VERBOSE === "true",
192
+ help: false
193
+ };
194
+ for (let index = 0; index < argv.length; index += 1) {
195
+ const argument = argv[index];
196
+ if (argument === "--help" || argument === "-h") {
197
+ options.help = true;
198
+ continue;
199
+ }
200
+ if (argument === "--verbose" || argument === "-v") {
201
+ options.verbose = true;
202
+ continue;
203
+ }
204
+ const take = (name) => {
205
+ const inline = argument.startsWith(`--${name}=`) ? argument.slice(name.length + 3) : void 0;
206
+ if (inline !== void 0) return inline;
207
+ if (argument !== `--${name}`) return void 0;
208
+ const value = argv[index + 1];
209
+ if (!value || value.startsWith("--")) {
210
+ throw new Error(`--${name} requires a value.`);
211
+ }
212
+ index += 1;
213
+ return value;
214
+ };
215
+ const host = take("host");
216
+ if (host !== void 0) {
217
+ options.host = host;
218
+ continue;
219
+ }
220
+ const port = take("port");
221
+ if (port !== void 0) {
222
+ options.port = Number(port);
223
+ continue;
224
+ }
225
+ const workspace = take("workspace");
226
+ if (workspace !== void 0) {
227
+ options.workspace = resolve(workspace);
228
+ continue;
229
+ }
230
+ const mode = take("mode");
231
+ if (mode !== void 0) {
232
+ if (mode !== "loopback" && mode !== "self-hosted") {
233
+ throw new Error("--mode must be loopback or self-hosted.");
234
+ }
235
+ options.mode = mode;
236
+ continue;
237
+ }
238
+ throw new Error(`Unknown sandbox option: ${argument}`);
239
+ }
240
+ if (!Number.isInteger(options.port) || options.port < 1 || options.port > 65535) {
241
+ throw new Error("--port must be an integer between 1 and 65535.");
242
+ }
243
+ if (options.mode === "loopback" && !isLoopbackHost(options.host)) {
244
+ options.mode = "self-hosted";
245
+ }
246
+ return options;
247
+ }
248
+ function isLoopbackHost(host) {
249
+ return host === "127.0.0.1" || host === "localhost" || host === "::1";
250
+ }
251
+ function printHelp() {
252
+ console.log(`Flowdular sandbox
253
+
254
+ Usage: npx @flowdular/sandbox [options]
255
+
256
+ Options:
257
+ --workspace <path> Flowdular workspace to use (default: current directory)
258
+ --host <host> Bind address (default: 127.0.0.1)
259
+ --port <port> HTTP port (default: 4320)
260
+ --mode <mode> loopback or self-hosted (default: loopback)
261
+ -v, --verbose Show Vite and tool warnings
262
+ -h, --help Show this help`);
263
+ }
264
+ async function sandboxStatus(server, workspace) {
265
+ const local = server.resolvedUrls?.local?.[0] ?? "http://127.0.0.1:4320/";
266
+ try {
267
+ const state = await fetch(new URL("/sandbox/api/state", local), {
268
+ headers: { accept: "application/json" }
269
+ }).then((response) => response.json());
270
+ if (state.error) {
271
+ return {
272
+ platform: `${state.configuration?.platformUrl ?? "not configured"} \xB7 sign in required`,
273
+ connected: false,
274
+ agents: "after sign-in",
275
+ hasAgents: false,
276
+ sessions: 0
277
+ };
278
+ }
279
+ const offered = (state.drivers ?? []).filter((driver) => driver.offered).map((driver) => driver.label);
280
+ const tenant = state.connection?.authority?.principal?.tenantName ?? "connected";
281
+ return {
282
+ platform: state.connection?.connected ? `${state.configuration.platformUrl} \xB7 ${tenant}` : `${state.configuration?.platformUrl ?? "not configured"} \xB7 not connected`,
283
+ connected: Boolean(state.connection?.connected),
284
+ agents: offered.length > 0 ? offered.join(" \xB7 ") : "none available",
285
+ hasAgents: offered.length > 0,
286
+ sessions: (state.sessions ?? []).length
287
+ };
288
+ } catch {
289
+ return {
290
+ platform: "unavailable",
291
+ connected: false,
292
+ agents: "unknown",
293
+ hasAgents: false,
294
+ sessions: 0
295
+ };
296
+ }
297
+ }
298
+ async function startSandbox(argv = process2.argv.slice(2)) {
299
+ const options = parseSandboxArguments(argv);
300
+ const useColor = shouldUseColor();
301
+ const theme = createTheme(useColor);
302
+ if (options.help) {
303
+ printHelp(theme);
304
+ return null;
305
+ }
306
+ process2.env.FD_SANDBOX_WORKSPACE = options.workspace;
307
+ process2.env.FD_SANDBOX_MODE = options.mode;
308
+ process2.env.FD_SANDBOX_PORT = String(options.port);
309
+ const startedAt = performance.now();
310
+ const restoreConsole = installOctaneConsoleBridge(options.verbose, useColor);
311
+ const logger = createOctaneLogger(options.verbose, useColor);
312
+ let server;
313
+ try {
314
+ server = await createServer({
315
+ root: appRoot,
316
+ configFile: resolve(appRoot, "vite.config.ts"),
317
+ customLogger: logger,
318
+ clearScreen: false,
319
+ server: { host: options.host, port: options.port, strictPort: true }
320
+ });
321
+ await server.listen();
322
+ } catch (error) {
323
+ restoreConsole();
324
+ throw error;
325
+ }
326
+ const status = await sandboxStatus(server, options.workspace);
327
+ printReady({
328
+ title: "FLOWDULAR SANDBOX",
329
+ subtitle: "agentic workspace",
330
+ theme,
331
+ lines: [
332
+ ["ready", `${Math.round(performance.now() - startedAt)} ms`, "success"],
333
+ [
334
+ "local",
335
+ server.resolvedUrls?.local?.[0] ?? `http://${options.host}:${options.port}/`,
336
+ "info"
337
+ ],
338
+ ...(server.resolvedUrls?.network ?? []).map((url) => [
339
+ "network",
340
+ url,
341
+ "info"
342
+ ]),
343
+ [
344
+ "mode",
345
+ options.mode,
346
+ options.mode === "loopback" ? "success" : "warning"
347
+ ],
348
+ ["workspace", options.workspace, "muted"],
349
+ [
350
+ "sessions",
351
+ status.sessions === 1 ? "1 open" : `${status.sessions} open`,
352
+ "text"
353
+ ],
354
+ ["platform", status.platform, status.connected ? "success" : "warning"],
355
+ ["agents", status.agents, status.hasAgents ? "success" : "warning"],
356
+ ["reload", "TSRX \xB7 TypeScript \xB7 CSS", "info"],
357
+ [
358
+ "diagnostics",
359
+ options.verbose ? "verbose" : "quiet \xB7 use --verbose",
360
+ options.verbose ? "warning" : "muted"
361
+ ]
362
+ ]
363
+ });
364
+ watchReloads(server, appRoot, useColor);
365
+ const close = async () => {
366
+ console.log(`
367
+ ${formatDevEvent("process", "Sandbox stopped.", useColor)}`);
368
+ await server.close();
369
+ restoreConsole();
370
+ process2.exit(0);
371
+ };
372
+ process2.once("SIGINT", () => void close());
373
+ process2.once("SIGTERM", () => void close());
374
+ return server;
375
+ }
376
+ if (process2.argv[1] && resolve(process2.argv[1]) === fileURLToPath(import.meta.url)) {
377
+ startSandbox().catch((error) => {
378
+ console.error(
379
+ formatDevEvent(
380
+ "error",
381
+ error instanceof Error ? error.message : String(error)
382
+ )
383
+ );
384
+ if (process2.argv.includes("--verbose") && error instanceof Error) {
385
+ console.error(error.stack);
386
+ }
387
+ process2.exitCode = 1;
388
+ });
389
+ }
390
+ export {
391
+ isLoopbackHost,
392
+ parseSandboxArguments,
393
+ startSandbox
394
+ };
@@ -0,0 +1,53 @@
1
+ import { readFileSync, realpathSync } from 'node:fs';
2
+ import {
3
+ createRequire,
4
+ registerHooks,
5
+ stripTypeScriptTypes,
6
+ } from 'node:module';
7
+ import { dirname, resolve, sep } from 'node:path';
8
+ import { fileURLToPath } from 'node:url';
9
+
10
+ // SDK server entrypoints are source TypeScript. Node deliberately does not strip
11
+ // types in node_modules, even with --experimental-transform-types. Transform only
12
+ // this application's and its SDK's source; never install a global package loader.
13
+ const packageRoot = realpathSync(fileURLToPath(new URL('..', import.meta.url)));
14
+ const roots = [packageRoot];
15
+ try {
16
+ const require = createRequire(import.meta.url);
17
+ roots.push(
18
+ realpathSync(dirname(require.resolve('@flowdular/sdk/package.json'))),
19
+ );
20
+ } catch (error) {
21
+ if (
22
+ error.code !== 'MODULE_NOT_FOUND' &&
23
+ error.code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED'
24
+ )
25
+ throw error;
26
+ // The authoring workspace uses ordinary, linked source packages.
27
+ }
28
+ // The host resolves the consumer's SDK before applying worker permissions. This
29
+ // avoids granting the worker access to platform/package.json or following its
30
+ // dependency links outside the permitted physical package roots.
31
+ if (process.env.FD_INTERNAL_SANDBOX_SDK_ROOT)
32
+ roots.push(realpathSync(process.env.FD_INTERNAL_SANDBOX_SDK_ROOT));
33
+
34
+ registerHooks({
35
+ load(url, context, nextLoad) {
36
+ if (!url.startsWith('file:')) return nextLoad(url, context);
37
+ const path = resolve(fileURLToPath(url));
38
+ if (
39
+ !path.endsWith('.ts') ||
40
+ !roots.some((root) => path.startsWith(root + sep))
41
+ ) {
42
+ return nextLoad(url, context);
43
+ }
44
+ return {
45
+ format: 'module',
46
+ source: stripTypeScriptTypes(readFileSync(path, 'utf8'), {
47
+ mode: 'transform',
48
+ sourceUrl: url,
49
+ }),
50
+ shortCircuit: true,
51
+ };
52
+ },
53
+ });