Skip to content

Commit e0ad820

Browse files
committed
rm tanstack start
1 parent 459f5b0 commit e0ad820

14 files changed

Lines changed: 528 additions & 258 deletions

File tree

‎.changeset/config.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@executor/plugin-keychain",
2727
"@executor/plugin-mcp",
2828
"@executor/plugin-onepassword",
29-
"@executor/plugin-openapi"
29+
"@executor/plugin-openapi",
30+
"@executor/marketing"
3031
]
3132
}

‎.changeset/pre.json‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"mode": "pre",
3+
"tag": "beta",
4+
"initialVersions": {
5+
"executor": "1.4.2",
6+
"@executor/cloud": "1.4.0",
7+
"@executor/desktop": "1.4.0",
8+
"@executor/local": "1.4.0",
9+
"@executor/marketing": "0.0.1",
10+
"@executor/api": "1.4.0",
11+
"@executor/config": "1.4.0",
12+
"@executor/execution": "1.4.0",
13+
"@executor/sdk": "1.4.0",
14+
"@executor/storage-file": "1.4.0",
15+
"@executor/storage-postgres": "1.4.0",
16+
"@executor/host-mcp": "1.4.0",
17+
"@executor/codemode-core": "1.4.0",
18+
"@executor/ir": "1.4.0",
19+
"@executor/runtime-deno-subprocess": "0.0.1",
20+
"@executor/runtime-quickjs": "1.4.0",
21+
"@executor/runtime-secure-exec": "0.0.1",
22+
"@executor/plugin-file-secrets": "1.4.0",
23+
"@executor/plugin-google-discovery": "1.4.0",
24+
"@executor/plugin-graphql": "1.4.0",
25+
"@executor/plugin-keychain": "1.4.0",
26+
"@executor/plugin-mcp": "1.4.0",
27+
"@executor/plugin-onepassword": "1.4.0",
28+
"@executor/plugin-openapi": "1.4.0",
29+
"@executor/react": "1.4.0"
30+
},
31+
"changesets": []
32+
}

‎.changeset/purple-jokes-rest.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"executor": patch
3+
---
4+
5+
Secure exec and improve web app serving

‎apps/cli/src/main.ts‎

Lines changed: 13 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import * as Option from "effect/Option";
2828
import * as Cause from "effect/Cause";
2929

3030
import { ExecutorApi } from "@executor/api";
31-
import { createServerHandlers, runMcpStdioServer, getExecutor } from "@executor/local";
31+
import { startServer, runMcpStdioServer, getExecutor } from "@executor/local";
3232

3333
// ---------------------------------------------------------------------------
3434
// Constants
@@ -39,9 +39,6 @@ const { version: CLI_VERSION } = await import("../package.json");
3939
const DEFAULT_PORT = 4788;
4040
const DEFAULT_BASE_URL = `http://localhost:${DEFAULT_PORT}`;
4141

42-
// Embedded web UI — baked into compiled binaries via `with { type: "file" }`
43-
import embeddedWebUI from "./embedded-web-ui.gen";
44-
4542
// ---------------------------------------------------------------------------
4643
// Helpers
4744
// ---------------------------------------------------------------------------
@@ -57,38 +54,13 @@ const waitForShutdownSignal = () =>
5754
});
5855
});
5956

