@marimo-team/islands 0.23.14-dev3 → 0.23.14-dev31

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-Du3_nUzI.js → ConnectedDataExplorerComponent-DXBx_nQg.js} +4 -4
  2. package/dist/{chat-ui-CsPewo4h.js → chat-ui-CO8WuXGb.js} +3243 -3039
  3. package/dist/{click-outside-container-BDd67_1U.js → click-outside-container-BLPjMamz.js} +141 -113
  4. package/dist/{code-visibility-BbnxGblD.js → code-visibility-0uqOIXQg.js} +1122 -924
  5. package/dist/data-grid-overlay-editor-C6lxUJp-.js +136 -0
  6. package/dist/{dist-D_bzzWBm.js → dist-Bf9f8MuT.js} +3 -3
  7. package/dist/{formats-d6MhLuQ9.js → formats-WsOgyW_K.js} +1 -1
  8. package/dist/{glide-data-editor-DkzAInWG.js → glide-data-editor-7wxMGXjG.js} +2084 -1889
  9. package/dist/{html-to-image-DXwLcQ6l.js → html-to-image-DLSOS-bE.js} +2351 -2282
  10. package/dist/{input-CbEz_aj_.js → input-BSdZp5Ng.js} +1 -1
  11. package/dist/main.js +1231 -1133
  12. package/dist/{mermaid-CJW9vIyO.js → mermaid-D-HYBMEV.js} +2 -2
  13. package/dist/{number-overlay-editor-D-a0qCT8.js → number-overlay-editor-BLJXvX9c.js} +1 -1
  14. package/dist/{process-output-C6_e1pT_.js → process-output-B9ysqk1y.js} +1 -1
  15. package/dist/{reveal-component-B2onAQFS.js → reveal-component-DxTNjwZw.js} +600 -596
  16. package/dist/{spec-Bv-XlYiv.js → spec-CnTgI25l.js} +1 -1
  17. package/dist/style.css +1 -1
  18. package/dist/{toDate-D-l5s8nn.js → toDate-D1Z7ZXWh.js} +1 -1
  19. package/dist/{useAsyncData-1Dhzjfwf.js → useAsyncData-BMc8itk2.js} +1 -1
  20. package/dist/{useDeepCompareMemoize-CDWT3BDz.js → useDeepCompareMemoize-ZwmDBRDY.js} +1 -1
  21. package/dist/{useLifecycle-AHlswLw-.js → useLifecycle-CxffarYV.js} +1 -1
  22. package/dist/{useTheme-BrYvK-_A.js → useTheme-yGsGEk82.js} +26 -24
  23. package/dist/{vega-component-Pk6lyc_a.js → vega-component-BFJTyykA.js} +5 -5
  24. package/package.json +3 -3
  25. package/src/components/chat/acp/agent-panel.tsx +35 -1
  26. package/src/components/chat/chat-panel.tsx +68 -29
  27. package/src/components/data-table/__tests__/column-explorer.test.tsx +25 -0
  28. package/src/components/data-table/__tests__/column-visibility-dropdown.test.tsx +60 -3
  29. package/src/components/data-table/charts/__tests__/merge-index-fields.test.ts +33 -0
  30. package/src/components/data-table/charts/charts.tsx +23 -1
  31. package/src/components/data-table/column-explorer-panel/column-explorer.tsx +33 -12
  32. package/src/components/data-table/column-visibility-dropdown.tsx +15 -0
  33. package/src/components/editor/actions/useNotebookActions.tsx +2 -2
  34. package/src/components/editor/chrome/panels/snippets-panel.tsx +5 -2
  35. package/src/components/editor/chrome/wrapper/__tests__/useOpenAiAssistant.test.ts +36 -0
  36. package/src/components/editor/chrome/wrapper/footer-items/pyodide-status.tsx +6 -36
  37. package/src/components/editor/chrome/wrapper/useAiPanel.ts +3 -1
  38. package/src/components/editor/chrome/wrapper/useOpenAiAssistant.ts +88 -0
  39. package/src/components/editor/code/readonly-python-code.tsx +16 -2
  40. package/src/components/editor/errors/__tests__/auto-fix.test.ts +23 -0
  41. package/src/components/editor/errors/auto-fix.tsx +88 -34
  42. package/src/components/editor/errors/fix-mode.ts +1 -1
  43. package/src/components/editor/output/MarimoTracebackOutput.tsx +10 -1
  44. package/src/components/editor/output/__tests__/traceback.test.tsx +14 -6
  45. package/src/components/editor/renderers/grid-layout/grid-layout.tsx +7 -2
  46. package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +6 -2
  47. package/src/components/lifecycle/ProgressiveBoundary.tsx +42 -0
  48. package/src/components/lifecycle/RuntimeStatusBadge.tsx +59 -0
  49. package/src/components/lifecycle/__tests__/ProgressiveBoundary.test.tsx +147 -0
  50. package/src/components/lifecycle/__tests__/RuntimeStatusBadge.test.tsx +72 -0
  51. package/src/components/slides/__tests__/slide.test.tsx +33 -0
  52. package/src/components/slides/minimap.tsx +7 -1
  53. package/src/components/slides/reveal-component.tsx +3 -0
  54. package/src/components/slides/slide-cell-view.tsx +10 -6
  55. package/src/components/slides/slide.tsx +16 -13
  56. package/src/core/ai/config.ts +2 -2
  57. package/src/core/ai/context/__tests__/registry.test.ts +133 -3
  58. package/src/core/ai/context/providers/__tests__/datasource.test.ts +3 -1
  59. package/src/core/ai/context/providers/__tests__/error.test.ts +200 -15
  60. package/src/core/ai/context/providers/datasource.ts +27 -2
  61. package/src/core/ai/context/providers/error.ts +226 -36
  62. package/src/core/ai/context/registry.ts +77 -43
  63. package/src/core/ai/state.ts +11 -0
  64. package/src/core/cells/__tests__/readonly-code-display.test.ts +46 -0
  65. package/src/core/cells/readonly-code-display.ts +35 -0
  66. package/src/core/codemirror/__tests__/setup.test.ts +33 -1
  67. package/src/core/codemirror/ai/resources.ts +15 -10
  68. package/src/core/codemirror/cells/extensions.ts +1 -4
  69. package/src/core/codemirror/completion/__tests__/signature-hint.test.ts +94 -0
  70. package/src/core/codemirror/completion/completer.ts +12 -1
  71. package/src/core/codemirror/completion/signature-hint.ts +68 -0
  72. package/src/core/codemirror/language/languages/python.ts +10 -4
  73. package/src/core/codemirror/utils.ts +15 -0
  74. package/src/core/edit-app.tsx +8 -5
  75. package/src/core/errors/errors.ts +2 -1
  76. package/src/core/lifecycle/__tests__/render-policy.test.ts +247 -0
  77. package/src/core/lifecycle/render-policy.ts +125 -0
  78. package/src/core/mime.ts +11 -4
  79. package/src/core/run-app.tsx +27 -23
  80. package/src/core/runtime/__tests__/adapter.test.ts +160 -0
  81. package/src/core/runtime/adapter.ts +182 -0
  82. package/src/core/wasm/PyodideLoader.tsx +20 -62
  83. package/src/core/wasm/bridge.ts +9 -4
  84. package/src/core/wasm/state.ts +8 -19
  85. package/src/css/app/codemirror.css +14 -0
  86. package/src/hooks/__tests__/useDelayElapsed.test.tsx +55 -0
  87. package/src/hooks/useDelayElapsed.ts +27 -0
  88. package/src/plugins/impl/DataTablePlugin.tsx +1 -0
  89. package/src/plugins/impl/anywidget/AnyWidgetPlugin.tsx +53 -2
  90. package/src/plugins/impl/anywidget/__tests__/AnyWidgetPlugin.test.tsx +52 -2
  91. package/src/plugins/impl/data-editor/__tests__/glide-data-editor.test.tsx +187 -0
  92. package/src/plugins/impl/data-editor/glide-data-editor.tsx +6 -0
  93. package/src/plugins/impl/data-editor/glide-portal.tsx +73 -0
  94. package/dist/data-grid-overlay-editor-mfEJ5475.js +0 -128
  95. package/src/core/ai/context/providers/__tests__/__snapshots__/error.test.ts.snap +0 -3
  96. package/src/core/wasm/__tests__/PyodideLoader.test.ts +0 -72
  97. package/src/core/wasm/__tests__/state.test.ts +0 -124
