@marimo-team/islands 0.23.9-dev4 → 0.23.9-dev41

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 (97) hide show
  1. package/dist/{ConnectedDataExplorerComponent-OzrfMM5L.js → ConnectedDataExplorerComponent-CyV83R2m.js} +4 -4
  2. package/dist/assets/__vite-browser-external-Ci2ZQfXU.js +1 -0
  3. package/dist/assets/{worker-CpBbwbQo.js → worker-ip3AI_sN.js} +2 -2
  4. package/dist/{chat-ui-BDI3FMI8.js → chat-ui-ChD4VvCo.js} +3060 -3033
  5. package/dist/{code-visibility-VZebNmSs.js → code-visibility-s3OWNKLN.js} +1634 -1314
  6. package/dist/{formats-DQ5qjo_Q.js → formats-DHxc-FdY.js} +1 -1
  7. package/dist/{glide-data-editor-DqRY9naW.js → glide-data-editor-BOmK9ETQ.js} +2 -2
  8. package/dist/{html-to-image-CiSinpSR.js → html-to-image-BHv7CEU_.js} +2145 -2153
  9. package/dist/{input-CZD2z6X2.js → input-_2sjvfne.js} +1 -1
  10. package/dist/main.js +1522 -1556
  11. package/dist/{mermaid-IU93XzmY.js → mermaid-lXOw5Py9.js} +2 -2
  12. package/dist/{process-output-5qJjMRKh.js → process-output-BvySRgli.js} +33 -25
  13. package/dist/{reveal-component-DZtPMEoM.js → reveal-component-DCO6zm_5.js} +17 -17
  14. package/dist/{spec-a6DaqW__.js → spec-B96zNUEA.js} +1 -1
  15. package/dist/style.css +1 -1
  16. package/dist/{toDate-ZVVIBmdk.js → toDate-x-WRDCH7.js} +1 -1
  17. package/dist/{useAsyncData-C008zUPi.js → useAsyncData-iRgKDT5s.js} +1 -1
  18. package/dist/{useDeepCompareMemoize-BrA3_n61.js → useDeepCompareMemoize-CkQ57VS2.js} +1 -1
  19. package/dist/{useLifecycle-BNaoJ5a4.js → useLifecycle-BBO9PIph.js} +1 -1
  20. package/dist/{useTheme-7O0YWlE5.js → useTheme-DHIrRQOe.js} +34 -21
  21. package/dist/{vega-component-DJNmOdUj.js → vega-component-Dq-SH463.js} +5 -5
  22. package/package.json +1 -1
  23. package/src/components/ai/__tests__/ai-utils.test.ts +43 -38
  24. package/src/components/ai/ai-model-dropdown.tsx +2 -2
  25. package/src/components/app-config/ai-config.tsx +147 -16
  26. package/src/components/app-config/user-config-form.tsx +37 -1
  27. package/src/components/chat/__tests__/chat-utils.test.ts +269 -0
  28. package/src/components/chat/chat-panel.tsx +38 -5
  29. package/src/components/chat/chat-utils.ts +14 -58
  30. package/src/components/data-table/TableBottomBar.tsx +27 -6
  31. package/src/components/data-table/TableTopBar.tsx +7 -1
  32. package/src/components/data-table/__tests__/TableBottomBar.test.tsx +73 -0
  33. package/src/components/data-table/__tests__/column-explorer.test.tsx +128 -0
  34. package/src/components/data-table/__tests__/data-table.test.tsx +52 -1
  35. package/src/components/data-table/__tests__/header-items.test.tsx +257 -1
  36. package/src/components/data-table/__tests__/useColumnVisibility.test.ts +42 -0
  37. package/src/components/data-table/column-explorer-panel/column-explorer.tsx +98 -26
  38. package/src/components/data-table/column-header.tsx +19 -12
  39. package/src/components/data-table/columns.tsx +3 -4
  40. package/src/components/data-table/data-table.tsx +37 -0
  41. package/src/components/data-table/export-actions.tsx +36 -18
  42. package/src/components/data-table/header-items.tsx +58 -17
  43. package/src/components/data-table/hooks/use-column-visibility.ts +56 -0
  44. package/src/components/data-table/pagination.tsx +16 -3
  45. package/src/components/data-table/schemas.ts +2 -2
  46. package/src/components/data-table/table-explorer-panel/table-explorer-panel.tsx +16 -6
  47. package/src/components/databases/display.tsx +2 -0
  48. package/src/components/datasources/__tests__/utils.test.ts +82 -0
  49. package/src/components/datasources/utils.ts +16 -15
  50. package/src/components/editor/actions/pair-with-agent-modal.tsx +1 -0
  51. package/src/components/editor/actions/useCellActionButton.tsx +3 -3
  52. package/src/components/editor/actions/useNotebookActions.tsx +5 -2
  53. package/src/components/editor/cell/code/cell-editor.tsx +7 -4
  54. package/src/components/editor/chrome/types.ts +13 -6
  55. package/src/components/editor/chrome/wrapper/app-chrome.tsx +6 -4
  56. package/src/components/editor/chrome/wrapper/footer-items/ai-status.tsx +10 -1
  57. package/src/components/editor/chrome/wrapper/sidebar.tsx +7 -5
  58. package/src/components/editor/errors/auto-fix.tsx +3 -3
  59. package/src/components/editor/errors/mangled-local-chip.tsx +50 -0
  60. package/src/components/editor/navigation/__tests__/navigation.test.ts +15 -0
  61. package/src/components/editor/navigation/navigation.ts +5 -0
  62. package/src/components/editor/output/MarimoErrorOutput.tsx +110 -27
  63. package/src/components/editor/output/MarimoTracebackOutput.tsx +55 -37
  64. package/src/components/editor/renderers/cell-array.tsx +27 -24
  65. package/src/components/editor/renderers/slides-layout/slides-layout.tsx +1 -1
  66. package/src/components/slides/reveal-component.tsx +3 -3
  67. package/src/components/slides/slide-form.tsx +11 -3
  68. package/src/components/static-html/static-banner.tsx +28 -22
  69. package/src/core/ai/__tests__/model-registry.test.ts +72 -60
  70. package/src/core/ai/model-registry.ts +33 -28
  71. package/src/core/cells/__tests__/actions.test.ts +48 -0
  72. package/src/core/cells/actions.ts +5 -6
  73. package/src/core/codemirror/__tests__/setup.test.ts +29 -0
  74. package/src/core/codemirror/cells/traceback-decorations.ts +1 -1
  75. package/src/core/codemirror/cm.ts +3 -2
  76. package/src/core/codemirror/completion/hints.ts +4 -1
  77. package/src/core/codemirror/format.ts +1 -0
  78. package/src/core/codemirror/keymaps/vim.ts +63 -0
  79. package/src/core/codemirror/language/languages/sql/sql.ts +1 -0
  80. package/src/core/codemirror/language/languages/sql/utils.ts +2 -0
  81. package/src/core/config/__tests__/config-schema.test.ts +4 -0
  82. package/src/core/config/config-schema.ts +4 -0
  83. package/src/core/config/config.ts +16 -0
  84. package/src/css/app/Cell.css +0 -1
  85. package/src/plugins/impl/DataTablePlugin.tsx +94 -33
  86. package/src/plugins/impl/__tests__/DataTablePlugin.test.tsx +1 -0
  87. package/src/plugins/impl/chat/ChatPlugin.tsx +7 -1
  88. package/src/plugins/impl/chat/__tests__/chat-ui.test.ts +278 -0
  89. package/src/plugins/impl/chat/chat-ui.tsx +106 -59
  90. package/src/plugins/impl/chat/types.ts +5 -0
  91. package/src/plugins/impl/data-frames/DataFramePlugin.tsx +8 -6
  92. package/src/stories/dataframe.stories.tsx +1 -0
  93. package/src/utils/__tests__/json-parser.test.ts +1 -69
  94. package/src/utils/__tests__/local-variables.test.ts +132 -0
  95. package/src/utils/json/json-parser.ts +0 -30
  96. package/src/utils/local-variables.ts +67 -0
  97. package/dist/assets/__vite-browser-external-CAdMKBac.js +0 -1