60-
const appendUrlPath = (baseUrl: string, pathname: string): string =>
61-
new URL(pathname, baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`).toString();
62-
63-
const renderSessionSummary = (kind: "web" | "mcp", baseUrl: string): string => {
64-
const displayKind = kind === "mcp" ? "MCP" : "web";
65-
const primaryLabel = kind === "web" ? "Web" : "MCP";
66-
const primaryUrl = kind === "web" ? baseUrl : appendUrlPath(baseUrl, "mcp");
67-
const secondaryLabel = kind === "web" ? "MCP" : "Web";
68-
const secondaryUrl = kind === "web" ? appendUrlPath(baseUrl, "mcp") : baseUrl;
69-
const guidance =
70-
kind === "web"
71-
? "Keep this process running while you use the browser session."
72-
: "Use this MCP URL in your client and keep this process running.";
73-
74-
return [
75-
`Executor ${displayKind} session is ready.`,
76-
`${primaryLabel}: ${primaryUrl}`,
77-
`${secondaryLabel}: ${secondaryUrl}`,
78-
`OpenAPI: ${appendUrlPath(baseUrl, "api/docs")}`,
79-
"",
80-
guidance,
81-
"Press Ctrl+C to stop.",
82-
].join("\n");
83-
};
84-
8557
// ---------------------------------------------------------------------------
8658
// Background server management
8759
// ---------------------------------------------------------------------------
8860

8961
const isServerReachable = async (baseUrl: string): Promise<boolean> => {
9062
try {
91-
const res = await fetch(`${baseUrl}/api/docs`, { signal: AbortSignal.timeout(2000) });
63+
const res = await fetch(`${baseUrl}/api/scope`, { signal: AbortSignal.timeout(2000) });
9264
return res.ok;
9365
} catch {
9466
return false;
@@ -133,121 +105,27 @@ const ensureServer = (baseUrl: string) =>
133105
// ---------------------------------------------------------------------------
134106

135107
const makeApiClient = (baseUrl: string) =>
136-
HttpApiClient.make(ExecutorApi, { baseUrl }).pipe(
108+
HttpApiClient.make(ExecutorApi, { baseUrl: `${baseUrl}/api` }).pipe(
137109
Effect.provide(FetchHttpClient.layer),
138110
);
139111

140112
// ---------------------------------------------------------------------------
141-
// Static file serving from embedded web UI
142-
// ---------------------------------------------------------------------------
143-
144-
const WEB_DIST_DIR = resolve(import.meta.dirname, "../../local/dist");
145-
146-
const serveStatic = async (pathname: string): Promise<Response | null> => {
147-
const key = pathname.replace(/^\//, "");
148-
149-
// Compiled binary: serve from embedded bunfs
150-
if (embeddedWebUI) {
151-
const match = embeddedWebUI[key] ?? embeddedWebUI["index.html"] ?? null;
152-
if (!match) return null;
153-
const file = Bun.file(match);
154-
return new Response(file, {
155-
headers: { "content-type": file.type || "application/octet-stream" },
156-
});
157-
}
158-
159-
// Dev mode: serve from apps/local/dist on disk
160-
const filePath = resolve(WEB_DIST_DIR, key);
161-
if (!filePath.startsWith(WEB_DIST_DIR)) return null;
162-
163-
const file = Bun.file(filePath);
164-
if (await file.exists()) {
165-
return new Response(file, {
166-
headers: { "content-type": file.type || "application/octet-stream" },
167-
});
168-
}
169-
170-
// SPA fallback
171-
const index = Bun.file(resolve(WEB_DIST_DIR, "index.html"));
172-
if (await index.exists()) {
173-
return new Response(index, { headers: { "content-type": "text/html" } });
174-
}
175-
176-
return null;
177-
};
178-
179-
// ---------------------------------------------------------------------------
180-
// Host-header allowlist — blocks DNS rebinding attacks
113+
// Foreground session
181114
// ---------------------------------------------------------------------------
182115

183-
const ALLOWED_HOSTS = new Set([
184-
"localhost",
185-
"127.0.0.1",
186-
"[::1]",
187-
"::1",
188-
]);
189-
190-
const isAllowedHost = (request: Request): boolean => {
191-
const host = request.headers.get("host");
192-
if (!host) return true; // no host header (e.g. HTTP/1.0) — allow
193-
// Strip port ("localhost:4788" → "localhost")
194-
const hostname = host.replace(/:\d+$/, "");
195-
return ALLOWED_HOSTS.has(hostname);
196-
};
197-
198-
// ---------------------------------------------------------------------------
199-
// Foreground session — API + MCP + Web UI on one Bun.serve()
200-
// ---------------------------------------------------------------------------
201-
202-
const runForegroundSession = (input: { kind: "web" | "mcp"; port: number }) =>
116+
const runForegroundSession = (input: { port: number }) =>
203117
Effect.gen(function* () {
204-
const handlers = yield* Effect.promise(() => createServerHandlers());
205-
206-
// Bind to loopback only — one server per address family so both
207-
// "localhost" (which may resolve to ::1 on Windows) and 127.0.0.1 work,
208-
// without exposing the server on the LAN.
209-
const fetch = async (request: Request): Promise<Response> => {
210-
if (!isAllowedHost(request)) {
211-
return new Response("Forbidden", { status: 403 });
212-
}
213-
214-
const url = new URL(request.url);
215-
216-
if (url.pathname.startsWith("/mcp")) {
217-
return handlers.mcp.handleRequest(request);
218-
}
219-
220-
if (url.pathname.startsWith("/api/") || url.pathname === "/api") {
221-
return handlers.api.handler(request);
222-
}
223-
224-
const staticResponse = await serveStatic(url.pathname);
225-
if (staticResponse) return staticResponse;
226-
227-
return new Response("Not Found", { status: 404 });
228-
};
229-
230-
const serverV4 = Bun.serve({ port: input.port, hostname: "127.0.0.1", fetch });
231-
232-
// IPv6 loopback — may fail on systems without IPv6; that's fine.
233-
let serverV6: ReturnType<typeof Bun.serve> | null = null;
234-
try {
235-
serverV6 = Bun.serve({ port: input.port, hostname: "::1", fetch });
236-
} catch {
237-
// IPv6 not available — continue with IPv4 only
238-
}
239-
240-
const server = serverV4;
118+
const server = yield* Effect.promise(() => startServer({ port: input.port }));
241119

242120
const baseUrl = `http://localhost:${server.port}`;
243-
console.log(renderSessionSummary(input.kind, baseUrl));
121+
console.log(`Executor is ready.`);
122+
console.log(`Web: ${baseUrl}`);
123+
console.log(`MCP: ${baseUrl}/mcp`);
124+
console.log(`OpenAPI: ${baseUrl}/api/docs`);
125+
console.log(`\nPress Ctrl+C to stop.`);
244126

245127
yield* waitForShutdownSignal();
246-
247-
serverV4.stop(true);
248-
serverV6?.stop(true);
249-
yield* Effect.promise(() => handlers.mcp.close());
250-
yield* Effect.promise(() => handlers.api.dispose());
128+
yield* Effect.promise(() => server.stop());
251129
});
252130