@@ -11,6 +11,7 @@ import {
11
11
  resourceDecorations,
12
12
  resourceInputFilter,
13
13
  resourcesField,
14
+ resourceSync,
14
15
  resourceTheme,
15
16
  } from "@marimo-team/codemirror-mcp";
16
17
  import {
@@ -38,25 +39,28 @@ const NONE_RESOURCE_FORMAT_COMPLETION = {
38
39
  },
39
40
  };
40
41
 
42
+ function getRegistryResources(store: JotaiStore): Resource[] {
43
+ const registry = getAIContextRegistry(store);
44
+ const resources = registry.getAllItems();
45
+ if (resources.length === 0) {
46
+ return NONE_RESOURCE;
47
+ }
48
+ return resources;
49
+ }
50
+
41
51
  export function resourceExtension(opts: {
42
52
  language: Language;
43
53
  store: JotaiStore;
44
54
  onAddFiles?: (files: File[]) => void;
45
55
  }): Extension[] {
46
56
  const { language, store, onAddFiles } = opts;
57
+ const getResources = () => getRegistryResources(store);
47
58
 
48
59
  return [
49
60
  language.data.of({
50
61
  // Resource completion for static resources (variables, tables, etc.)
51
62
  autocomplete: resourceCompletion(
52
- async (): Promise<Resource[]> => {
53
- const registry = getAIContextRegistry(store);
54
- const resources = registry.getAllItems();
55
- if (resources.length === 0) {
56
- return NONE_RESOURCE;
57
- }
58
- return resources;
59
- },
63
+ async (): Promise<Resource[]> => getResources(),
60
64
  (resource) => {
61
65
  if (resource.type === NONE_RESOURCE_TYPE) {
62
66
  return NONE_RESOURCE_FORMAT_COMPLETION;
@@ -92,9 +96,10 @@ export function resourceExtension(opts: {
92
96
  : []),
93
97
  resourceDecorations,
94
98
  resourceInputFilter,
99
+ // Resolve @-mention chips for programmatic prefills.
100
+ resourceSync(getResources, { logger: Logger }),
95
101
  resourcesField.init(() => {
96
- const registry = getAIContextRegistry(store);
97
- const resources = registry.getAllItems();
102
+ const resources = getRegistryResources(store);
98
103
  return new Map(resources.map((resource) => [resource.uri, resource]));
99
104
  }),
100
105
  resourceTheme,
@@ -106,11 +106,8 @@ function cellKeymaps({
106
106
  keybindings.push(
107
107
  {
108
108
  key: hotkeys.getHotkey("cell.goToDefinition").key,
109
- preventDefault: true,
110
- stopPropagation: true,
111
109
  run: (ev) => {
112
- goToDefinitionAtCursorPosition(ev);
113
- return true;
110
+ return goToDefinitionAtCursorPosition(ev);
114
111
  },
115
112
  },
116
113
  {
@@ -0,0 +1,94 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { EditorState } from "@codemirror/state";
4
+ import { EditorView, type Tooltip } from "@codemirror/view";
5
+ import { describe, expect, it } from "vitest";
6
+ import {
7
+ asSignatureHint,
8
+ setSignatureHintEffect,
9
+ signatureHintField,
10
+ } from "../signature-hint";
11
+
12
+ function fakeTooltip(pos: number): Tooltip {
13
+ return {
14
+ pos,
15
+ above: true,
16
+ create: () => ({ dom: document.createElement("div") }),
17
+ };
18
+ }
19
+
20
+ function stateWithHint(doc: string, pos: number): EditorState {
21
+ const state = EditorState.create({
22
+ doc,
23
+ extensions: [signatureHintField],
24
+ });
25
+ return state.update({ effects: setSignatureHintEffect.of(fakeTooltip(pos)) })
26
+ .state;
27
+ }
28
+
29
+ describe("signatureHintField", () => {
30
+ it("starts empty", () => {
31
+ const state = EditorState.create({ extensions: [signatureHintField] });
32
+ expect(state.field(signatureHintField)).toBeNull();
33
+ });
34
+
35
+ it("shows a tooltip when the effect is dispatched", () => {
36
+ const state = stateWithHint("plt.plot(", 9);
37
+ expect(state.field(signatureHintField)?.pos).toBe(9);
38
+ });
39
+
40
+ it("clears the tooltip when the effect dispatches null", () => {
41
+ let state = stateWithHint("plt.plot(", 9);
42
+ state = state.update({
43
+ effects: setSignatureHintEffect.of(null),
44
+ }).state;
45
+ expect(state.field(signatureHintField)).toBeNull();
46
+ });
47
+
48
+ it("dismisses the tooltip on a selection-only change", () => {
49
+ let state = stateWithHint("plt.plot(x)", 9);
50
+ state = state.update({ selection: { anchor: 0 } }).state;
51
+ expect(state.field(signatureHintField)).toBeNull();
52
+ });
53
+
54
+ it("keeps and re-anchors the tooltip across edits", () => {
55
+ let state = stateWithHint("plt.plot(", 9);
56
+ // Insert before the tooltip position; it should shift to stay anchored.
57
+ state = state.update({ changes: { from: 0, insert: "xy" } }).state;
58
+ expect(state.field(signatureHintField)?.pos).toBe(11);
59
+ });
60
+ });
61
+
62
+ describe("asSignatureHint", () => {
63
+ it("nests the content so descendant styling applies", () => {
64
+ const content = document.createElement("span");
65
+ content.classList.add("mo-cm-tooltip", "docs-documentation");
66
+ const base: Tooltip = {
67
+ pos: 0,
68
+ create: () => ({ dom: content, resize: false }),
69
+ };
70
+
71
+ const view = new EditorView({ state: EditorState.create({}) });
72
+ const { dom } = asSignatureHint(base).create(view);
73
+
74
+ // Outer wrapper carries the tooltip sizing class...
75
+ expect(dom.classList.contains("mo-cm-tooltip")).toBe(true);
76
+ // ...and the documentation content is a descendant (not the same node),
77
+ // so `.cm-tooltip .docs-documentation` padding/font rules match.
78
+ expect(dom).not.toBe(content);
79
+ expect(dom.querySelector(".docs-documentation")).toBe(content);
80
+
81
+ view.destroy();
82
+ });
83
+
84
+ it("preserves other tooltip fields", () => {
85
+ const base: Tooltip = {
86
+ pos: 5,
87
+ above: true,
88
+ create: () => ({ dom: document.createElement("span"), resize: false }),
89
+ };
90
+ const wrapped = asSignatureHint(base);
91
+ expect(wrapped.pos).toBe(5);
92
+ expect(wrapped.above).toBe(true);
93
+ });
94
+ });
@@ -9,6 +9,7 @@ import { documentationAtom } from "@/core/documentation/state";
9
9
  import { store } from "@/core/state/jotai";
10
10
  import { Logger } from "../../../utils/Logger";
11
11
  import { AUTOCOMPLETER, Autocompleter } from "./Autocompleter";
12
+ import { asSignatureHint, setSignatureHintEffect } from "./signature-hint";
12
13
 
13
14
  /**
14
15
  * Completion source for Python, using Jedi.
@@ -36,10 +37,12 @@ export const pythonCompletionSource: CompletionSource = async (
36
37
  cellId: cellId,
37
38
  });
38
39
  if (!result) {
40
+ context.view?.dispatch({ effects: setSignatureHintEffect.of(null) });
39
41
  return null;
40
42
  }
41
43
 
42
- // If it is a tooltip, show it as a Tooltip instead of a completion
44
+ // If it is a tooltip (e.g. a signature after `(` or `,`), show it as a
45
+ // Tooltip instead of a completion.
43
46
  const tooltip = Autocompleter.asHoverTooltip({
44
47
  position: context.pos,
45
48
  message: result,
@@ -50,6 +53,14 @@ export const pythonCompletionSource: CompletionSource = async (
50
53
  documentation: tooltip.html ?? null,
51
54
  });
52
55
  }
56
+ // Surface the signature as a floating hint near the cursor (the LSP path has
57
+ // its own signature help), and clear any stale hint when we instead have a
58
+ // real completion list.
59
+ context.view?.dispatch({
60
+ effects: setSignatureHintEffect.of(
61
+ tooltip ? asSignatureHint(tooltip) : null,
62
+ ),
63
+ });
53
64
  if (tooltip) {
54
65
  return null;
55
66
  }
@@ -0,0 +1,68 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+ import { StateEffect, StateField } from "@codemirror/state";
3
+ import { showTooltip, type Tooltip } from "@codemirror/view";
4
+
5
+ /**
6
+ * Effect to set (or clear, with `null`) the floating signature hint.
7
+ */
8
+ export const setSignatureHintEffect = StateEffect.define<Tooltip | null>();
9
+
10
+ /**
11
+ * Wrap a tooltip so it renders like the completion popup's info box.
12
+ *
13
+ * CodeMirror adds `cm-tooltip` directly to the DOM node returned by `create`,
14
+ * so the documentation content ends up on the same element as `cm-tooltip`.
15
+ * Our styling for padding/font (`.cm-tooltip .docs-documentation`) is a
16
+ * descendant selector, so we nest the content one level deeper to make it
17
+ * apply — mirroring how CodeMirror nests completion info inside its own
18
+ * wrapper. The outer `mo-cm-tooltip` class picks up the shared tooltip sizing.
19
+ */
20
+ export function asSignatureHint(tooltip: Tooltip): Tooltip {
21
+ return {
22
+ ...tooltip,
23
+ create: (view) => {
24
+ const { dom: content, ...rest } = tooltip.create(view);
25
+ const dom = document.createElement("div");
26
+ dom.classList.add("mo-cm-tooltip");
27
+ dom.append(content);
28
+ return { ...rest, dom };
29
+ },
30
+ };
31
+ }
32
+
33
+ /**
34
+ * Holds the floating "signature hint" shown after typing `(` or `,` inside a
35
+ * call on the non-LSP (Jedi) completion path.
36
+ *
37
+ * The LSP path has its own signature help; this fills the gap for users
38
+ * without a language server. The completion source (`pythonCompletionSource`)
39
+ * drives it: it dispatches `setSignatureHintEffect` with the tooltip when the
40
+ * backend returns a signature and with `null` otherwise. The hint is also
41
+ * cleared when the cursor moves via a selection-only change (e.g. clicking
42
+ * away or arrowing out of the call), and kept anchored across edits so it
43
+ * doesn't flicker while a fresh result is in flight.
44
+ */
45
+ export const signatureHintField = StateField.define<Tooltip | null>({
46
+ create: () => null,
47
+ update(tooltip, tr) {
48
+ for (const effect of tr.effects) {
49
+ if (effect.is(setSignatureHintEffect)) {
50
+ return effect.value;
51
+ }
52
+ }
53
+ if (!tooltip) {
54
+ return null;
55
+ }
56
+ // Cursor moved without editing (click / arrow key): dismiss the hint.
57
+ if (tr.selection && !tr.docChanged) {
58
+ return null;
59
+ }
60
+ // Keep the hint anchored across edits; the completion source refreshes or
61
+ // clears it as new results arrive.
62
+ if (tr.docChanged) {
63
+ return { ...tooltip, pos: tr.changes.mapPos(tooltip.pos) };
64
+ }
65
+ return tooltip;
66
+ },
67
+ provide: (field) => showTooltip.from(field),
68
+ });
@@ -31,6 +31,7 @@ import { Logger } from "@/utils/Logger";
31
31
  import { once } from "@/utils/once";
32
32
  import { cellActionsState } from "../../cells/state";
33
33
  import { pythonCompletionSource } from "../../completion/completer";
34
+ import { signatureHintField } from "../../completion/signature-hint";
34
35
  import type { PlaceholderType } from "../../config/types";
35
36
  import { FederatedLanguageServerClient } from "../../lsp/federated-lsp";
36
37
  import { createLspMarkdownRenderer } from "../../lsp/markdown-renderer";
@@ -376,10 +377,15 @@ export class PythonLanguageAdapter implements LanguageAdapter<{}> {
376
377
  ];
377
378
  }
378
379
 
379
- return autocompletion({
380
- ...autocompleteOptions,
381
- override: [pythonCompletionSource],
382
- });
380
+ return [
381
+ autocompletion({
382
+ ...autocompleteOptions,
383
+ override: [pythonCompletionSource],
384
+ }),
385
+ // The Jedi path has no built-in signature help; show a floating hint
386
+ // fed by `pythonCompletionSource` (the LSP path handles this itself).
387
+ signatureHintField,
388
+ ];
383
389
  };
384
390
 
385
391
  return [
@@ -2,6 +2,7 @@
2
2
  import type { EditorState, Transaction } from "@codemirror/state";
3
3
  import type { EditorView, ViewUpdate } from "@codemirror/view";
4
4
  import { getCM } from "@replit/codemirror-vim";
5
+ import type { ReactCodeMirrorRef } from "@uiw/react-codemirror";
5
6
 
6
7
  export function isAtStartOfEditor(ev: { state: EditorState }) {
7
8
  const main = ev.state.selection.main;
@@ -37,6 +38,20 @@ export function moveToEndOfEditor(ev: EditorView | undefined) {
37
38
  });
38
39
  }
39
40
 
41
+ /** We delay the focus and move to end of the editor until React has rendered the prefilled value. */
42
+ export function focusInputAndMoveToEnd(
43
+ ref: React.RefObject<ReactCodeMirrorRef | null>,
44
+ ) {
45
+ requestAnimationFrame(() => {
46
+ const view = ref.current?.view;
47
+ if (!view) {
48
+ return;
49
+ }
50
+ view.focus();
51
+ moveToEndOfEditor(view);
52
+ });
53
+ }
54
+
40
55
  export function isInVimMode(ev: EditorView): boolean {
41
56
  return getCM(ev)?.state.vim != null;
42
57
  }
@@ -13,6 +13,7 @@ import { AppHeader } from "@/components/editor/header/app-header";
13
13
  import { FilenameForm } from "@/components/editor/header/filename-form";
14
14
  import { MultiCellActionToolbar } from "@/components/editor/navigation/multi-cell-action-toolbar";
15
15
  import { ViewerBanner } from "@/components/editor/viewer-banner";
16
+ import { ProgressiveBoundary } from "@/components/lifecycle/ProgressiveBoundary";
16
17
  import { cn } from "@/utils/cn";
17
18
  import { Paths } from "@/utils/paths";
18
19
  import { AppContainer } from "../components/editor/app-container";
@@ -64,7 +65,6 @@ export const EditApp: React.FC<AppProps> = ({
64
65
  useCellActions();
65
66
  const viewState = useAtomValue(viewStateAtom);
66
67
  const numColumns = useAtomValue(numColumnsAtom);
67
- const hasCells = useAtomValue(hasCellsAtom);
68
68
  const filename = useFilename();
69
69
  const setLastSavedNotebook = useSetAtom(lastSavedNotebookAtom);
70
70
  const { sendComponentValues, sendInterrupt } = useRequestClient();
@@ -181,13 +181,16 @@ export const EditApp: React.FC<AppProps> = ({
181
181
 
182
182
  <ViewerBanner />
183
183
 
184
- {/* Don't render until we have a single cell */}
185
- {hasCells && (
184
+ {/* Don't render until we have a single cell. NotStartedConnectionAlert
185
+ still covers the "no remote runtime started" prompt. */}
186
+ <ProgressiveBoundary
187
+ requires={hasCellsAtom}
188
+ fallback={<NotStartedConnectionAlert />}
189
+ >
186
190
  <CellsRenderer appConfig={appConfig} mode={viewState.mode}>
187
191
  {editableCellsArray}
188
192
  </CellsRenderer>
189
- )}
190
- {!hasCells && <NotStartedConnectionAlert />}
193
+ </ProgressiveBoundary>
191
194
  </AppContainer>
192
195
  <MultiCellActionToolbar />
193
196
  {!hideControls && (
@@ -6,6 +6,7 @@ import type { AiCompletionCell } from "../ai/state";
6
6
  import type { CellId } from "../cells/ids";
7
7
  import type { MarimoError } from "../kernel/messages";
8
8
  import { wrapInFunction } from "./utils";
9
+ import { store } from "../state/jotai";
9
10
 
10
11
  interface AIFix {
11
12
  setAiCompletionCell: (opts: AiCompletionCell) => void;
@@ -84,7 +85,7 @@ export function getAutoFixes(
84
85
  description: "Fix the SQL statement",
85
86
  fixType: "ai",
86
87
  onFix: async (ctx) => {
87
- const datasourceContext = getDatasourceContext(ctx.cellId);
88
+ const datasourceContext = getDatasourceContext(ctx.cellId, store);
88
89
  let initialPrompt = `Fix the SQL statement: ${error.msg}.`;
89
90
  if (datasourceContext) {
90
91
  initialPrompt += `\nDatabase schema: ${datasourceContext}`;
@@ -0,0 +1,247 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
4
+ import { visibleForTesting } from "../render-policy";
5
+
6
+ const { computeRenderPolicy } = visibleForTesting;
7
+
8
+ const originalHref = window.location.href;
9
+ function setSearch(search: string) {
10
+ window.history.replaceState(null, "", `/${search}`);
11
+ }
12
+
13
+ describe("computeRenderPolicy", () => {
14
+ it("shows code in edit mode", () => {
15
+ const policy = computeRenderPolicy({
16
+ mode: "edit",
17
+ showAppCode: false, // ignored in edit mode
18
+ hasCells: true,
19
+ hasCachedOutputs: false,
20
+ allCellsIdle: false,
21
+ });
22
+ expect(policy.showCode).toBe(true);
23
+ });
24
+
25
+ it("hides code in present mode regardless of config", () => {
26
+ const policy = computeRenderPolicy({
27
+ mode: "present",
28
+ showAppCode: true,
29
+ hasCells: true,
30
+ hasCachedOutputs: true,
31
+ allCellsIdle: false,
32
+ });
33
+ expect(policy.showCode).toBe(false);
34
+ });
35
+
36
+ it("respects showAppCode in read mode", () => {
37
+ expect(
38
+ computeRenderPolicy({
39
+ mode: "read",
40
+ showAppCode: true,
41
+ hasCells: true,
42
+ hasCachedOutputs: false,
43
+ allCellsIdle: false,
44
+ }).showCode,
45
+ ).toBe(true);
46
+
47
+ expect(
48
+ computeRenderPolicy({
49
+ mode: "read",
50
+ showAppCode: false,
51
+ hasCells: true,
52
+ hasCachedOutputs: false,
53
+ allCellsIdle: false,
54
+ }).showCode,
55
+ ).toBe(false);
56
+ });
57
+
58
+ it("reports showCachedOutputs when cells and cached outputs are present", () => {
59
+ expect(
60
+ computeRenderPolicy({
61
+ mode: "read",
62
+ showAppCode: false,
63
+ hasCells: true,
64
+ hasCachedOutputs: true,
65
+ allCellsIdle: false,
66
+ }).showCachedOutputs,
67
+ ).toBe(true);
68
+ });
69
+
70
+ it("does not report showCachedOutputs when there are no cells", () => {
71
+ expect(
72
+ computeRenderPolicy({
73
+ mode: "read",
74
+ showAppCode: false,
75
+ hasCells: false,
76
+ hasCachedOutputs: true,
77
+ allCellsIdle: false,
78
+ }).showCachedOutputs,
79
+ ).toBe(false);
80
+ });
81
+
82
+ it("only reports showCachedOutputs for real outputs, not an idle notebook", () => {
83
+ // Regression guard: `showCachedOutputs` must stay honest even when the
84
+ // notebook is settled with no outputs (that only affects `canPaint`).
85
+ expect(
86
+ computeRenderPolicy({
87
+ mode: "read",
88
+ showAppCode: false,
89
+ hasCells: true,
90
+ hasCachedOutputs: false,
91
+ allCellsIdle: true,
92
+ }).showCachedOutputs,
93
+ ).toBe(false);
94
+ });
95
+ });
96
+
97
+ describe("computeRenderPolicy — read-mode code visibility", () => {
98
+ beforeEach(() => {
99
+ setSearch("");
100
+ });
101
+
102
+ afterEach(() => {
103
+ window.history.replaceState(null, "", originalHref);
104
+ });
105
+
106
+ it("hides code when the server stripped sources (?include-code=false)", () => {
107
+ setSearch("?include-code=false");
108
+ const policy = computeRenderPolicy({
109
+ mode: "read",
110
+ showAppCode: true, // config would show code, but sources are stripped
111
+ hasCells: true,
112
+ hasCachedOutputs: false,
113
+ allCellsIdle: false,
114
+ });
115
+ expect(policy.showCode).toBe(false);
116
+ // With no code, no outputs, and still running, there is nothing to paint.
117
+ expect(policy.canPaint).toBe(false);
118
+ });
119
+
120
+ it("include-code=false still paints when cached outputs exist", () => {
121
+ setSearch("?include-code=false");
122
+ expect(
123
+ computeRenderPolicy({
124
+ mode: "read",
125
+ showAppCode: true,
126
+ hasCells: true,
127
+ hasCachedOutputs: true,
128
+ allCellsIdle: false,
129
+ }).canPaint,
130
+ ).toBe(true);
131
+ });
132
+ });
133
+
134
+ describe("computeRenderPolicy.canPaint", () => {
135
+ it("is false when no cells exist, even if all (zero) cells are vacuously idle", () => {
136
+ expect(
137
+ computeRenderPolicy({
138
+ mode: "read",
139
+ showAppCode: true,
140
+ hasCells: false,
141
+ hasCachedOutputs: false,
142
+ allCellsIdle: true,
143
+ }).canPaint,
144
+ ).toBe(false);
145
+ });
146
+
147
+ it("is true in edit mode whenever cells exist", () => {
148
+ expect(
149
+ computeRenderPolicy({
150
+ mode: "edit",
151
+ showAppCode: false,
152
+ hasCells: true,
153
+ hasCachedOutputs: false,
154
+ allCellsIdle: false,
155
+ }).canPaint,
156
+ ).toBe(true);
157
+ });
158
+
159
+ it("is true in read mode when code is visible", () => {
160
+ expect(
161
+ computeRenderPolicy({
162
+ mode: "read",
163
+ showAppCode: true,
164
+ hasCells: true,
165
+ hasCachedOutputs: false,
166
+ allCellsIdle: false,
167
+ }).canPaint,
168
+ ).toBe(true);
169
+ });
170
+
171
+ it("is false in headless read mode while the notebook is still running with no outputs", () => {
172
+ expect(
173
+ computeRenderPolicy({
174
+ mode: "read",
175
+ showAppCode: false,
176
+ hasCells: true,
177
+ hasCachedOutputs: false,
178
+ allCellsIdle: false,
179
+ }).canPaint,
180
+ ).toBe(false);
181
+ });
182
+
183
+ it("is true in headless read mode with cached outputs", () => {
184
+ expect(
185
+ computeRenderPolicy({
186
+ mode: "read",
187
+ showAppCode: false,
188
+ hasCells: true,
189
+ hasCachedOutputs: true,
190
+ allCellsIdle: false,
191
+ }).canPaint,
192
+ ).toBe(true);
193
+ });
194
+
195
+ it("is true in headless read mode for a settled notebook with no outputs", () => {
196
+ // A notebook that ran to completion producing no outputs must still paint
197
+ // (empty) rather than sit on a spinner — parity with the pre-framework
198
+ // `hasAnyOutputAtom` idle fallback.
199
+ expect(
200
+ computeRenderPolicy({
201
+ mode: "read",
202
+ showAppCode: false,
203
+ hasCells: true,
204
+ hasCachedOutputs: false,
205
+ allCellsIdle: true,
206
+ }).canPaint,
207
+ ).toBe(true);
208
+ });
209
+
210
+ // In present mode `showCode` is always false, so `canPaint` rides entirely
211
+ // on cached outputs / a settled notebook.
212
+ it("is true in present mode with cached outputs", () => {
213
+ expect(
214
+ computeRenderPolicy({
215
+ mode: "present",
216
+ showAppCode: true,
217
+ hasCells: true,
218
+ hasCachedOutputs: true,
219
+ allCellsIdle: false,
220
+ }).canPaint,
221
+ ).toBe(true);
222
+ });
223
+
224
+ it("is false in present mode while still running with no outputs", () => {
225
+ expect(
226
+ computeRenderPolicy({
227
+ mode: "present",
228
+ showAppCode: true,
229
+ hasCells: true,
230
+ hasCachedOutputs: false,
231
+ allCellsIdle: false,
232
+ }).canPaint,
233
+ ).toBe(false);
234
+ });
235
+
236
+ it("is true in present mode for a settled notebook with no outputs", () => {
237
+ expect(
238
+ computeRenderPolicy({
239
+ mode: "present",
240
+ showAppCode: true,
241
+ hasCells: true,
242
+ hasCachedOutputs: false,
243
+ allCellsIdle: true,
244
+ }).canPaint,
245
+ ).toBe(true);
246
+ });
247
+ });