@@ -27,6 +27,7 @@ import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
27
27
  import { LazyActivity } from "@/components/utils/lazy-mount";
28
28
  import { cellErrorCount } from "@/core/cells/cells";
29
29
  import { capabilitiesAtom } from "@/core/config/capabilities";
30
+ import { aiEnabledAtom } from "@/core/config/config";
30
31
  import { getFeatureFlag } from "@/core/config/feature-flag";
31
32
  import { cn } from "@/utils/cn";
32
33
  import { ErrorBoundary } from "../../boundary/ErrorBoundary";
@@ -93,18 +94,19 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {
93
94
  const [panelLayout, setPanelLayout] = useAtom(panelLayoutAtom);
94
95
  // Subscribe to capabilities to re-render when they change (e.g., terminal capability)
95
96
  const capabilities = useAtomValue(capabilitiesAtom);
97
+ const aiEnabled = useAtomValue(aiEnabledAtom);
96
98
 
97
99
  // Convert current developer panel items to PanelDescriptors
98
100
  // Filter out hidden panels (e.g., terminal when capability is not available)
99
101
  const devPanelItems = useMemo(() => {
100
102
  return panelLayout.developerPanel.flatMap((id) => {
101
103
  const panel = PANEL_MAP.get(id);
102
- if (!panel || isPanelHidden(panel, capabilities)) {
104
+ if (!panel || isPanelHidden({ panel, capabilities, aiEnabled })) {
103
105
  return [];
104
106
  }
105
107
  return [panel];
106
108
  });
107
- }, [panelLayout.developerPanel, capabilities]);
109
+ }, [panelLayout.developerPanel, capabilities, aiEnabled]);
108
110
 