253131
// ---------------------------------------------------------------------------
@@ -387,7 +265,7 @@ const webCommand = Command.make(
387265
},
388266
({ port, scope }) => Effect.gen(function* () {
389267
applyScope(scope);
390-
yield* runForegroundSession({ kind: "web", port });
268+
yield* runForegroundSession({ port });
391269
}),
392270
).pipe(Command.withDescription("Start a foreground web session"));
393271

‎apps/local/index.html‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
6+
<title>Executor</title>
7+
<link rel="preconnect" href="https://fonts.googleapis.com" />
8+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
9+
<link
10+
rel="stylesheet"
11+
href="https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300..700;1,9..40,300..700&family=Instrument+Serif&family=JetBrains+Mono:wght@400;500&display=swap"
12+
/>
13+
</head>
14+
<body>
15+
<div id="root"></div>
16+
<script type="module" src="/src/entry-client.tsx"></script>
17+
</body>
18+
</html>

‎apps/local/package.json‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
"@executor/storage-file": "workspace:*",
2929
"@modelcontextprotocol/sdk": "^1.12.1",
3030
"@tanstack/react-router": "catalog:",
31-
"@tanstack/react-start": "catalog:",
3231
"effect": "catalog:",
3332
"react": "catalog:",
3433
"react-dom": "catalog:"
3534
},
3635
"devDependencies": {
3736
"@tailwindcss/vite": "catalog:",
37+
"@tanstack/router-plugin": "^1.167.12",
3838
"@types/node": "catalog:",
3939
"@types/react": "catalog:",
4040
"@types/react-dom": "catalog:",
@@ -46,7 +46,8 @@
4646
},
4747
"scripts": {
4848
"dev": "portless run --name executor-local bunx --bun vite dev",
49-
"build": "vite build",
49+
"build": "bunx --bun vite build",
50+
"start": "bun run src/serve.ts",
5051
"typecheck": "tsc --noEmit"
5152
}
5253
}

