History

fix markdown rendering, scope to current folder

Rhys Sullivan committed 7 months ago

Commit 996904a1 parent df846c129 files · +323 −118Browse files

Unified · Split

29 files
  1. apps/server/src/handlers/scope.ts +20 −0
  2. apps/server/src/main.ts +2 −0
  3. apps/server/src/services/executor.ts +9 −7
  4. apps/web/src/lib/use-scope.ts +1 −0
  5. apps/web/src/pages/secrets.tsx +9 −6
  6. apps/web/src/pages/source-detail.tsx +18 −11
  7. apps/web/src/pages/sources.tsx +5 −3
  8. apps/web/src/pages/tools.tsx +3 −1
  9. apps/web/src/shell.tsx +33 −14
  10. packages/clients/react/src/atoms.ts +13 −8
  11. packages/clients/react/src/index.ts +4 −0
  12. packages/clients/react/src/provider.tsx +4 −1
  13. packages/clients/react/src/scope-context.tsx +55 −0
  14. packages/clients/react/src/use-scope.ts +2 −0
  15. packages/core/api/src/api.ts +2 −0
  16. packages/core/api/src/index.ts +1 −0
  17. packages/core/api/src/scope/api.ts +23 −0
  18. packages/core/sdk/src/scope.ts +0 −1
  19. packages/core/sdk/src/testing.ts +3 −3
  20. packages/core/storage-file/src/index.ts +39 −10
  21. packages/plugins/google-discovery/src/react/AddGoogleDiscoverySource.tsx +6 −7
  22. packages/plugins/graphql/src/react/AddGraphqlSource.tsx +7 −5
  23. packages/plugins/mcp/src/react/AddMcpSource.tsx +6 −5
  24. packages/plugins/onepassword/src/react/OnePasswordSettings.tsx +10 −7
  25. packages/plugins/onepassword/src/react/atoms.ts +5 −11
  26. packages/plugins/openapi/src/react/AddOpenApiSource.tsx +10 −7
  27. packages/plugins/openapi/src/sdk/plugin.test.ts +1 −2
  28. packages/plugins/openapi/src/sdk/plugin.ts +6 −2
  29. packages/ui/src/components/markdown.tsx +26 −7