109
111
  const handleSetDevPanelItems = (items: PanelDescriptor[]) => {
110
112
  setPanelLayout((prev) => ({
@@ -141,7 +143,7 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {
141
143
  const availableDevPanels = useMemo(() => {
142
144
  const sidebarIds = new Set(panelLayout.sidebar);
143
145
  return PANELS.filter((p) => {
144
- if (isPanelHidden(p, capabilities)) {
146
+ if (isPanelHidden({ panel: p, capabilities, aiEnabled })) {
145
147
  return false;
146
148
  }
147
149
  // Exclude panels that are in the sidebar
@@ -150,7 +152,7 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {
150
152
  }
151
153
  return true;
152
154
  });
153
- }, [panelLayout.sidebar, capabilities]);
155
+ }, [panelLayout.sidebar, capabilities, aiEnabled]);
154
156
 
155
157
  const emitResizeEvent = useEvent(() => {
156
158
  // HACK: Unfortunately, we have to do this twice to make sure the
@@ -4,18 +4,27 @@ import { useAtomValue } from "jotai";
4
4
  import { SparklesIcon } from "lucide-react";
5
5
  import React from "react";
6
6
  import { useOpenSettingsToTab } from "@/components/app-config/state";
7
- import { aiAtom, aiEnabledAtom } from "@/core/config/config";
7
+ import {
8
+ aiAtom,
9
+ aiEnabledAtom,
10
+ aiModelConfiguredAtom,
11
+ } from "@/core/config/config";
8
12
  import { DEFAULT_AI_MODEL } from "@/core/config/config-schema";
9
13
  import { FooterItem } from "../footer-item";
10
14
 
11
15
  export const AIStatusIcon: React.FC = () => {
12
16
  const ai = useAtomValue(aiAtom);
13
17
  const aiEnabled = useAtomValue(aiEnabledAtom);
18
+ const aiModelConfigured = useAtomValue(aiModelConfiguredAtom);
14
19
  const chatModel = ai?.models?.chat_model || DEFAULT_AI_MODEL;
15
20
  const editModel = ai?.models?.edit_model || chatModel;
16
21
  const { handleClick } = useOpenSettingsToTab();
17
22
 
18
23
  if (!aiEnabled) {
24
+ return null;
25
+ }
26
+
27
+ if (!aiModelConfigured) {
19
28
  return (
20
29
  <FooterItem
21
30
  tooltip="Assist is disabled"
@@ -12,6 +12,7 @@ import {
12
12
  notebookQueuedOrRunningCountAtom,
13
13
  } from "@/core/cells/cells";
14
14
  import { capabilitiesAtom } from "@/core/config/capabilities";
15
+ import { aiEnabledAtom } from "@/core/config/config";
15
16
  import { cn } from "@/utils/cn";
16
17
  import { FeedbackButton } from "../components/feedback-button";
17
18
  import { panelLayoutAtom, useChromeActions, useChromeState } from "../state";
@@ -30,6 +31,7 @@ export const Sidebar: React.FC = () => {
30
31
  const [panelLayout, setPanelLayout] = useAtom(panelLayoutAtom);
31
32
  // Subscribe to capabilities to re-render when they change
32
33
  const capabilities = useAtomValue(capabilitiesAtom);
34
+ const aiEnabled = useAtomValue(aiEnabledAtom);
33
35
 
34
36
  const renderIcon = ({ Icon }: PanelDescriptor, className?: string) => {
35
37
  return <Icon className={cn("h-5 w-5", className)} />;
@@ -40,7 +42,7 @@ export const Sidebar: React.FC = () => {
40
42
  const availableSidebarPanels = useMemo(() => {
41
43
  const devPanelIds = new Set(panelLayout.developerPanel);
42
44
  return PANELS.filter((p) => {
43
- if (isPanelHidden(p, capabilities)) {
45
+ if (isPanelHidden({ panel: p, capabilities, aiEnabled })) {
44
46
  return false;
45
47
  }
46
48
  // Exclude panels that are in the developer panel
@@ -49,19 +51,19 @@ export const Sidebar: React.FC = () => {
49
51
  }
50
52
  return true;
51
53
  });
52
- }, [panelLayout.developerPanel, capabilities]);
54
+ }, [panelLayout.developerPanel, capabilities, aiEnabled]);
53
55
 
54
56
  // Convert current sidebar items to PanelDescriptors
55
57
  // Filter out hidden panels (e.g., when capability is not available)
56
58
  const sidebarItems = useMemo(() => {
57
59
  return panelLayout.sidebar.flatMap((id) => {
58
60
  const panel = PANEL_MAP.get(id);
59
- if (!panel || isPanelHidden(panel, capabilities)) {
61
+ if (!panel || isPanelHidden({ panel, capabilities, aiEnabled })) {
60
62
  return [];
61
63
  }
62
64
  return [panel];
63
65
  });
64
- }, [panelLayout.sidebar, capabilities]);
66
+ }, [panelLayout.sidebar, capabilities, aiEnabled]);
65
67
 
66
68
  const handleSetSidebarItems = (items: PanelDescriptor[]) => {
67
69
  setPanelLayout((prev) => ({
@@ -218,7 +220,7 @@ const SidebarItem: React.FC<
218
220
  // Render as div when not clickable (e.g., inside ReorderableList)
219
221
  // This avoids nested interactive elements which break react-aria's drag behavior
220
222
  const content = onClick ? (
221
- <button className={itemClassName} onClick={onClick}>
223
+ <button type="button" className={itemClassName} onClick={onClick}>
222
224
  {children}
223
225
  </button>
224
226
  ) : (
@@ -13,7 +13,7 @@ import { Tooltip } from "@/components/ui/tooltip";
13
13
  import { aiCompletionCellAtom } from "@/core/ai/state";
14
14
  import { notebookAtom, useCellActions } from "@/core/cells/cells";
15
15
  import type { CellId } from "@/core/cells/ids";
16
- import { aiEnabledAtom } from "@/core/config/config";
16
+ import { aiFeaturesEnabledAtom } from "@/core/config/config";
17
17
  import { getAutoFixes } from "@/core/errors/errors";
18
18
  import type { MarimoError } from "@/core/kernel/messages";
19
19
  import { cn } from "@/utils/cn";
@@ -30,9 +30,9 @@ export const AutoFixButton = ({
30
30
  }) => {
31
31
  const store = useStore();
32
32
  const { createNewCell } = useCellActions();
33
- const aiEnabled = useAtomValue(aiEnabledAtom);
33
+ const aiFeaturesEnabled = useAtomValue(aiFeaturesEnabledAtom);
34
34
  const autoFixes = errors.flatMap((error) =>
35
- getAutoFixes(error, { aiEnabled }),
35
+ getAutoFixes(error, { aiEnabled: aiFeaturesEnabled }),
36
36
  );
37
37
  const setAiCompletionCell = useSetAtom(aiCompletionCellAtom);
38
38
 
@@ -0,0 +1,50 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+ import type { JSX } from "react";
3
+ import { Tooltip } from "@/components/ui/tooltip";
4
+ import type { MangledSegment, UnmangledLocal } from "@/utils/local-variables";
5
+ import { CellLinkError } from "../links/cell-link";
6
+
7
+ interface Props {
8
+ local: UnmangledLocal;
9
+ }
10
+
11
+ /**
12
+ * Renders a compiler-mangled cell-local variable as the user's original name
13
+ * (e.g. `_a`) with a tooltip linking to the defining cell.
14
+ */
15
+ export const MangledLocalChip = ({ local }: Props): JSX.Element => {
16
+ const tooltipContent = (
17
+ <div className="max-w-xs">
18
+ Local variable <span className="font-code">{local.name}</span> in cell{" "}
19
+ <CellLinkError cellId={local.cellId} />.
20
+ </div>
21
+ );
22
+
23
+ return (
24
+ <Tooltip content={tooltipContent}>
25
+ <span className="font-code cursor-help">{local.name}</span>
26
+ </Tooltip>
27
+ );
28
+ };
29
+
30
+ interface MangledSegmentsProps {
31
+ segments: MangledSegment[];
32
+ }
33
+
34
+ /**
35
+ * Render an array of `splitMangledLocals` segments as alternating text and
36
+ * `<MangledLocalChip>` nodes.
37
+ */
38
+ export const MangledSegments = ({
39
+ segments,
40
+ }: MangledSegmentsProps): JSX.Element => (
41
+ <>
42
+ {segments.map((segment, idx) =>
43
+ typeof segment === "string" ? (
44
+ <span key={idx}>{segment}</span>
45
+ ) : (
46
+ <MangledLocalChip key={idx} local={segment} />
47
+ ),
48
+ )}
49
+ </>
50
+ );
@@ -1207,6 +1207,21 @@ describe("useCellNavigationProps", () => {
1207
1207
  });
1208
1208
 
1209
1209
  describe("AI completion functionality", () => {
1210
+ beforeEach(() => {
1211
+ const config = defaultUserConfig();
1212
+ store.set(userConfigAtom, {
1213
+ ...config,
1214
+ ai: {
1215
+ ...config.ai,
1216
+ models: {
1217
+ displayed_models: [],
1218
+ custom_models: [],
1219
+ edit_model: "openai/gpt-4o",
1220
+ },
1221
+ },
1222
+ });
1223
+ });
1224
+
1210
1225
  it("should toggle AI completion when shortcut is pressed", () => {
1211
1226
  const { result } = renderWithProvider(() =>
1212
1227
  useCellNavigationProps(cellId1, optionsWithMockEditor),
@@ -24,6 +24,7 @@ import { usePendingDeleteService } from "@/core/cells/pending-delete-service";
24
24
  import { scrollCellIntoView } from "@/core/cells/scrollCellIntoView";
25
25
  import {
26
26
  hotkeysAtom,
27
+ isAiFeatureEnabled,
27
28
  keymapPresetAtom,
28
29
  userConfigAtom,
29
30
  } from "@/core/config/config";
@@ -195,6 +196,7 @@ export function useCellNavigationProps(
195
196
  const pendingDeleteService = usePendingDeleteService();
196
197
  const deleteCells = useDeleteManyCellsCallback();
197
198
  const userConfig = useAtomValue(userConfigAtom);
199
+ const aiFeaturesEnabled = isAiFeatureEnabled(userConfig);
198
200
 
199
201
  // Wrap selection actions to clear pending cells on any selection change
200
202
  const selectionActions = {
@@ -496,6 +498,9 @@ export function useCellNavigationProps(
496
498
  return true;
497
499
  }),
498
500
  "cell.aiCompletion": (cellId) => {
501
+ if (!aiFeaturesEnabled) {
502
+ return false;
503
+ }
499
504
  let closed = false;
500
505
  setAiCompletionCell((v) => {
501
506
  // Toggle close
@@ -1,12 +1,16 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
+ import { useAtomValue } from "jotai";
3
4
  import {
5
+ ChevronDown,
6
+ ChevronRight,
7
+ InfoIcon,
4
8
  NotebookPenIcon,
5
9
  PackageIcon,
6
10
  SquareArrowOutUpRightIcon,
7
11
  TerminalIcon,
8
12
  } from "lucide-react";
9
- import { Fragment, type JSX } from "react";
13
+ import { Fragment, type JSX, useState } from "react";
10
14
  import {
11
15
  Accordion,
12
16
  AccordionContent,
@@ -16,16 +20,53 @@ import {
16
20
  import { Button } from "@/components/ui/button";
17
21
  import { Kbd } from "@/components/ui/kbd";
18
22
  import { ExternalLink } from "@/components/ui/links";
23
+ import { Tooltip } from "@/components/ui/tooltip";
19
24
  import type { CellId } from "@/core/cells/ids";
25
+ import { resolvedMarimoConfigAtom } from "@/core/config/config";
26
+ import { renderHTML } from "@/plugins/core/RenderHTML";
27
+ import { splitMangledLocals } from "@/utils/local-variables";
20
28
  import type { MarimoError } from "../../../core/kernel/messages";
21
29
  import { cn } from "../../../utils/cn";
22
30
  import { Alert, AlertTitle } from "../../ui/alert";
23
31
  import { openPackageManager } from "../chrome/panels/packages-utils";
24
32
  import { useChromeActions } from "../chrome/state";
25
33
  import { AutoFixButton } from "../errors/auto-fix";
34
+ import { MangledSegments } from "../errors/mangled-local-chip";
26
35
  import { CellLinkError } from "../links/cell-link";
27
36
  import { processTextForUrls } from "./console/text-rendering";
28
- import { renderHTML } from "@/plugins/core/RenderHTML";
37
+
38
+ const CollapsibleTraceback = ({
39
+ traceback,
40
+ }: {
41
+ traceback: string;
42
+ }): JSX.Element => {
43
+ const [isOpen, setIsOpen] = useState(true);
44
+ return (
45
+ <div className="mt-2">
46
+ <button
47
+ type="button"
48
+ onClick={() => setIsOpen(!isOpen)}
49
+ aria-expanded={isOpen}
50
+ aria-label={isOpen ? "Collapse traceback" : "Expand traceback"}
51
+ className="flex items-center gap-1 text-muted-foreground/70 hover:text-muted-foreground transition-colors"
52
+ >
53
+ {isOpen ? (
54
+ <ChevronDown className="h-3 w-3" />
55
+ ) : (
56
+ <ChevronRight className="h-3 w-3" />
57
+ )}
58
+ <span className="text-[0.6875rem] uppercase tracking-wider">
59
+ Traceback
60
+ </span>
61
+ </button>
62
+ {isOpen && (
63
+ <div className="font-code text-sm mt-1 p-3 bg-muted rounded border overflow-auto max-h-[50vh] cursor-text select-text">
64
+ {renderHTML({ html: traceback })}
65
+ </div>
66
+ )}
67
+ </div>
68
+ );
69
+ };
29
70
 
30
71
  const Tip = (props: {
31
72
  title?: string;
@@ -35,10 +76,13 @@ const Tip = (props: {
35
76
  return (
36
77
  <Accordion type="single" collapsible={true} className={props.className}>
37
78
  <AccordionItem value="item-1" className="text-muted-foreground">
38
- <AccordionTrigger className="pt-2 pb-2 font-normal">
79
+ <AccordionTrigger className="pt-2 pb-0 font-normal">
39
80
  {props.title ?? "Tip"}
40
81
  </AccordionTrigger>
41
- <AccordionContent className="mr-24 text-[0.84375rem]">
82
+ <AccordionContent
83
+ className="mr-24 text-[0.84375rem]"
84
+ wrapperClassName="pt-0 pb-2"
85
+ >
42
86
  {props.children}
43
87
  </AccordionContent>
44
88
  </AccordionItem>
@@ -61,10 +105,21 @@ export const MarimoErrorOutput = ({
61
105
  className,
62
106
  }: Props): JSX.Element => {
63
107
  const chromeActions = useChromeActions();
64
-
65
- let titleContents = "This cell wasn't run because it has errors";
108
+ // The console area (where tracebacks are shown) sits below the cell editor.
109
+ // When cell outputs are also displayed below the editor, the traceback is
110
+ // already adjacent, so the "See the console area" hint is redundant. It is
111
+ // only helpful when outputs are displayed above the editor.
112
+ const showConsoleHint =
113
+ useAtomValue(resolvedMarimoConfigAtom).display.cell_output === "above";
114
+
115
+ let titleContents: string | null =
116
+ "This cell wasn't run because it has errors";
66
117
  let alertVariant: "destructive" | "default" = "destructive";
67
118
  let titleColor = "text-error";
119
+ // A small muted overline shown above the title for static errors, where
120
+ // the cell genuinely never executes. These errors have no separate title:
121
+ // the body text already describes them, so the overline carries the status.
122
+ let statusOverline: string | null = null;
68
123
  const liStyle = "my-0.5 ml-8 text-muted-foreground/40";
69
124
 
70
125
  // Check for certain error types to adjust title and appearance
@@ -75,7 +130,6 @@ export const MarimoErrorOutput = ({
75
130
  } else if (errors.some((e) => e.type === "ancestor-prevented")) {
76
131
  titleContents = "Ancestor prevented from running";
77
132
  alertVariant = "default";
78
- titleColor = "text-muted-foreground";
79
133
  titleColor = "text-secondary-foreground";
80
134
  } else if (errors.some((e) => e.type === "ancestor-stopped")) {
81
135
  titleContents = "Ancestor stopped";
@@ -83,6 +137,19 @@ export const MarimoErrorOutput = ({
83
137
  titleColor = "text-secondary-foreground";
84
138
  } else if (errors.some((e) => e.type === "sql-error")) {
85
139
  titleContents = "SQL error";
140
+ } else if (
141
+ errors.some(
142
+ (e) =>
143
+ e.type === "multiple-defs" ||
144
+ e.type === "cycle" ||
145
+ e.type === "setup-refs" ||
146
+ e.type === "import-star",
147
+ )
148
+ ) {
149
+ // Static errors: the body text describes the problem, so there is no
150
+ // separate title — only the status overline.
151
+ titleContents = null;
152
+ statusOverline = "Cell not run";
86
153
  } else {
87
154
  // Check for exception type
88
155
  const exceptionError = errors.find((e) => e.type === "exception");
@@ -454,10 +521,13 @@ export const MarimoErrorOutput = ({
454
521
  error.exception_type === "NameError" &&
455
522
  error.msg.startsWith("name '_")
456
523
  ) {
524
+ const segments = splitMangledLocals(error.msg);
457
525
  return (
458
526
  <li className="my-2" key={`exception-${idx}`}>
459
527
  <div>
460
- <p className="text-muted-foreground">{error.msg}</p>
528
+ <p className="text-muted-foreground">
529
+ <MangledSegments segments={segments} />
530
+ </p>
461
531
  <p className="text-muted-foreground mt-2">
462
532
  Variables prefixed with an underscore are local to a cell{" "}
463
533
  (
@@ -470,9 +540,11 @@ export const MarimoErrorOutput = ({
470
540
  </ExternalLink>
471
541
  ).
472
542
  </p>
473
- <div className="text-muted-foreground mt-2">
474
- See the console area for a traceback.
475
- </div>
543
+ {showConsoleHint && (
544
+ <div className="text-muted-foreground mt-2">
545
+ See the console area for a traceback.
546
+ </div>
547
+ )}
476
548
  </div>
477
549
  </li>
478
550
  );
@@ -487,13 +559,13 @@ export const MarimoErrorOutput = ({
487
559
  {processTextForUrls(error.msg, `exception-${idx}`)}
488
560
  </p>
489
561
  {"traceback" in error && error.traceback ? (
490
- <div className="font-code text-sm mt-2 p-3 bg-muted rounded border overflow-auto max-h-[50vh] cursor-text select-text">
491
- {renderHTML({ html: error.traceback })}
492
- </div>
562
+ <CollapsibleTraceback traceback={error.traceback} />
493
563
  ) : (
494
- <div className="text-muted-foreground mt-2">
495
- See the console area for a traceback.
496
- </div>
564
+ showConsoleHint && (
565
+ <div className="text-muted-foreground mt-2">
566
+ See the console area for a traceback.
567
+ </div>
568
+ )
497
569
  )}
498
570
  </div>
499
571
  ) : (
@@ -501,9 +573,7 @@ export const MarimoErrorOutput = ({
501
573
  {processTextForUrls(error.msg, `exception-${idx}`)}
502
574
  <CellLinkError cellId={error.raising_cell} />
503
575
  {"traceback" in error && error.traceback && (
504
- <div className="font-code text-sm mt-2 p-3 bg-muted rounded border overflow-auto max-h-[50vh] cursor-text select-text">
505
- {renderHTML({ html: error.traceback })}
506
- </div>
576
+ <CollapsibleTraceback traceback={error.traceback} />
507
577
  )}
508
578
  </div>
509
579
  )}
@@ -628,23 +698,36 @@ export const MarimoErrorOutput = ({
628
698
  };
629
699
 
630
700
  const title = (
631
- <AlertTitle className={`font-code font-medium tracking-wide ${titleColor}`}>
632
- {titleContents}
633
- </AlertTitle>
701
+ <div className="space-y-0.5">
702
+ {statusOverline && (
703
+ <div className="flex items-center gap-1 font-code text-[0.6875rem] uppercase tracking-wider text-muted-foreground/70">
704
+ {statusOverline}
705
+ <Tooltip
706
+ content="marimo didn't run this cell because it detected an error."
707
+ delayDuration={200}
708
+ >
709
+ <InfoIcon className="size-3 cursor-help" />
710
+ </Tooltip>
711
+ </div>
712
+ )}
713
+ {titleContents && (
714
+ <AlertTitle className={`font-code font-medium ${titleColor}`}>
715
+ {titleContents}
716
+ </AlertTitle>
717
+ )}
718
+ </div>
634
719
  );
635
720
 
636
721
  return (
637
722
  <Alert
638
723
  variant={alertVariant}
639
724
  className={cn(
640
- "border-none font-code text-sm text-[0.84375rem] px-0 text-muted-foreground normal [&:has(svg)]:pl-0 space-y-4",
725
+ "border-none font-code text-sm text-[0.84375rem] p-0 text-muted-foreground normal [&:has(svg)]:pl-0 space-y-2",
641
726
  className,
642
727
  )}
643
728
  >
644
729
  {title}
645
- <div>
646
- <div className="flex flex-col gap-8">{renderMessages()}</div>
647
- </div>
730
+ <div className="flex flex-col gap-4">{renderMessages()}</div>
648
731
  </Alert>
649
732
  );
650
733
  };
@@ -5,17 +5,13 @@ import { useAtomValue } from "jotai";
5
5
  import {
6
6
  BugPlayIcon,
7
7
  ChevronDown,
8
+ ChevronRight,
8
9
  CopyIcon,
9
10
  ExternalLinkIcon,
10
11
  MessageCircleIcon,
11
12
  SearchIcon,
12
13
  } from "lucide-react";
13
14
  import { type JSX, useState } from "react";
14
- import {
15
- Accordion,
16
- AccordionContent,
17
- AccordionItem,
18
- } from "@/components/ui/accordion";
19
15
  import { Button } from "@/components/ui/button";
20
16
  import {
21
17
  DropdownMenu,
@@ -29,20 +25,24 @@ import { getCellEditorView } from "@/core/cells/cells";
29
25
  import type { CellId } from "@/core/cells/ids";
30
26
  import { SCRATCH_CELL_ID } from "@/core/cells/ids";
31
27
  import { insertDebuggerAtLine } from "@/core/codemirror/editing/debugging";
32
- import { aiEnabledAtom } from "@/core/config/config";
28
+ import { aiFeaturesEnabledAtom } from "@/core/config/config";
33
29
  import { getRequestClient } from "@/core/network/requests";
34
30
  import { isStaticNotebook } from "@/core/static/static-state";
35
31
  import { isWasm } from "@/core/wasm/utils";
36
32
  import { renderHTML } from "@/plugins/core/RenderHTML";
37
33
  import { sanitizeHtml } from "@/plugins/core/sanitize-html";
38
34
  import { copyToClipboard } from "@/utils/copy";
35
+ import {
36
+ containsMangledLocal,
37
+ splitMangledLocals,
38
+ } from "@/utils/local-variables";
39
39
  import {
40
40
  elementContainsMarimoCellFile,
41
41
  extractAllTracebackInfo,
42
42
  getTracebackInfo,
43
43
  } from "@/utils/traceback";
44
- import { cn } from "../../../utils/cn";
45
44
  import { AIFixButton } from "../errors/auto-fix";
45
+ import { MangledSegments } from "../errors/mangled-local-chip";
46
46
  import { CellLinkTraceback } from "../links/cell-link";
47
47
  import type { OnRefactorWithAI } from "../Output";
48
48
 
@@ -52,8 +52,6 @@ interface Props {
52
52
  onRefactorWithAI?: OnRefactorWithAI;
53
53
  }
54
54
 
55
- const KEY = "item";
56
-
57
55
  /**
58
56
  * List of errors due to violations of Marimo semantics.
59
57
  */
@@ -64,12 +62,15 @@ export const MarimoTracebackOutput = ({
64
62
  }: Props): JSX.Element => {
65
63
  const htmlTraceback = renderHTML({
66
64
  html: traceback,
67
- additionalReplacements: [replaceTracebackFilenames, replaceTracebackPrefix],
65
+ additionalReplacements: [
66
+ replaceTracebackFilenames,
67
+ replaceTracebackPrefix,
68
+ replaceMangledLocal,
69
+ ],
68
70
  });
69
- const [expanded, setExpanded] = useState(true);
70
71
 
71
72
  const lastTracebackLine = lastLine(traceback);
72
- const aiEnabled = useAtomValue(aiEnabledAtom);
73
+ const aiFeaturesEnabled = useAtomValue(aiFeaturesEnabledAtom);
73
74
 
74
75
  // Get last traceback info
75
76
  const tracebackInfo = extractAllTracebackInfo(traceback)?.at(0);
@@ -82,10 +83,13 @@ export const MarimoTracebackOutput = ({
82
83
  !isStaticNotebook() &&
83
84
  cellId !== SCRATCH_CELL_ID;
84
85
 
85
- const showAIFix = onRefactorWithAI && aiEnabled && !isStaticNotebook();
86
+ const showAIFix =
87
+ onRefactorWithAI && aiFeaturesEnabled && !isStaticNotebook();
86
88
 
87
89
  const showSearch = !isStaticNotebook();
88
90
 
91
+ const [isOpen, setIsOpen] = useState(true);
92
+
89
93
  const handleRefactorWithAI = (triggerImmediately: boolean) => {
90
94
  onRefactorWithAI?.({
91
95
  prompt: `My code gives the following error:\n\n${lastTracebackLine}`,
@@ -93,32 +97,29 @@ export const MarimoTracebackOutput = ({
93
97
  });
94
98
  };
95
99
 
96
- const [error, errorMessage] = lastTracebackLine.split(":", 2);
97
-
98
100
  return (
99
101
  <div className="flex flex-col gap-2 min-w-full w-fit">
100
- <Accordion type="single" collapsible={true} value={expanded ? KEY : ""}>
101
- <AccordionItem value={KEY} className="border-none">
102
- <div
103
- className="flex gap-2 h-10 px-2 hover:bg-muted rounded-sm select-none items-center cursor-pointer transition-all"
104
- onClick={() => setExpanded((prev) => !prev)}
105
- >
106
- <ChevronDown
107
- className={cn(
108
- "h-4 w-4 text-muted-foreground transition-transform duration-200 shrink-0",
109
- expanded ? "rotate-180" : "rotate-0",
110
- )}
111
- />
112
- <div className="text-sm inline font-mono">
113
- <span className="text-destructive">{error || "Error"}:</span>{" "}
114
- {errorMessage}
115
- </div>
116
- </div>
117
- <AccordionContent className="text-muted-foreground px-4 pt-2 text-xs overflow-auto">
118
- {htmlTraceback}
119
- </AccordionContent>
120
- </AccordionItem>
121
- </Accordion>
102
+ <button
103
+ type="button"
104
+ onClick={() => setIsOpen(!isOpen)}
105
+ aria-expanded={isOpen}
106
+ aria-label={isOpen ? "Collapse traceback" : "Expand traceback"}
107
+ className="self-start flex items-center gap-1 pt-2 text-muted-foreground/70 hover:text-muted-foreground transition-colors"
108
+ >
109
+ {isOpen ? (
110
+ <ChevronDown className="h-3 w-3" />
111
+ ) : (
112
+ <ChevronRight className="h-3 w-3" />
113
+ )}
114
+ <span className="text-[0.6875rem] uppercase tracking-wider">
115
+ Traceback
116
+ </span>
117
+ </button>
118
+ {isOpen && (
119
+ <div className="text-muted-foreground pr-4 text-xs overflow-auto">
120
+ {htmlTraceback}
121
+ </div>
122
+ )}
122
123
  <div className="flex gap-2">
123
124
  {showAIFix && (
124
125
  <AIFixButton
@@ -249,6 +250,23 @@ export const replaceTracebackFilenames = (domNode: DOMNode) => {
249
250
  }
250
251
  };
251
252
 
253
+ /**
254
+ * Replace any cell-local mangled name (`_cell_<id>_<name>`) inside a text
255
+ * node with a {@link MangledLocalChip}. The mangled name appears in both
256
+ * the final `NameError:` line and inside compiled-cell source lines because
257
+ * the compiler rewrites underscore-prefixed references at AST-visit time.
258
+ */
259
+ export const replaceMangledLocal = (domNode: DOMNode) => {
260
+ if (!(domNode instanceof Text) || !domNode.nodeValue) {
261
+ return;
262
+ }
263
+ if (!containsMangledLocal(domNode.nodeValue)) {
264
+ return;
265
+ }
266
+ const segments = splitMangledLocals(domNode.nodeValue);
267
+ return <MangledSegments segments={segments} />;
268
+ };
269
+
252
270
  export const replaceTracebackPrefix = (domNode: DOMNode) => {
253
271
  if (
254
272
  domNode instanceof Text &&