‎apps/local/src/entry-client.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from "react";
2+
import ReactDOM from "react-dom/client";
3+
import { RouterProvider } from "@tanstack/react-router";
4+
import { getRouter } from "./router";
5+
import "@executor/react/globals.css";
6+
7+
const router = getRouter();
8+
9+
ReactDOM.createRoot(document.getElementById("root")!).render(
10+
<RouterProvider router={router} />,
11+
);

‎apps/local/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { createServerHandlers, getServerHandlers, disposeServerHandlers, type ServerHandlers } from "./server/main";
22
export { createExecutorHandle, disposeExecutor, getExecutor, reloadExecutor, type ExecutorHandle, type LocalExecutor } from "./server/executor";
33
export { createMcpRequestHandler, runMcpStdioServer, type McpRequestHandler } from "./server/mcp";
4+
export { startServer, type StartServerOptions, type ServerInstance } from "./serve";

‎apps/local/src/routeTree.gen.ts‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,3 @@ const rootRouteChildren: RootRouteChildren = {
145145
export const routeTree = rootRouteImport
146146
._addFileChildren(rootRouteChildren)
147147
._addFileTypes<FileRouteTypes>()
148-
149-
import type { getRouter } from './router.tsx'
150-
import type { startInstance } from './start.ts'
151-
declare module '@tanstack/react-start' {
152-
interface Register {
153-
ssr: true
154-
router: Awaited<ReturnType<typeof getRouter>>
155-
config: Awaited<ReturnType<typeof startInstance.getOptions>>
156-
}
157-
}

‎apps/local/src/routes/__root.tsx‎

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,12 @@
11
import React from "react";
2-
import { HeadContent, Outlet, Scripts, createRootRoute } from "@tanstack/react-router";
2+
import { Outlet, createRootRoute } from "@tanstack/react-router";
33
import { ExecutorProvider } from "@executor/react/api/provider";
44
import { Shell } from "../web/shell";
5-
import appCss from "@executor/react/globals.css?url";
65

76
export const Route = createRootRoute({
8-
head: () => ({
9-
meta: [
10-
{ charSet: "utf-8" },
11-
{ name: "viewport", content: "width=device-width, initial-scale=1" },
12-
{ title: "Executor" },
13-
],
14-
links: [
15-
{ rel: "preconnect", href: "https://fonts.googleapis.com" },
16-
{ rel: "preconnect", href: "https://fonts.gstatic.com", crossOrigin: "anonymous" },
17-
{ rel: "stylesheet", href: "https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300..700;1,9..40,300..700&family=Instrument+Serif&family=JetBrains+Mono:wght@400;500&display=swap" },
18-
{ rel: "stylesheet", href: appCss },
19-
],
20-
scripts: import.meta.env.DEV
21-
? [{ src: "https://ui.sh/ui-picker.js" }]
22-
: [],
23-
}),
247
component: RootComponent,
25-
shellComponent: RootDocument,
268
});
279

28-
function RootDocument({ children }: { children: React.ReactNode }) {
29-
return (
30-
<html lang="en">
31-
<head>
32-
<HeadContent />
33-
</head>
34-
<body>
35-
{children}
36-
<Scripts />
37-
</body>
38-
</html>
39-
);
40-
}
41-
4210
function RootComponent() {
4311
return (
4412
<ExecutorProvider>

0 commit comments

Comments
 (0)