apps/server/src/handlers/scope.ts+20−0
@@ -0,0 +1,20 @@
1+import { HttpApiBuilder } from "@effect/platform";
2+import { Effect } from "effect";
3+
4+import { ExecutorApi } from "@executor/api";
5+import { ExecutorService } from "../services/executor";
6+
7+export const ScopeHandlers = HttpApiBuilder.group(
8+ ExecutorApi,
9+ "scope",
10+ (handlers) =>
11+ handlers.handle("info", () =>
12+ Effect.gen(function* () {
13+ const executor = yield* ExecutorService;
14+ return {
15+ id: executor.scope.id,
16+ name: executor.scope.name,
17+ };
18+ }),
19+ ),
20+);
apps/server/src/main.ts+2−0
@@ -17,6 +17,7 @@ import { ToolsHandlers } from "./handlers/tools"; · 16 unmodified lines
1717 import { SourcesHandlers } from "./handlers/sources";
1818 import { SecretsHandlers } from "./handlers/secrets";
1919 import { ExecutionsHandlers } from "./handlers/executions";
20+import { ScopeHandlers } from "./handlers/scope";
2021 import { OpenApiHandlersLive } from "./handlers/openapi";
2122 import { McpSourceHandlersLive } from "./handlers/mcp-source";
2223 import { GoogleDiscoveryHandlersLive } from "./handlers/google-discovery";
@@ -46,6 +47,7 @@ const ApiBase = HttpApiBuilder.api(ExecutorApiWithPlugins).pipe( · 23 unmodified lines
4647 SourcesHandlers,
4748 SecretsHandlers,
4849 ExecutionsHandlers,
50+ ScopeHandlers,
4951 OpenApiHandlersLive,
5052 McpSourceHandlersLive,
5153 GoogleDiscoveryHandlersLive,
apps/server/src/services/executor.ts+9−7
@@ -5,7 +5,7 @@ import { NodeFileSystem } from "@effect/platform-node"; · 4 unmodified lines
55 import * as fs from "node:fs";
66
77 import { createExecutor, scopeKv } from "@executor/sdk";
8−import { makeSqliteKv, makeKvConfig, migrate } from "@executor/storage-file";
8+import { makeSqliteKv, makeKvConfig, makeScopedKv, migrate } from "@executor/storage-file";
99 import { withConfigFile } from "@executor/config";
1010 import { openApiPlugin, makeKvOperationStore, type OpenApiPluginExtension } from "@executor/plugin-openapi";
1111 import { mcpPlugin, makeKvBindingStore, type McpPluginExtension } from "@executor/plugin-mcp";
@@ -82,8 +82,10 @@ const ExecutorLayer = Layer.effect( · 70 unmodified lines
8282
8383 yield* migrate.pipe(Effect.catchAll((e) => Effect.die(e)));
8484
85+ const cwd = process.cwd();
8586 const kv = makeSqliteKv(sql);
86− const config = makeKvConfig(kv);
87+ const config = makeKvConfig(kv, { cwd });
88+ const scopedKv = makeScopedKv(kv, cwd);
8789
8890 const configPath = join(process.cwd(), "executor.jsonc");
8991 const fsLayer = NodeFileSystem.layer;
@@ -93,24 +95,24 @@ const ExecutorLayer = Layer.effect( · 3 unmodified lines
9395 plugins: [
9496 openApiPlugin({
9597 operationStore: withConfigFile.openapi(
96− makeKvOperationStore(kv, "openapi"),
98+ makeKvOperationStore(scopedKv, "openapi"),
9799 configPath,
98100 fsLayer,
99101 ),
100102 }),
101103 mcpPlugin({
102104 bindingStore: withConfigFile.mcp(
103− makeKvBindingStore(kv, "mcp"),
105+ makeKvBindingStore(scopedKv, "mcp"),
104106 configPath,
105107 fsLayer,
106108 ),
107109 }),
108110 googleDiscoveryPlugin({
109− bindingStore: makeKvGoogleDiscoveryBindingStore(kv, "google-discovery"),
111+ bindingStore: makeKvGoogleDiscoveryBindingStore(scopedKv, "google-discovery"),
110112 }),
111113 graphqlPlugin({
112114 operationStore: withConfigFile.graphql(
113− makeKvGraphqlOperationStore(kv, "graphql"),
115+ makeKvGraphqlOperationStore(scopedKv, "graphql"),
114116 configPath,
115117 fsLayer,
116118 ),
@@ -118,7 +120,7 @@ const ExecutorLayer = Layer.effect( · 1 unmodified line
118120 keychainPlugin(),
119121 fileSecretsPlugin(),
120122 onepasswordPlugin({
121− kv: scopeKv(kv, "onepassword"),
123+ kv: scopeKv(scopedKv, "onepassword"),
122124 }),
123125 ] as const,
124126 });
apps/web/src/lib/use-scope.ts+1−0
@@ -0,0 +1 @@
1+export { useScope } from "@executor/react";
apps/web/src/pages/secrets.tsx+9−6
@@ -9,7 +9,8 @@ import { · 8 unmodified lines
99 removeSecret,
1010 } from "@executor/react";
1111 import type { SecretProviderPlugin } from "@executor/react";
12−import { SecretId, ScopeId } from "@executor/sdk";
12+import { SecretId } from "@executor/sdk";
13+import { useScope } from "../lib/use-scope";
1314 import { onePasswordSecretProviderPlugin } from "@executor/plugin-onepassword/react";
1415 import {
1516 Dialog,
@@ -51,8 +52,9 @@ function AddSecretDialog(props: { open: boolean; onOpenChange: (v: boolean) => v · 35 unmodified lines
5152 const [saving, setSaving] = useState(false);
5253 const [error, setError] = useState<string | null>(null);
5354
55+ const scopeId = useScope();
5456 const doSet = useAtomSet(setSecret, { mode: "promise" });
55− const refresh = useAtomRefresh(secretsAtom());
57+ const refresh = useAtomRefresh(secretsAtom(scopeId));
5658
5759 const reset = () => {
5860 setId("");
@@ -70,7 +72,7 @@ function AddSecretDialog(props: { open: boolean; onOpenChange: (v: boolean) => v · 11 unmodified lines
7072 setError(null);
7173 try {
7274 await doSet({
73− path: { scopeId: ScopeId.make("default") },
75+ path: { scopeId },
7476 payload: {
7577 id: SecretId.make(id.trim()),
7678 name: name.trim(),
@@ -275,15 +277,16 @@ const secretProviderPlugins: SecretProviderPlugin[] = [ · 198 unmodified lines
275277
276278 export function SecretsPage() {
277279 const [addOpen, setAddOpen] = useState(false);
278− const secrets = useAtomValue(secretsAtom());
280+ const scopeId = useScope();
281+ const secrets = useAtomValue(secretsAtom(scopeId));
279282 const doRemove = useAtomSet(removeSecret, { mode: "promise" });
280− const refresh = useAtomRefresh(secretsAtom());
283+ const refresh = useAtomRefresh(secretsAtom(scopeId));
281284
282285 const handleRemove = async (secretId: string) => {
283286 try {
284287 await doRemove({
285288 path: {
286− scopeId: ScopeId.make("default"),
289+ scopeId,
287290 secretId: SecretId.make(secretId),
288291 },
289292 });
apps/web/src/pages/source-detail.tsx+18−11
@@ -1,4 +1,4 @@
1−import { useMemo, useState } from "react";
1+import { useEffect, useMemo, useState } from "react";
22 import { useNavigate } from "@tanstack/react-router";
33 import {
44 useAtomValue,
@@ -10,24 +10,31 @@ import { · 5 unmodified lines
1010 removeSource,
1111 refreshSource,
1212 Result,
13− ScopeId,
1413 } from "@executor/react";
1514 import { ToolTree } from "../components/tool-tree";
1615 import { ToolDetail, ToolDetailEmpty } from "../components/tool-detail";
1716 import type { ToolSummary } from "../components/tool-tree";
18−
19−const DEFAULT_SCOPE = ScopeId.make("default");
17+import { useScope } from "../lib/use-scope";
2018
2119 export function SourceDetailPage(props: { namespace: string }) {
2220 const { namespace } = props;
23− const source = useAtomValue(sourceAtom(namespace));
24− const tools = useAtomValue(sourceToolsAtom(namespace));
25− const refreshSources = useAtomRefresh(sourcesAtom());
26− const refreshTools = useAtomRefresh(sourceToolsAtom(namespace));
21+ const scopeId = useScope();
22+ const source = useAtomValue(sourceAtom(namespace, scopeId));
23+ const tools = useAtomValue(sourceToolsAtom(namespace, scopeId));
24+ const refreshSources = useAtomRefresh(sourcesAtom(scopeId));
25+ const refreshTools = useAtomRefresh(sourceToolsAtom(namespace, scopeId));
2726 const doRemove = useAtomSet(removeSource, { mode: "promise" });
2827 const doRefresh = useAtomSet(refreshSource, { mode: "promise" });
2928 const navigate = useNavigate();
3029
30+ // HMR: refresh source tools when the backend is hot-reloaded
31+ useEffect(() => {
32+ if (!import.meta.hot) return;
33+ const refresh = () => { refreshTools(); refreshSources(); };
34+ import.meta.hot.on("executor:backend-updated", refresh);
35+ return () => { import.meta.hot?.off("executor:backend-updated", refresh); };
36+ }, [refreshTools, refreshSources]);
37+
3138 const [selectedToolId, setSelectedToolId] = useState<string | null>(null);
3239 const [confirmDelete, setConfirmDelete] = useState(false);
3340 const [deleting, setDeleting] = useState(false);
@@ -56,7 +63,7 @@ export function SourceDetailPage(props: { namespace: string }) { · 22 unmodified lines
5663 setDeleting(true);
5764 try {
5865 await doRemove({
59− path: { scopeId: DEFAULT_SCOPE, sourceId: namespace },
66+ path: { scopeId, sourceId: namespace },
6067 });
6168 refreshSources();
6269 void navigate({ to: "/" });
@@ -70,7 +77,7 @@ export function SourceDetailPage(props: { namespace: string }) { · 7 unmodified lines
7077 setRefreshing(true);
7178 try {
7279 await doRefresh({
73− path: { scopeId: DEFAULT_SCOPE, sourceId: namespace },
80+ path: { scopeId, sourceId: namespace },
7481 });
7582 refreshTools();
7683 refreshSources();
@@ -174,7 +181,7 @@ export function SourceDetailPage(props: { namespace: string }) { · 97 unmodified lines
174181 toolId={selectedTool.id}
175182 toolName={selectedTool.name}
176183 toolDescription={selectedTool.description}
177− scopeId={DEFAULT_SCOPE}
184+ scopeId={scopeId}
178185 />
179186 ) : (
180187 <ToolDetailEmpty hasTools={sourceTools.length > 0} />
apps/web/src/pages/sources.tsx+5−3
@@ -1,6 +1,7 @@
11 import { useReducer, useCallback, useMemo, Suspense } from "react";
22 import { Link } from "@tanstack/react-router";
33 import { Result, useAtomValue, useAtomRefresh, useAtomSet, sourcesAtom, detectSource } from "@executor/react";
4+import { useScope } from "../lib/use-scope";
45 import type { SourcePlugin, SourcePreset } from "@executor/react";
56 import { openApiSourcePlugin } from "@executor/plugin-openapi/react";
67 import { mcpSourcePlugin } from "@executor/plugin-mcp/react";
@@ -82,8 +83,9 @@ function reducer(state: State, action: Action): State { · 75 unmodified lines
8283
8384 export function SourcesPage() {
8485 const [state, dispatch] = useReducer(reducer, init);
85− const sources = useAtomValue(sourcesAtom());
86− const refreshSources = useAtomRefresh(sourcesAtom());
86+ const scopeId = useScope();
87+ const sources = useAtomValue(sourcesAtom(scopeId));
88+ const refreshSources = useAtomRefresh(sourcesAtom(scopeId));
8789 const doDetect = useAtomSet(detectSource, { mode: "promise" });
8890
8991 const handleDetect = useCallback(async () => {
@@ -92,7 +94,7 @@ export function SourcesPage() { · 2 unmodified lines
9294 dispatch({ type: "detect-start" });
9395 try {
9496 const results = await doDetect({
95− path: { scopeId: "default" as any },
97+ path: { scopeId },
9698 payload: { url: trimmed },
9799 });
98100 if (results.length === 0) {
apps/web/src/pages/tools.tsx+3−1
@@ -1,7 +1,9 @@
11 import { useAtomValue, Result, toolsAtom } from "@executor/react";
2+import { useScope } from "../lib/use-scope";
23
34 export function ToolsPage() {
4− const tools = useAtomValue(toolsAtom());
5+ const scopeId = useScope();
6+ const tools = useAtomValue(toolsAtom(scopeId));
57
68 return (
79 <div className="min-h-0 flex-1 overflow-y-auto">
apps/web/src/shell.tsx+33−14
@@ -4,9 +4,10 @@ import { · 3 unmodified lines
44 useAtomRefresh,
55 useAtomValue,
66 Result,
7− sourceToolsAtom,
87 sourcesAtom,
98 toolsAtom,
9+ useScope,
10+ useScopeInfo,
1011 } from "@executor/react";
1112 import { Button } from "@executor/ui/components/button";
1213
@@ -190,7 +191,8 @@ function NavItem(props: { to: string; label: string; active: boolean; onNavigate · 177 unmodified lines
190191 // ── SourceList ───────────────────────────────────────────────────────────
191192
192193 function SourceList(props: { pathname: string; onNavigate?: () => void }) {
193− const sources = useAtomValue(sourcesAtom());
194+ const scopeId = useScope();
195+ const sources = useAtomValue(sourcesAtom(scopeId));
194196
195197 return Result.match(sources, {
196198 onInitial: () => (
@@ -236,6 +238,30 @@ function SourceList(props: { pathname: string; onNavigate?: () => void }) { · 39 unmodified lines
236238 });
237239 }
238240
241+// ── ScopeLabel ───────────────────────────────────────────────────────────
242+
243+function ScopeLabel() {
244+ const { name } = useScopeInfo();
245+ // Show just the last folder name, with full path as tooltip
246+ const parts = name.replace(/\/+$/, "").split("/");
247+ const folder = parts[parts.length - 1] || name;
248+
249+ return (
250+ <div className="mb-1.5 flex items-center gap-1.5 rounded-md px-2.5 py-1.5" title={name}>
251+ <svg viewBox="0 0 16 16" fill="none" className="size-3.5 shrink-0 text-muted-foreground/50">
252+ <path
253+ d="M2 4.5C2 3.67 2.67 3 3.5 3h3.09a1 1 0 0 1 .7.29l1.42 1.42a1 1 0 0 0 .7.29H12.5c.83 0 1.5.67 1.5 1.5v5.5c0 .83-.67 1.5-1.5 1.5h-9A1.5 1.5 0 0 1 2 12V4.5z"
254+ stroke="currentColor"
255+ strokeWidth="1.2"
256+ />
257+ </svg>
258+ <span className="truncate text-[12px] font-medium text-foreground/80">
259+ {folder}
260+ </span>
261+ </div>
262+ );
263+}
264+
239265 // ── SidebarContent ───────────────────────────────────────────────────────
240266
241267 function SidebarContent(props: {
@@ -265,6 +291,7 @@ function SidebarContent(props: { · 23 unmodified lines
265291 )}
266292
267293 <nav className="flex flex-1 flex-col overflow-y-auto p-2">
294+ <ScopeLabel />
268295 <NavItem
269296 to="/"
270297 label="Dashboard"
@@ -338,14 +365,9 @@ function SidebarContent(props: { · 67 unmodified lines
338365 export function Shell() {
339366 const location = useLocation();
340367 const pathname = location.pathname;
341− const currentSourceId = pathname.startsWith("/sources/")
342− ? decodeURIComponent(pathname.slice("/sources/".length).split("/")[0] ?? "")
343− : null;
344− const refreshSources = useAtomRefresh(sourcesAtom());
345− const refreshTools = useAtomRefresh(toolsAtom());
346− const refreshSourceTools = useAtomRefresh(
347− sourceToolsAtom(currentSourceId ?? "__runtime__"),
348− );
368+ const scopeId = useScope();
369+ const refreshSources = useAtomRefresh(sourcesAtom(scopeId));
370+ const refreshTools = useAtomRefresh(toolsAtom(scopeId));
349371 const { latestVersion, updateAvailable, channel } = useLatestVersion(VITE_APP_VERSION);
350372 const lastPathname = useRef(pathname);
351373 const [mobileSidebarOpen, setMobileSidebarOpen] = useState(false);
@@ -372,9 +394,6 @@ export function Shell() { · 20 unmodified lines
372394 const refreshBackendData = () => {
373395 refreshSources();
374396 refreshTools();
375− if (currentSourceId) {
376− refreshSourceTools();
377− }
378397 };
379398
380399 import.meta.hot.on("executor:backend-updated", refreshBackendData);
@@ -382,7 +401,7 @@ export function Shell() { · 1 unmodified line
382401 return () => {
383402 import.meta.hot?.off("executor:backend-updated", refreshBackendData);
384403 };
385− }, [currentSourceId, refreshSourceTools, refreshSources, refreshTools]);
404+ }, [refreshSources, refreshTools]);
386405
387406 return (
388407 <div className="flex h-screen overflow-hidden">
packages/clients/react/src/atoms.ts+13−8
@@ -1,23 +1,28 @@
11 import type { ScopeId, ToolId, SecretId } from "@executor/sdk";
22 import { Atom } from "@effect-atom/atom-react";
3−import { ScopeId as ScopeIdSchema } from "@executor/sdk";
43
54 import { ExecutorApiClient } from "./client";
65
76 // ---------------------------------------------------------------------------
8−// Query atoms — typed, cached, reactive
7+// Scope — fetched from the server
98 // ---------------------------------------------------------------------------
109
11−const DEFAULT_SCOPE = ScopeIdSchema.make("default");
10+export const scopeAtom = ExecutorApiClient.query("scope", "info", {
11+ timeToLive: "5 minutes",
12+});
13+
14+// ---------------------------------------------------------------------------
15+// Query atoms — typed, cached, reactive
16+// ---------------------------------------------------------------------------
1217
13−export const toolsAtom = (scopeId: ScopeId = DEFAULT_SCOPE) =>
18+export const toolsAtom = (scopeId: ScopeId) =>
1419 ExecutorApiClient.query("tools", "list", {
1520 path: { scopeId },
1621 timeToLive: "30 seconds",
1722 });
1823
1924 /** Tools for a specific source */
20−export const sourceToolsAtom = (sourceId: string, scopeId: ScopeId = DEFAULT_SCOPE) =>
25+export const sourceToolsAtom = (sourceId: string, scopeId: ScopeId) =>
2126 ExecutorApiClient.query("sources", "tools", {
2227 path: { scopeId, sourceId },
2328 timeToLive: "30 seconds",
@@ -29,20 +34,20 @@ export const toolSchemaAtom = (scopeId: ScopeId, toolId: ToolId) => · 5 unmodified lines
2934 timeToLive: "1 minute",
3035 });
3136
32−export const sourcesAtom = (scopeId: ScopeId = DEFAULT_SCOPE) =>
37+export const sourcesAtom = (scopeId: ScopeId) =>
3338 ExecutorApiClient.query("sources", "list", {
3439 path: { scopeId },
3540 timeToLive: "30 seconds",
3641 });
3742
3843 /** Single source by id — derived from the sources list */
39−export const sourceAtom = (sourceId: string, scopeId: ScopeId = DEFAULT_SCOPE) =>
44+export const sourceAtom = (sourceId: string, scopeId: ScopeId) =>
4045 Atom.mapResult(
4146 sourcesAtom(scopeId),
4247 (sources) => sources.find((s) => s.id === sourceId) ?? null,
4348 );
4449
45−export const secretsAtom = (scopeId: ScopeId = DEFAULT_SCOPE) =>
50+export const secretsAtom = (scopeId: ScopeId) =>
4651 ExecutorApiClient.query("secrets", "list", {
4752 path: { scopeId },
4853 timeToLive: "30 seconds",
packages/clients/react/src/index.ts+4−0
@@ -36,6 +36,10 @@ export { · 35 unmodified lines
3636 detectSource,
3737 } from "./atoms";
3838
39+// Scope hook
40+export { useScope, useScopeInfo } from "./use-scope";
41+export type { ScopeInfo } from "./use-scope";
42+
3943 // Provider
4044 export { ExecutorProvider } from "./provider";
4145 export { SecretPicker } from "./secret-picker";
packages/clients/react/src/provider.tsx+4−1
@@ -1,6 +1,9 @@
11 import { RegistryProvider } from "@effect-atom/atom-react";
22 import * as React from "react";
3+import { ScopeProvider } from "./scope-context";
34
45 export const ExecutorProvider = (props: React.PropsWithChildren) => (
5− <RegistryProvider>{props.children}</RegistryProvider>
6+ <RegistryProvider>
7+ <ScopeProvider>{props.children}</ScopeProvider>
8+ </RegistryProvider>
69 );
packages/clients/react/src/scope-context.tsx+55−0
@@ -0,0 +1,55 @@
1+import * as React from "react";
2+import { useAtomValue, Result } from "@effect-atom/atom-react";
3+
4+import type { ScopeId } from "@executor/sdk";
5+import { scopeAtom } from "./atoms";
6+
7+export interface ScopeInfo {
8+ readonly id: ScopeId;
9+ readonly name: string;
10+}
11+
12+const ScopeContext = React.createContext<ScopeInfo | null>(null);
13+
14+/**
15+ * Provides the server scope to all children.
16+ * Renders nothing until the scope is fetched.
17+ */
18+export function ScopeProvider(props: React.PropsWithChildren) {
19+ const result = useAtomValue(scopeAtom);
20+
21+ if (Result.isSuccess(result)) {
22+ return (
23+ <ScopeContext.Provider value={result.value}>
24+ {props.children}
25+ </ScopeContext.Provider>
26+ );
27+ }
28+
29+ // Loading or error — don't render children
30+ return null;
31+}
32+
33+/**
34+ * Returns the current scope ID.
35+ * Must be used inside a ScopeProvider (which gates rendering until scope is loaded).
36+ */
37+export function useScope(): ScopeId {
38+ const scope = React.useContext(ScopeContext);
39+ if (scope === null) {
40+ throw new Error("useScope must be used inside a ScopeProvider");
41+ }
42+ return scope.id;
43+}
44+
45+/**
46+ * Returns the full scope info (id + display name).
47+ * Must be used inside a ScopeProvider.
48+ */
49+export function useScopeInfo(): ScopeInfo {
50+ const scope = React.useContext(ScopeContext);
51+ if (scope === null) {
52+ throw new Error("useScopeInfo must be used inside a ScopeProvider");
53+ }
54+ return scope;
55+}
packages/clients/react/src/use-scope.ts+2−0
@@ -0,0 +1,2 @@
1+export { useScope, useScopeInfo } from "./scope-context";
2+export type { ScopeInfo } from "./scope-context";
packages/core/api/src/api.ts+2−0
@@ -5,12 +5,14 @@ import { ToolsApi } from "./tools/api"; · 4 unmodified lines
55 import { SourcesApi } from "./sources/api";
66 import { SecretsApi } from "./secrets/api";
77 import { ExecutionsApi } from "./executions/api";
8+import { ScopeApi } from "./scope/api";
89
910 export const CoreExecutorApi = HttpApi.make("executor")
1011 .add(ToolsApi)
1112 .add(SourcesApi)
1213 .add(SecretsApi)
1314 .add(ExecutionsApi)
15+ .add(ScopeApi)
1416 .annotateContext(
1517 OpenApi.annotations({
1618 title: "Executor API",
packages/core/api/src/index.ts+1−0
@@ -3,3 +3,4 @@ export { ToolsApi } from "./tools/api"; · 2 unmodified lines
33 export { SourcesApi } from "./sources/api";
44 export { SecretsApi } from "./secrets/api";
55 export { ExecutionsApi } from "./executions/api";
6+export { ScopeApi } from "./scope/api";
packages/core/api/src/scope/api.ts+23−0
@@ -0,0 +1,23 @@
1+import { HttpApiEndpoint, HttpApiGroup } from "@effect/platform";
2+import { Schema } from "effect";
3+import { ScopeId } from "@executor/sdk";
4+
5+// ---------------------------------------------------------------------------
6+// Response schemas
7+// ---------------------------------------------------------------------------
8+
9+const ScopeInfoResponse = Schema.Struct({
10+ id: ScopeId,
11+ name: Schema.String,
12+});
13+
14+// ---------------------------------------------------------------------------
15+// Group
16+// ---------------------------------------------------------------------------
17+
18+export class ScopeApi extends HttpApiGroup.make("scope")
19+ .add(
20+ HttpApiEndpoint.get("info")`/scope`
21+ .addSuccess(ScopeInfoResponse),
22+ )
23+ .prefix("/v1") {}
packages/core/sdk/src/scope.ts+0−1
@@ -4,7 +4,6 @@ import { ScopeId } from "./ids"; · 3 unmodified lines
44
55 export class Scope extends Schema.Class<Scope>("Scope")({
66 id: ScopeId,
7− parentId: Schema.NullOr(ScopeId),
87 name: Schema.String,
98 createdAt: Schema.DateFromNumber,
109 }) {}
packages/core/sdk/src/testing.ts+3−3
@@ -16,14 +16,14 @@ export const makeTestConfig = < · 15 unmodified lines
1616 const TPlugins extends readonly ExecutorPlugin<string, object>[] = [],
1717 >(
1818 options?: {
19− readonly name?: string;
19+ readonly cwd?: string;
2020 readonly plugins?: TPlugins;
2121 },
2222 ): ExecutorConfig<TPlugins> => {
23+ const cwd = options?.cwd ?? "/test";
2324 const scope: Scope = {
2425 id: ScopeId.make("test-scope"),
25− parentId: null,
26− name: options?.name ?? "test",
26+ name: cwd,
2727 createdAt: new Date(),
2828 };
2929
packages/core/storage-file/src/index.ts+39−10
@@ -21,6 +21,9 @@ · 20 unmodified lines
2121 //
2222 // ---------------------------------------------------------------------------
2323
24+import { createHash } from "node:crypto";
25+import { basename } from "node:path";
26+
2427 import { scopeKv, ScopeId, makeInMemorySourceRegistry } from "@executor/sdk";
2528 import type { Kv, Scope, ExecutorConfig, ExecutorPlugin } from "@executor/sdk";
2629
@@ -28,6 +31,16 @@ import { makeKvToolRegistry } from "./tool-registry"; · 1 unmodified line
2831 import { makeKvSecretStore } from "./secret-store";
2932 import { makeKvPolicyEngine } from "./policy-engine";
3033
34+/**
35+ * Derive a URL-safe scope ID from a folder path.
36+ * Format: `foldername-shortHash` e.g. `my-project-a1b2c3d4`
37+ */
38+const makeScopeId = (cwd: string): string => {
39+ const folder = basename(cwd) || cwd;
40+ const hash = createHash("sha256").update(cwd).digest("hex").slice(0, 8);
41+ return `${folder}-${hash}`;
42+};
43+
3144 export { makeSqliteKv, makeInMemoryKv } from "./plugin-kv";
3245 export { makeKvToolRegistry } from "./tool-registry";
3346 export { makeKvSecretStore } from "./secret-store";
@@ -42,32 +55,48 @@ export const makeKvConfig = < · 8 unmodified lines
4255 const TPlugins extends readonly ExecutorPlugin<string, object>[] = [],
4356 >(
4457 kv: Kv,
45− options?: {
46− readonly name?: string;
58+ options: {
59+ readonly cwd: string;
4760 readonly plugins?: TPlugins;
4861 },
4962 ): ExecutorConfig<TPlugins> => {
63+ const cwd = options.cwd;
64+ const scopeId = makeScopeId(cwd);
5065 const scope: Scope = {
51− id: ScopeId.make("default"),
52− parentId: null,
53− name: options?.name ?? "default",
66+ id: ScopeId.make(scopeId),
67+ name: cwd,
5468 createdAt: new Date(),
5569 };
5670
71+ // Prefix all KV namespaces with the full cwd so each folder is fully isolated.
72+ const ns = (name: string) => `${cwd}::${name}`;
73+
5774 return {
5875 scope,
5976 tools: makeKvToolRegistry(
60− scopeKv(kv, "tools"),
61− scopeKv(kv, "defs"),
77+ scopeKv(kv, ns("tools")),
78+ scopeKv(kv, ns("defs")),
6279 ),
6380 sources: makeInMemorySourceRegistry(),
6481 secrets: makeKvSecretStore(
65− scopeKv(kv, "secrets"),
82+ scopeKv(kv, ns("secrets")),
6683 ),
6784 policies: makeKvPolicyEngine(
68− scopeKv(kv, "policies"),
69− scopeKv(kv, "meta"),
85+ scopeKv(kv, ns("policies")),
86+ scopeKv(kv, ns("meta")),
7087 ),
7188 plugins: options?.plugins,
7289 };
7390 };
91+
92+/**
93+ * Create a scoped Kv that prefixes all namespaces with the given folder path.
94+ * Used by plugins that need their own KV namespace scoped to a folder.
95+ */
96+export const makeScopedKv = (kv: Kv, folder: string): Kv => ({
97+ get: (namespace, key) => kv.get(`${folder}::${namespace}`, key),
98+ set: (namespace, key, value) => kv.set(`${folder}::${namespace}`, key, value),
99+ delete: (namespace, key) => kv.delete(`${folder}::${namespace}`, key),
100+ list: (namespace) => kv.list(`${folder}::${namespace}`),
101+ deleteAll: (namespace) => kv.deleteAll(`${folder}::${namespace}`),
102+});
packages/plugins/google-discovery/src/react/AddGoogleDiscoverySource.tsx+6−7
@@ -2,7 +2,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react"; · 1 unmodified line
22 import { useAtomSet, useAtomValue, Result } from "@effect-atom/atom-react";
33
44 import {
5− ScopeId,
5+ useScope,
66 SecretPicker,
77 secretsAtom,
88 type SecretPickerSecret,
@@ -212,8 +212,6 @@ type OAuthPopupResult = · 203 unmodified lines
212212 error: string;
213213 };
214214
215−const DEFAULT_SCOPE = ScopeId.make("default");
216−
217215 function openOAuthPopup(
218216 url: string,
219217 onResult: (data: OAuthPopupResult) => void,
@@ -287,10 +285,11 @@ export default function AddGoogleDiscoverySource(props: { · 67 unmodified lines
287285 const [error, setError] = useState<string | null>(null);
288286 const [showScopes, setShowScopes] = useState(false);
289287
288+ const scopeId = useScope();
290289 const doProbe = useAtomSet(probeGoogleDiscovery, { mode: "promise" });
291290 const doAdd = useAtomSet(addGoogleDiscoverySource, { mode: "promise" });
292291 const doStartOAuth = useAtomSet(startGoogleDiscoveryOAuth, { mode: "promise" });
293− const secrets = useAtomValue(secretsAtom());
292+ const secrets = useAtomValue(secretsAtom(scopeId));
294293
295294 const canUseOAuth = useMemo(
296295 () => (probe?.scopes.length ?? 0) > 0,
@@ -326,7 +325,7 @@ export default function AddGoogleDiscoverySource(props: { · 29 unmodified lines
326325 setShowScopes(false);
327326 try {
328327 const result = await doProbe({
329− path: { scopeId: DEFAULT_SCOPE },
328+ path: { scopeId },
330329 payload: { discoveryUrl: discoveryUrl.trim() },
331330 });
332331 setProbe({ ...result, scopes: [...result.scopes] });
@@ -358,7 +357,7 @@ export default function AddGoogleDiscoverySource(props: { · 25 unmodified lines
358357 setError(null);
359358 try {
360359 const response = await doStartOAuth({
361− path: { scopeId: DEFAULT_SCOPE },
360+ path: { scopeId },
362361 payload: {
363362 name: name.trim() || probe.name,
364363 discoveryUrl: discoveryUrl.trim(),
@@ -406,7 +405,7 @@ export default function AddGoogleDiscoverySource(props: { · 41 unmodified lines
406405 setError(null);
407406 try {
408407 await doAdd({
409− path: { scopeId: DEFAULT_SCOPE },
408+ path: { scopeId },
410409 payload: {
411410 name: name.trim() || probe.name,
412411 discoveryUrl: discoveryUrl.trim(),
packages/plugins/graphql/src/react/AddGraphqlSource.tsx+7−5
@@ -4,7 +4,7 @@ import { useAtomSet, useAtomValue, useAtomRefresh, Result } from "@effect-atom/a · 3 unmodified lines
44 import {
55 secretsAtom,
66 setSecret,
7− ScopeId,
7+ useScope,
88 SecretPicker,
99 type SecretPickerSecret,
1010 } from "@executor/react";
@@ -31,8 +31,9 @@ function InlineCreateSecret(props: { · 20 unmodified lines
3131 const [secretValue, setSecretValue] = useState("");
3232 const [saving, setSaving] = useState(false);
3333 const [error, setError] = useState<string | null>(null);
34+ const scopeId = useScope();
3435 const doSet = useAtomSet(setSecret, { mode: "promise" });
35− const refreshSecrets = useAtomRefresh(secretsAtom());
36+ const refreshSecrets = useAtomRefresh(secretsAtom(scopeId));
3637
3738 const handleSave = async () => {
3839 if (!secretId.trim() || !secretValue.trim()) return;
@@ -40,7 +41,7 @@ function InlineCreateSecret(props: { · 1 unmodified line
4041 setError(null);
4142 try {
4243 await doSet({
43− path: { scopeId: ScopeId.make("default") },
44+ path: { scopeId },
4445 payload: {
4546 id: SecretId.make(secretId.trim()),
4647 name: secretName.trim() || secretId.trim(),
@@ -165,8 +166,9 @@ export default function AddGraphqlSource(props: { · 118 unmodified lines
165166 const [adding, setAdding] = useState(false);
166167 const [addError, setAddError] = useState<string | null>(null);
167168
169+ const scopeId = useScope();
168170 const doAdd = useAtomSet(addGraphqlSource, { mode: "promise" });
169− const secrets = useAtomValue(secretsAtom());
171+ const secrets = useAtomValue(secretsAtom(scopeId));
170172
171173 const secretList: readonly SecretPickerSecret[] = Result.match(secrets, {
172174 onInitial: () => [] as SecretPickerSecret[],
@@ -191,7 +193,7 @@ export default function AddGraphqlSource(props: { · 18 unmodified lines
191193 }
192194
193195 await doAdd({
194− path: { scopeId: "default" as never },
196+ path: { scopeId },
195197 payload: {
196198 endpoint: endpoint.trim(),
197199 namespace: namespace.trim() || undefined,
packages/plugins/mcp/src/react/AddMcpSource.tsx+6−5
@@ -1,7 +1,7 @@
11 import { useReducer, useCallback, useEffect, useRef } from "react";
22 import { useAtomSet } from "@effect-atom/atom-react";
33
4−import { ScopeId } from "@executor/react";
4+import { useScope } from "@executor/react";
55 import { Button } from "@executor/ui/components/button";
66 import { Input } from "@executor/ui/components/input";
77 import { Label } from "@executor/ui/components/label";
@@ -171,6 +171,7 @@ export default function AddMcpSource(props: { · 163 unmodified lines
171171 props.initialUrl ? { step: "url" as const, url: props.initialUrl } : init,
172172 );
173173
174+ const scopeId = useScope();
174175 const doProbe = useAtomSet(probeMcpEndpoint, { mode: "promise" });
175176 const doAdd = useAtomSet(addMcpSource, { mode: "promise" });
176177 const doStartOAuth = useAtomSet(startMcpOAuth, { mode: "promise" });
@@ -191,14 +192,14 @@ export default function AddMcpSource(props: { · 14 unmodified lines
191192 dispatch({ type: "probe-start" });
192193 try {
193194 const result = await doProbe({
194− path: { scopeId: ScopeId.make("default") },
195+ path: { scopeId },
195196 payload: { endpoint: state.url.trim() },
196197 });
197198 dispatch({ type: "probe-ok", probe: result });
198199 } catch (e) {
199200 dispatch({ type: "probe-fail", error: e instanceof Error ? e.message : "Failed to connect" });
200201 }
201− }, [state.url, doProbe]);
202+ }, [state.url, scopeId, doProbe]);
202203
203204 const autoProbed = useRef(false);
204205 useEffect(() => {
@@ -213,7 +214,7 @@ export default function AddMcpSource(props: { · 8 unmodified lines
213214 try {
214215 const redirectUrl = `${window.location.origin}/v1/mcp/oauth/callback`;
215216 const result = await doStartOAuth({
216− path: { scopeId: ScopeId.make("default") },
217+ path: { scopeId },
217218 payload: { endpoint: state.url.trim(), redirectUrl },
218219 });
219220 dispatch({ type: "oauth-waiting", sessionId: result.sessionId });
@@ -247,7 +248,7 @@ export default function AddMcpSource(props: { · 27 unmodified lines
247248 dispatch({ type: "add-start" });
248249 try {
249250 await doAdd({
250− path: { scopeId: ScopeId.make("default") },
251+ path: { scopeId },
251252 payload: {
252253 transport: "remote" as const,
253254 name: probe.serverName ?? probe.name,
packages/plugins/onepassword/src/react/OnePasswordSettings.tsx+10−7
@@ -1,7 +1,7 @@
11 import { useState } from "react";
22 import { useAtomSet, useAtomValue, useAtomRefresh } from "@effect-atom/atom-react";
33 import { Result } from "@effect-atom/atom-react";
4−import { ScopeId } from "@executor/sdk";
4+import { useScope } from "@executor/react";
55 import { Button } from "@executor/ui/components/button";
66 import { Input } from "@executor/ui/components/input";
77 import { Label } from "@executor/ui/components/label";
@@ -41,8 +41,9 @@ function VaultPicker(props: { · 33 unmodified lines
4141 onVaultSelect: (id: string, name: string) => void;
4242 }) {
4343 const account = props.accountName.trim();
44+ const scopeId = useScope();
4445 const vaultsResult = useAtomValue(
45− onepasswordVaultsAtom(props.authKind, account),
46+ onepasswordVaultsAtom(props.authKind, account, scopeId),
4647 );
4748
4849 const { vaults, isLoading, error } = Result.match(
@@ -117,8 +118,9 @@ function ConfigDialog(props: { · 68 unmodified lines
117118 const [saving, setSaving] = useState(false);
118119 const [error, setError] = useState<string | null>(null);
119120
121+ const scopeId = useScope();
120122 const doConfigure = useAtomSet(configureOnePassword, { mode: "promise" });
121− const refreshConfig = useAtomRefresh(onepasswordConfigAtom());
123+ const refreshConfig = useAtomRefresh(onepasswordConfigAtom(scopeId));
122124
123125 const reset = () => {
124126 if (!isEdit) {
@@ -142,7 +144,7 @@ function ConfigDialog(props: { · 17 unmodified lines
142144 : { kind: "service-account" as const, tokenSecretId: accountName.trim() };
143145
144146 await doConfigure({
145− path: { scopeId: "default" as ScopeId },
147+ path: { scopeId },
146148 payload: { auth, vaultId: vaultId.trim(), name: vaultName.trim() || "1Password" },
147149 });
148150 props.onOpenChange(false);
@@ -256,13 +258,14 @@ function ConfigDialog(props: { · 107 unmodified lines
256258
257259 export default function OnePasswordSettings() {
258260 const [configOpen, setConfigOpen] = useState(false);
259− const configResult = useAtomValue(onepasswordConfigAtom());
261+ const scopeId = useScope();
262+ const configResult = useAtomValue(onepasswordConfigAtom(scopeId));
260263 const doRemove = useAtomSet(removeOnePasswordConfig, { mode: "promise" });
261− const refreshConfig = useAtomRefresh(onepasswordConfigAtom());
264+ const refreshConfig = useAtomRefresh(onepasswordConfigAtom(scopeId));
262265
263266 const handleRemove = async () => {
264267 try {
265− await doRemove({ path: { scopeId: "default" as ScopeId } });
268+ await doRemove({ path: { scopeId } });
266269 refreshConfig();
267270 } catch { /* TODO: toast */ }
268271 };
packages/plugins/onepassword/src/react/atoms.ts+5−11
@@ -1,23 +1,17 @@
1−import { ScopeId } from "@executor/sdk";
1+import type { ScopeId } from "@executor/sdk";
22 import { OnePasswordClient } from "./client";
33
44 // ---------------------------------------------------------------------------
5−// Stable default scope
5+// Query atoms
66 // ---------------------------------------------------------------------------
77
8−const DEFAULT_SCOPE = ScopeId.make("default");
9−
10−// ---------------------------------------------------------------------------
11−// Query atoms — stable references for default scope
12−// ---------------------------------------------------------------------------
13−
14−export const onepasswordConfigAtom = (scopeId: ScopeId = DEFAULT_SCOPE) =>
8+export const onepasswordConfigAtom = (scopeId: ScopeId) =>
159 OnePasswordClient.query("onepassword", "getConfig", {
1610 path: { scopeId },
1711 timeToLive: "30 seconds",
1812 });
1913
20−export const onepasswordStatusAtom = (scopeId: ScopeId = DEFAULT_SCOPE) =>
14+export const onepasswordStatusAtom = (scopeId: ScopeId) =>
2115 OnePasswordClient.query("onepassword", "status", {
2216 path: { scopeId },
2317 timeToLive: "15 seconds",
@@ -30,7 +24,7 @@ export const onepasswordStatusAtom = (scopeId: ScopeId = DEFAULT_SCOPE) => · 6 unmodified lines
3024 export const onepasswordVaultsAtom = (
3125 authKind: "desktop-app" | "service-account",
3226 account: string,
33− scopeId: ScopeId = DEFAULT_SCOPE,
27+ scopeId: ScopeId,
3428 ) =>
3529 OnePasswordClient.query("onepassword", "listVaults", {
3630 path: { scopeId },
packages/plugins/openapi/src/react/AddOpenApiSource.tsx+10−7
@@ -6,7 +6,7 @@ import { · 5 unmodified lines
66 secretsAtom,
77 setSecret,
88 resolveSecret,
9− ScopeId,
9+ useScope,
1010 SecretPicker,
1111 type SecretPickerSecret,
1212 } from "@executor/react";
@@ -38,8 +38,9 @@ function InlineCreateSecret(props: { · 25 unmodified lines
3838 const [secretValue, setSecretValue] = useState("");
3939 const [saving, setSaving] = useState(false);
4040 const [error, setError] = useState<string | null>(null);
41+ const scopeId = useScope();
4142 const doSet = useAtomSet(setSecret, { mode: "promise" });
42− const refreshSecrets = useAtomRefresh(secretsAtom());
43+ const refreshSecrets = useAtomRefresh(secretsAtom(scopeId));
4344
4445 const handleSave = async () => {
4546 if (!secretId.trim() || !secretValue.trim()) return;
@@ -47,7 +48,7 @@ function InlineCreateSecret(props: { · 1 unmodified line
4748 setError(null);
4849 try {
4950 await doSet({
50− path: { scopeId: ScopeId.make("default") },
51+ path: { scopeId },
5152 payload: {
5253 id: SecretId.make(secretId.trim()),
5354 name: secretName.trim() || secretId.trim(),
@@ -129,6 +130,7 @@ function HeaderValuePreview(props: { · 75 unmodified lines
129130 prefix?: string;
130131 }) {
131132 const { headerName, secretId, prefix } = props;
133+ const scopeId = useScope();
132134 const [state, setState] = useState<ResolveState>({ status: "hidden" });
133135 const doResolve = useAtomSet(resolveSecret, { mode: "promise" });
134136
@@ -141,7 +143,7 @@ function HeaderValuePreview(props: { · 6 unmodified lines
141143 try {
142144 const result = await doResolve({
143145 path: {
144− scopeId: ScopeId.make("default"),
146+ scopeId,
145147 secretId: SecretId.make(secretId),
146148 },
147149 });
@@ -433,9 +435,10 @@ export default function AddOpenApiSource(props: { · 285 unmodified lines
433435 const [adding, setAdding] = useState(false);
434436 const [addError, setAddError] = useState<string | null>(null);
435437
438+ const scopeId = useScope();
436439 const doPreview = useAtomSet(previewOpenApiSpec, { mode: "promise" });
437440 const doAdd = useAtomSet(addOpenApiSpec, { mode: "promise" });
438− const secrets = useAtomValue(secretsAtom());
441+ const secrets = useAtomValue(secretsAtom(scopeId));
439442 const autoAnalyzed = useRef(false);
440443
441444 useEffect(() => {
@@ -497,7 +500,7 @@ export default function AddOpenApiSource(props: { · 55 unmodified lines
497500 setAddError(null);
498501 try {
499502 const result = await doPreview({
500− path: { scopeId: "default" as never },
503+ path: { scopeId },
501504 payload: { spec: specUrl },
502505 });
503506 setPreview(result);
@@ -546,7 +549,7 @@ export default function AddOpenApiSource(props: { · 42 unmodified lines
546549 setAddError(null);
547550 try {
548551 await doAdd({
549− path: { scopeId: "default" as never },
552+ path: { scopeId },
550553 payload: {
551554 spec: specUrl,
552555 baseUrl: baseUrl.trim() || undefined,
packages/plugins/openapi/src/sdk/plugin.test.ts+1−2
@@ -181,8 +181,7 @@ layer(TestLayer)("OpenAPI Plugin", (it) => { · 180 unmodified lines
181181
182182 const scope = {
183183 id: ScopeId.make("test-scope"),
184− parentId: null,
185− name: "test",
184+ name: "/test",
186185 createdAt: new Date(),
187186 } as const;
188187
packages/plugins/openapi/src/sdk/plugin.ts+6−2
@@ -206,7 +206,11 @@ export const openApiPlugin = (options?: { · 205 unmodified lines
206206 Effect.gen(function* () {
207207 const trimmed = url.trim();
208208 if (!trimmed) return null;
209− try { new URL(trimmed); } catch { return null; }
209+ try {
210+ new URL(trimmed);
211+ } catch {
212+ return null;
213+ }
210214
211215 // Try fetching the URL and parsing as OpenAPI spec
212216 // parse() handles both URLs directly and spec text
@@ -310,7 +314,7 @@ export const openApiPlugin = (options?: { · 97 unmodified lines
310314 id: "openapi.previewSpec",
311315 name: "openapi.previewSpec",
312316 description:
313− "Preview an OpenAPI document before adding it as a source",
317+ "Preview an OpenAPI document before adding it as a source \n\n ```ts \ntesting this```",
314318 inputSchema: PreviewSpecInputSchema,
315319 outputSchema: SpecPreview,
316320 handler: ({ spec }: PreviewSpecInput) => previewSpec(spec),
packages/ui/src/components/markdown.tsx+26−7
@@ -1,7 +1,27 @@
1+import { isValidElement, Children, type ReactNode } from "react";
12 import { Streamdown } from "streamdown";
2−import { createCodeHighlighterPlugin } from "../lib/shiki";
3+import { CodeBlock } from "./code-block";
34
4−const codePlugin = createCodeHighlighterPlugin();
5+function extractText(node: ReactNode): string {
6+ if (typeof node === "string") return node;
7+ if (typeof node === "number") return String(node);
8+ if (Array.isArray(node)) return node.map(extractText).join("");
9+ if (isValidElement(node) && node.props) {
10+ return extractText((node.props as { children?: ReactNode }).children);
11+ }
12+ return "";
13+}
14+
15+function PreBlock(props: { children?: ReactNode; node?: unknown }) {
16+ const child = Children.toArray(props.children)[0];
17+ if (isValidElement(child) && (child.type === "code" || (child.props as Record<string, unknown>)?.className)) {
18+ const childProps = child.props as { className?: string; children?: ReactNode };
19+ const lang = childProps.className?.replace("language-", "") ?? undefined;
20+ const code = extractText(childProps.children).replace(/\n$/, "");
21+ return <CodeBlock code={code} lang={lang} className="my-2" />;
22+ }
23+ return <pre>{props.children}</pre>;
24+}
525
626 const PROSE_CLASSES = [
727 "text-[13px] leading-relaxed text-muted-foreground",
@@ -13,10 +33,6 @@ const PROSE_CLASSES = [ · 5 unmodified lines
1333 // inline code
1434 "[&_code]:font-mono [&_code]:text-xs [&_code]:bg-muted [&_code]:border [&_code]:border-border",
1535 "[&_code]:rounded-sm [&_code]:px-1.5 [&_code]:py-px [&_code]:text-primary",
16− // pre blocks
17− "[&_pre]:bg-muted [&_pre]:border [&_pre]:border-border [&_pre]:rounded-md",
18− "[&_pre]:px-3 [&_pre]:py-2 [&_pre]:overflow-x-auto [&_pre]:my-2 [&_pre]:text-xs [&_pre]:leading-relaxed",
19− "[&_pre_code]:bg-transparent [&_pre_code]:border-0 [&_pre_code]:p-0 [&_pre_code]:text-inherit",
2036 // links
2137 "[&_a]:text-primary [&_a]:underline [&_a]:underline-offset-2",
2238 "[&_a]:decoration-primary/30 hover:[&_a]:decoration-primary/80",
@@ -43,7 +59,10 @@ const PROSE_CLASSES = [ · 20 unmodified lines
4359 export function Markdown(props: { children: string; className?: string }) {
4460 return (
4561 <div className={props.className ? `${PROSE_CLASSES} ${props.className}` : PROSE_CLASSES}>
46− <Streamdown plugins={{ code: codePlugin }} controls={{ code: true }} linkSafety={{ enabled: false }}>
62+ <Streamdown
63+ linkSafety={{ enabled: false }}
64+ components={{ pre: PreBlock as never }}
65+ >
4766 {props.children}
4867 </Streamdown>
4968 </div>

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t