@marimo-team/islands 0.26.1-dev21 → 0.26.1-dev27

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 (106) hide show
  1. package/dist/{ConnectedDataExplorerComponent-CR9WyiEc.js → ConnectedDataExplorerComponent-jtTaDisw.js} +16 -16
  2. package/dist/{ErrorBoundary-C5X_T831.js → ErrorBoundary-zpe6C93k.js} +6 -6
  3. package/dist/{abnfDiagram-VCTEODGH-DGAbsdXT.js → abnfDiagram-VCTEODGH-cUj3Gnnh.js} +2 -2
  4. package/dist/{any-language-editor-DzGF1ll-.js → any-language-editor-BHgkY7jY.js} +2 -2
  5. package/dist/{architectureDiagram-5GKGNRK7-D4DnIo7R.js → architectureDiagram-5GKGNRK7-CIAZgn9d.js} +1 -1
  6. package/dist/{assertNever-CqwxSD_2.js → assertNever-BHnIohkX.js} +13 -13
  7. package/dist/{chat-ui-qZdDDrzU.js → chat-ui-DOvIzlMA.js} +46 -46
  8. package/dist/{check-D9vf6LYF.js → check-LtjuWmNn.js} +1 -1
  9. package/dist/{chunk-IMKFNOWR-Bc_i6jWx.js → chunk-IMKFNOWR-CB9N3qYR.js} +1 -1
  10. package/dist/{chunk-SHT3W25Y-CGML5pnF.js → chunk-SHT3W25Y-D9njV7TI.js} +1 -1
  11. package/dist/{chunk-SVP7TREG-ZpeFKfFT.js → chunk-SVP7TREG-CUCE0BFm.js} +1 -1
  12. package/dist/{chunk-TICWLB2K-C6cLmcg8.js → chunk-TICWLB2K-iQB6ttkI.js} +1 -1
  13. package/dist/{classDiagram-ZZMXUADV--q40NTXr.js → classDiagram-ZZMXUADV-BI1VBNIo.js} +2 -2
  14. package/dist/{classDiagram-v2-VYDZK3BY-Dt_Pp94L.js → classDiagram-v2-VYDZK3BY-BYL3asWh.js} +2 -2
  15. package/dist/{code-visibility-7FxdzbDq.js → code-visibility-BtvMUvQ6.js} +19 -19
  16. package/dist/{common-D-iTRwaQ.js → common-B46KECgx.js} +156 -156
  17. package/dist/{config-B8JCQMby.js → config-DL9e-OWE.js} +3 -3
  18. package/dist/{copy-icon-BLig0ZKb.js → copy-icon-rYV2znAe.js} +2 -2
  19. package/dist/{createReducer-BIUQ3TbG.js → createReducer-BdiSrxHu.js} +5 -5
  20. package/dist/{cynefinDiagram-5FMLGOSQ-2FtF_-cc.js → cynefinDiagram-5FMLGOSQ-DpGtYvnZ.js} +1 -1
  21. package/dist/{dagre-GXQ25YYZ-Cymu2SPS.js → dagre-GXQ25YYZ-B5GDC2kN.js} +1 -1
  22. package/dist/{data-grid-overlay-editor-DoWUW2oW.js → data-grid-overlay-editor-CLCJ44fs.js} +1 -1
  23. package/dist/{diagram-S7CK7UJ4-OwDa8kAa.js → diagram-S7CK7UJ4-B2T25t1t.js} +1 -1
  24. package/dist/{diagram-UQ7AKVKN-CzRDwZwd.js → diagram-UQ7AKVKN-Dy3B5L_z.js} +1 -1
  25. package/dist/{diagram-VX7I27RA-XRIcgMDs.js → diagram-VX7I27RA-tOptWvNh.js} +1 -1
  26. package/dist/{diagram-Z3DM3KII-DdRDYAs6.js → diagram-Z3DM3KII-DsgZAokO.js} +1 -1
  27. package/dist/{dialog-DGh2HNAO.js → dialog-vs6x3On9.js} +19 -19
  28. package/dist/{dropdown-menu-ChH3oiqI.js → dropdown-menu-DYN2RV5d.js} +193 -193
  29. package/dist/{ebnfDiagram-PWID7BFC-CZMNMGNP.js → ebnfDiagram-PWID7BFC-CGWECzS1.js} +2 -2
  30. package/dist/{erDiagram-RLTQ6QDP-ByxHAN4b.js → erDiagram-RLTQ6QDP-CZLi87y3.js} +1 -1
  31. package/dist/{error-banner-BvRaQnGH.js → error-banner-D-AC7pQx.js} +70 -70
  32. package/dist/{error-entries-DhI0hGvj.js → error-entries-CncQR572.js} +443 -436
  33. package/dist/{feedback-button-OUiV15AL.js → feedback-button-CnyHlwaY.js} +120 -120
  34. package/dist/{flowDiagram-HODETNUW-BQpzWx5O.js → flowDiagram-HODETNUW-CS86WYbX.js} +2 -2
  35. package/dist/{formats-BxP8k8Un.js → formats-BUFLQJXY.js} +1 -1
  36. package/dist/{glide-data-editor-CFouYM6e.js → glide-data-editor-C3znsea0.js} +11 -11
  37. package/dist/{glide-utils-bKdvDwwo.js → glide-utils-CZ-O-CB_.js} +2 -2
  38. package/dist/{globals-B_U6Frqj.js → globals-DHoGn4Qt.js} +3 -3
  39. package/dist/{html-to-image-B803aaWE.js → html-to-image-BU7H-AM1.js} +4323 -4318
  40. package/dist/{infoDiagram-27XIBGKW-C9EWHkak.js → infoDiagram-27XIBGKW-C9JBFfpC.js} +1 -1
  41. package/dist/{ishikawaDiagram-5VMMS53U-D67SGFvp.js → ishikawaDiagram-5VMMS53U-Eh3iuw2D.js} +1 -1
  42. package/dist/{kanban-definition-UXKFOSKX-CTMTiazR.js → kanban-definition-UXKFOSKX-DYtuVwYD.js} +1 -1
  43. package/dist/main.js +399 -398
  44. package/dist/{mermaid-DE_tvTGF.js → mermaid--k1o49nH.js} +34 -34
  45. package/dist/{mindmap-definition-YA3MSWOX-LzNgDy8O.js → mindmap-definition-YA3MSWOX-Dn1Cnqys.js} +1 -1
  46. package/dist/{number-overlay-editor-CiQQjf9m.js → number-overlay-editor-DwK5S3_f.js} +1 -1
  47. package/dist/{pegDiagram-XKGWAZYB-DFMS6feI.js → pegDiagram-XKGWAZYB-DiY7rITR.js} +2 -2
  48. package/dist/{pencil-CHkdsX07.js → pencil-AWgwbH4D.js} +1 -1
  49. package/dist/{pieDiagram-E7YTZNPT-C0MSBop-.js → pieDiagram-E7YTZNPT-BL6InbDs.js} +1 -1
  50. package/dist/{process-output-CnCLfvnL.js → process-output-xJm8T5-E.js} +4 -4
  51. package/dist/{railroadDiagram-O6MQD6OU-mbdav2pV.js → railroadDiagram-O6MQD6OU-DterenMu.js} +2 -2
  52. package/dist/{requirementDiagram-BXWQKSXE-C1HNBBO6.js → requirementDiagram-BXWQKSXE-Vb5_9LHC.js} +1 -1
  53. package/dist/{reveal-component-B73BObRc.js → reveal-component-Dsp5kSt3.js} +1008 -1008
  54. package/dist/{select-CvorIE3l.js → select-CKLRKIzB.js} +298 -298
  55. package/dist/{sequenceDiagram-WJ2MYXX4-D6gBHifq.js → sequenceDiagram-WJ2MYXX4-BWsq8hMt.js} +1 -1
  56. package/dist/{spec-ayzaXGVq.js → spec-C4uOz0Em.js} +4 -4
  57. package/dist/{stateDiagram-D77RDMKH-Bx-fTtRZ.js → stateDiagram-D77RDMKH-nfKKy6aQ.js} +2 -2
  58. package/dist/{stateDiagram-v2-MP3YSRHH-Cec8T2yO.js → stateDiagram-v2-MP3YSRHH-DMUHA_9A.js} +2 -2
  59. package/dist/{static-state-CqwW3B_X.js → static-state-DZ1nSa6e.js} +9 -9
  60. package/dist/{swimlanes-42K2YHIH-C2bAgnov.js → swimlanes-42K2YHIH-N4qHIMoc.js} +1 -1
  61. package/dist/{swimlanesDiagram-VR7AAH4N-CzeG-Mnb.js → swimlanesDiagram-VR7AAH4N-DQpDDjQb.js} +2 -2
  62. package/dist/{timeline-definition-24CTP7MA-DTJ0Rx8X.js → timeline-definition-24CTP7MA-Od8dY9F5.js} +1 -1
  63. package/dist/{toast-6V8Og7d5.js → toast-bhZHUEal.js} +187 -187
  64. package/dist/{tooltip-D0h-ZJ6j.js → tooltip-DSWC_Td_.js} +40 -40
  65. package/dist/{use-restore-focus-BFvwj2Hj.js → use-restore-focus-ocw7t85i.js} +1371 -1373
  66. package/dist/{useDateFormatter-D6o9PsWt.js → useDateFormatter-BiDS8uXQ.js} +2 -2
  67. package/dist/{useDeepCompareMemoize-D-Pbv7dN.js → useDeepCompareMemoize-BsaXfZ8C.js} +1 -1
  68. package/dist/{useLifecycle-CE0yGTMF.js → useLifecycle-CCV7yZ-v.js} +1 -1
  69. package/dist/{vega-component-DTf7GHQe.js → vega-component-DpTyTrz3.js} +6 -6
  70. package/dist/{vennDiagram-4TSXK5OY-lIM3SAjl.js → vennDiagram-4TSXK5OY-Di3T2YMb.js} +1 -1
  71. package/dist/{wardleyDiagram-VM6X3IG4-Bw_t7uvA.js → wardleyDiagram-VM6X3IG4-CKOF5DTi.js} +1 -1
  72. package/dist/{xychartDiagram-S5SC5T6Z-BXwkLYKj.js → xychartDiagram-S5SC5T6Z-GYLPWSeb.js} +1 -1
  73. package/package.json +1 -1
  74. package/src/__mocks__/executions.ts +25 -3
  75. package/src/__tests__/notebook-analysis.ts +48 -0
  76. package/src/components/editor/ai/__tests__/completion-utils.test.ts +28 -61
  77. package/src/components/editor/navigation/__tests__/navigation.test.ts +0 -4
  78. package/src/core/cells/__tests__/add-missing-import.test.ts +14 -9
  79. package/src/core/cells/__tests__/pending-delete-service.test.tsx +4 -11
  80. package/src/core/cells/add-missing-import.ts +2 -3
  81. package/src/core/codemirror/code-lens/__tests__/entities.test.ts +7 -11
  82. package/src/core/codemirror/code-lens/__tests__/extension.test.ts +8 -13
  83. package/src/core/codemirror/code-lens/__tests__/perf.test.ts +7 -9
  84. package/src/core/codemirror/copilot/__tests__/getCodes.test.ts +9 -13
  85. package/src/core/codemirror/go-to-definition/__tests__/utils.test.ts +16 -35
  86. package/src/core/codemirror/language/embedded/__tests__/embedded-python.test.ts +2 -18
  87. package/src/core/codemirror/reactive-references/__tests__/extension.test.ts +8 -14
  88. package/src/core/datasets/__tests__/data-source.test.ts +15 -17
  89. package/src/core/datasets/data-source-connections.ts +8 -11
  90. package/src/core/datasets/state.ts +7 -12
  91. package/src/core/executions/__tests__/freshness.test.ts +8 -3
  92. package/src/core/executions/__tests__/interrupt.test.ts +1 -0
  93. package/src/core/executions/__tests__/select.test.ts +1 -1
  94. package/src/core/executions/atoms.ts +1 -0
  95. package/src/core/executions/freshness.ts +2 -2
  96. package/src/core/islands/bootstrap.ts +0 -2
  97. package/src/core/notebook/replica/__tests__/executions.test.ts +4 -2
  98. package/src/core/notebook/replica/replica.ts +11 -2
  99. package/src/core/notebook/replica/resources/executions.ts +29 -20
  100. package/src/core/session/__tests__/useNotebookSession.hook.test.tsx +192 -1
  101. package/src/core/session/useNotebookSession.tsx +37 -37
  102. package/src/core/storage/__tests__/state.test.ts +6 -9
  103. package/src/core/storage/state.ts +5 -8
  104. package/src/core/variables/state.ts +73 -68
  105. package/src/core/variables/types.ts +2 -2
  106. package/src/core/variables/__tests__/state.test.ts +0 -148
@@ -1,7 +1,7 @@
1
1
  import { a as e } from "./rolldown-runtime-BPCzCO3I.js";
2
2
  import { t } from "./react-Bgs_wQh3.js";
3
- import { h as n } from "./tooltip-D0h-ZJ6j.js";
4
- import { C as r } from "./select-CvorIE3l.js";
3
+ import { h as n } from "./tooltip-DSWC_Td_.js";
4
+ import { C as r } from "./select-CKLRKIzB.js";
5
5
  var i = n("chart-pie", [["path", {
6
6
  d: "M21 12c.552 0 1.005-.449.95-.998a10 10 0 0 0-8.953-8.951c-.55-.055-.998.398-.998.95v8a1 1 0 0 0 1 1z",
7
7
  key: "pzmjnu"
@@ -1,6 +1,6 @@
1
1
  import { a as e } from "./rolldown-runtime-BPCzCO3I.js";
2
2
  import { t } from "./react-Bgs_wQh3.js";
3
- import { It as n } from "./use-restore-focus-BFvwj2Hj.js";
3
+ import { Lt as n } from "./use-restore-focus-ocw7t85i.js";
4
4
  //#region src/utils/semaphore.ts
5
5
  var r = class {
6
6
  maxPermits;
@@ -2,7 +2,7 @@ import { a as e } from "./rolldown-runtime-BPCzCO3I.js";
2
2
  import { h as t, i as n } from "./button-Z2R2272J.js";
3
3
  import { t as r } from "./react-Bgs_wQh3.js";
4
4
  import { t as i } from "./compiler-runtime-C5KHtL5D.js";
5
- import { h as a } from "./tooltip-D0h-ZJ6j.js";
5
+ import { h as a } from "./tooltip-DSWC_Td_.js";
6
6
  import { t as o } from "./jsx-runtime-D8btoEHk.js";
7
7
  var s = a("calendar", [
8
8
  ["path", {
@@ -2,18 +2,18 @@ import { a as e } from "./rolldown-runtime-BPCzCO3I.js";
2
2
  import { g as t, h as n, m as r, s as i } from "./button-Z2R2272J.js";
3
3
  import { t as a } from "./react-Bgs_wQh3.js";
4
4
  import { t as o } from "./compiler-runtime-C5KHtL5D.js";
5
- import { t as s } from "./tooltip-D0h-ZJ6j.js";
6
- import { l as c, t as l } from "./config-B8JCQMby.js";
5
+ import { t as s } from "./tooltip-DSWC_Td_.js";
6
+ import { l as c, t as l } from "./config-DL9e-OWE.js";
7
7
  import { t as u } from "./jsx-runtime-D8btoEHk.js";
8
- import { d } from "./use-restore-focus-BFvwj2Hj.js";
9
- import { n as f } from "./error-banner-BvRaQnGH.js";
8
+ import { d } from "./use-restore-focus-ocw7t85i.js";
9
+ import { n as f } from "./error-banner-D-AC7pQx.js";
10
10
  import { t as p } from "./debounce-DrhhziJv.js";
11
11
  import { t as ee } from "./objects-DCmMvZtn.js";
12
12
  import { t as te } from "./useEvent-BoN7U38T.js";
13
- import { a as ne, i as re, n as ie, t as m } from "./formats-BxP8k8Un.js";
13
+ import { a as ne, i as re, n as ie, t as m } from "./formats-BUFLQJXY.js";
14
14
  import { a as h, t as g } from "./arrays-DoQ-AILx.js";
15
15
  import { t as ae } from "./useAsyncData-P5-Oovhq.js";
16
- import { n as _, t as oe } from "./useDeepCompareMemoize-D-Pbv7dN.js";
16
+ import { n as _, t as oe } from "./useDeepCompareMemoize-BsaXfZ8C.js";
17
17
  import { W as se, n as ce } from "./vega-loader.browser-Co9gYE8Z.js";
18
18
  import { t as le } from "./react-vega-CGgQEf0O.js";
19
19
  import { a as ue, n as de } from "./loader-qPmiRXZd.js";
@@ -3,7 +3,7 @@ import { t } from "./src-D5uZaZib.js";
3
3
  import { n } from "./chunk-Y2CYZVJY-DKKS1VyV.js";
4
4
  import { $ as r, H as i, K as a, U as o, a as s, b as c, c as l, et as u, f as d, nt as f, tt as p, v as m, w as h, y as g } from "./chunk-DU6HZSFF-4SDIhUTY.js";
5
5
  import { t as _ } from "./rough.esm-CtV9AnV1.js";
6
- import { p as v } from "./mermaid-DE_tvTGF.js";
6
+ import { p as v } from "./mermaid--k1o49nH.js";
7
7
  //#region ../node_modules/.pnpm/khroma@2.1.0/node_modules/khroma/dist/methods/transparentize.js
8
8
  var y = (e, t) => p(e, "a", -t), b = 1e-10;
9
9
  function x(e, t) {
@@ -2,7 +2,7 @@ import { i as e } from "./chunk-75Z2AOVW-76L6My3P.js";
2
2
  import { n as t } from "./src-D5uZaZib.js";
3
3
  import { n } from "./chunk-Y2CYZVJY-DKKS1VyV.js";
4
4
  import { D as r, H as i, K as a, U as o, a as s, b as c, c as l, v as u, w as d, x as f, y as p } from "./chunk-DU6HZSFF-4SDIhUTY.js";
5
- import { p as m } from "./mermaid-DE_tvTGF.js";
5
+ import { p as m } from "./mermaid--k1o49nH.js";
6
6
  import { n as h } from "./mermaid-parser.core-DtOnl7m4.js";
7
7
  import { t as g } from "./chunk-JWPE2WC7-DJvv1t8U.js";
8
8
  //#region ../node_modules/.pnpm/mermaid@11.17.2/node_modules/mermaid/dist/chunks/mermaid.core/wardleyDiagram-VM6X3IG4.mjs
@@ -9,7 +9,7 @@ import { n as s } from "./chunk-Y2CYZVJY-DKKS1VyV.js";
9
9
  import { D as c, H as l, K as u, U as d, a as f, b as p, c as m, f as h, v as g, w as _, y as v, z as y } from "./chunk-DU6HZSFF-4SDIhUTY.js";
10
10
  import "./chunk-PWAF6VOD-CRu_RGP2.js";
11
11
  import { t as b } from "./chunk-GMAD6QVW-BJGF8QZL.js";
12
- import { p as x } from "./mermaid-DE_tvTGF.js";
12
+ import { p as x } from "./mermaid--k1o49nH.js";
13
13
  //#region ../node_modules/.pnpm/d3-scale@4.0.2/node_modules/d3-scale/src/band.js
14
14
  function S() {
15
15
  var e = t().unknown(void 0), r = e.domain, i = e.range, o = 0, s = 1, c, l, u = !1, d = 0, f = 0, p = .5;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marimo-team/islands",
3
- "version": "0.26.1-dev21",
3
+ "version": "0.26.1-dev27",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -38,7 +38,10 @@ const READY: Protocol.RuntimeState = { status: "ready" };
38
38
  const SUCCEEDED: Protocol.ExecutionOutcomeOutput = { kind: "succeeded" };
39
39
 
40
40
  /** An execution, or the output it set, as the stream delivers them. */
41
- type ExecutionFixture = Protocol.ExecutionOutput & { items?: readonly Item[] };
41
+ type ExecutionFixture = Protocol.ExecutionOutput & {
42
+ items?: readonly Item[];
43
+ bindings?: readonly Pick<Protocol.Variable, "name" | "type" | "preview">[];
44
+ };
42
45
  type Entry = ExecutionFixture | Protocol.Output;
43
46
  export type ExecutionEntries = ReadonlyArray<Entry | readonly Entry[]>;
44
47
 
@@ -96,7 +99,11 @@ function mirror(entries: ExecutionEntries): Executions {
96
99
  const { records, outputs } = split(entries);
97
100
  const executions = new Map<Protocol.ExecutionId, Execution>();
98
101
  const latest = new Map<Protocol.CellId, Protocol.ExecutionId>();
99
- for (const { items = [], ...record } of records) {
102
+ const variables = new Map<
103
+ Protocol.CellId,
104
+ Map<Protocol.ItemId, Protocol.Variable>
105
+ >();
106
+ for (const { items = [], bindings = [], ...record } of records) {
100
107
  if (record.cell_id !== null) {
101
108
  // The host retains one execution per cell on the stream.
102
109
  const previous = latest.get(record.cell_id);
@@ -104,13 +111,27 @@ function mirror(entries: ExecutionEntries): Executions {
104
111
  executions.delete(previous);
105
112
  }
106
113
  latest.set(record.cell_id, record.id);
114
+ const bound = new Map<Protocol.ItemId, Protocol.Variable>();
115
+ for (const binding of bindings) {
116
+ const id = `${record.id}:${binding.name}`;
117
+ bound.set(id, {
118
+ ...binding,
119
+ id,
120
+ execution_id: record.id,
121
+ revision: { execution_id: record.id, update: 0 },
122
+ });
123
+ }
124
+ if (bound.size) {
125
+ variables.set(record.cell_id, bound);
126
+ } else {
127
+ variables.delete(record.cell_id);
128
+ }
107
129
  }
108
130
  executions.set(record.id, {
109
131
  record,
110
132
  output: outputs.get(record.id) ?? null,
111
133
  outputVersion: 0,
112
134
  items: new Map(items.map((item) => [item.id, item])),
113
- variables: new Map(),
114
135
  });
115
136
  }
116
137
  const scratch = [...executions.values()].findLast(
@@ -118,6 +139,7 @@ function mirror(entries: ExecutionEntries): Executions {
118
139
  execution.record.cell_id === null && shown(execution) !== null,
119
140
  );
120
141
  return {
142
+ variables,
121
143
  runs: new Map(),
122
144
  executions,
123
145
  latest,
@@ -0,0 +1,48 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import type { CellAnalysis } from "@marimo-team/client/protocol";
4
+ import { atom, type createStore } from "jotai";
5
+ import { cellId } from "@/__tests__/branded";
6
+ import { cell, document } from "@/core/notebook/document/__tests__/fixtures";
7
+ import { createNotebookReplica } from "@/core/notebook/replica";
8
+ import { activeNotebookReplicaAtom } from "@/core/session/active-notebook";
9
+
10
+ export type AnalysisCells = Record<
11
+ string,
12
+ Partial<Pick<CellAnalysis, "defs" | "refs">>
13
+ >;
14
+
15
+ export function setNotebookAnalysis(
16
+ store: ReturnType<typeof createStore>,
17
+ cells: AnalysisCells,
18
+ ) {
19
+ const replica =
20
+ store.get(activeNotebookReplicaAtom) ?? createNotebookReplica(store);
21
+ const ids = Object.keys(cells).map(cellId);
22
+ const base = document();
23
+ const analyzedDocument = {
24
+ revision: { ...base.revision, order: ids },
25
+ cells: new Map(ids.map((id) => [id, cell(id, "")])),
26
+ };
27
+ const analysis = {
28
+ notebook_id: analyzedDocument.revision.notebook_id,
29
+ document_etag: analyzedDocument.revision.etag,
30
+ cells: Object.fromEntries(
31
+ Object.entries(cells).map(([id, names]) => [
32
+ id,
33
+ { defs: [], refs: [], diagnostics: [], ...names },
34
+ ]),
35
+ ),
36
+ };
37
+ const documentAtom = atom(analyzedDocument);
38
+ store.set(activeNotebookReplicaAtom, {
39
+ ...replica,
40
+ analysisAtom: atom({
41
+ freshness: "current" as const,
42
+ analysis,
43
+ document: analyzedDocument,
44
+ }),
45
+ documentAtom,
46
+ shownDocumentAtom: documentAtom,
47
+ });
48
+ }
@@ -1,4 +1,6 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
+ import type { Variable } from "@marimo-team/client/protocol";
3
+ import type { FileUIPart, UIMessage } from "ai";
2
4
  import {
3
5
  afterEach,
4
6
  beforeEach,
@@ -8,16 +10,16 @@ import {
8
10
  type Mock,
9
11
  vi,
10
12
  } from "vitest";
11
- import { variableName } from "@/__tests__/branded";
13
+ import { MockExecutions } from "@/__mocks__/executions";
12
14
  import * as aiContext from "@/core/ai/context/context";
13
15
  import { getCodes } from "@/core/codemirror/copilot/getCodes";
14
16
  import { dataSourceConnectionsAtom } from "@/core/datasets/data-source-connections";
15
17
  import { DUCKDB_ENGINE } from "@/core/datasets/engines";
16
18
  import { datasetsAtom } from "@/core/datasets/state";
17
19
  import type { DatasetsState } from "@/core/datasets/types";
20
+ import { document as notebookDocument } from "@/core/notebook/document/__tests__/fixtures";
21
+ import { activeNotebookReplicaAtom } from "@/core/session/active-notebook";
18
22
  import { store } from "@/core/state/jotai";
19
- import { variablesAtom } from "@/core/variables/state";
20
- import type { FileUIPart, UIMessage } from "ai";
21
23
  import {
22
24
  getAICompletionBody,
23
25
  getAICompletionBodyWithAttachments,
@@ -31,6 +33,15 @@ vi.mock("@/core/codemirror/copilot/getCodes", () => ({
31
33
  getCodes: vi.fn(),
32
34
  }));
33
35
 
36
+ function setBindings(bindings: Pick<Variable, "name" | "type" | "preview">[]) {
37
+ MockExecutions.seed(
38
+ store,
39
+ [{ ...MockExecutions.completed("c1"), bindings }],
40
+ null,
41
+ notebookDocument(),
42
+ );
43
+ }
44
+
34
45
  describe("getAICompletionBody", () => {
35
46
  beforeEach(() => {
36
47
  // Reset the Jotai store before each test
@@ -41,7 +52,7 @@ describe("getAICompletionBody", () => {
41
52
  latestEngineSelected: DUCKDB_ENGINE,
42
53
  connectionsMap: new Map(),
43
54
  });
44
- store.set(variablesAtom, {});
55
+ store.set(activeNotebookReplicaAtom, null);
45
56
  (getCodes as Mock).mockReturnValue("// Some other code");
46
57
  });
47
58
 
@@ -221,23 +232,10 @@ describe("getAICompletionBody", () => {
221
232
 
222
233
  it("should return the correct completion body with mentioned variables", () => {
223
234
  // Set up test data in the Jotai store
224
- const testVariables = {
225
- [variableName("var1")]: {
226
- name: variableName("var1"),
227
- value: "string value",
228
- dataType: "string",
229
- declaredBy: [],
230
- usedBy: [],
231
- },
232
- [variableName("var2")]: {
233
- name: variableName("var2"),
234
- value: "42",
235
- dataType: "number",
236
- declaredBy: [],
237
- usedBy: [],
238
- },
239
- };
240
- store.set(variablesAtom, testVariables);
235
+ setBindings([
236
+ { name: "var1", type: "string", preview: "string value" },
237
+ { name: "var2", type: "number", preview: "42" },
238
+ ]);
241
239
 
242
240
  const input = "Use @variable://var1 and @variable://var2 for analysis";
243
241
  const result = getAICompletionBody({ input });
@@ -269,16 +267,7 @@ describe("getAICompletionBody", () => {
269
267
  ];
270
268
  store.set(datasetsAtom, { tables: testDatasets } as DatasetsState);
271
269
 
272
- const testVariables = {
273
- [variableName("var1")]: {
274
- name: variableName("var1"),
275
- value: "string value",
276
- dataType: "string",
277
- declaredBy: [],
278
- usedBy: [],
279
- },
280
- };
281
- store.set(variablesAtom, testVariables);
270
+ setBindings([{ name: "var1", type: "string", preview: "string value" }]);
282
271
 
283
272
  const input = "Use @data://dataset1 and @variable://var1 for analysis";
284
273
  const result = getAICompletionBody({ input });
@@ -301,16 +290,9 @@ describe("getAICompletionBody", () => {
301
290
 
302
291
  it("should handle non-existent variables", () => {
303
292
  // Set up test data in the Jotai store
304
- const testVariables = {
305
- [variableName("existingVar")]: {
306
- name: variableName("existingVar"),
307
- value: "string value",
308
- dataType: "string",
309
- declaredBy: [],
310
- usedBy: [],
311
- },
312
- };
313
- store.set(variablesAtom, testVariables);
293
+ setBindings([
294
+ { name: "existingVar", type: "string", preview: "string value" },
295
+ ]);
314
296
 
315
297
  const input =
316
298
  "Use @variable://existingVar and @variable://nonExistentVar for analysis";
@@ -338,16 +320,9 @@ describe("getAICompletionBody", () => {
338
320
  ];
339
321
  store.set(datasetsAtom, { tables: testDatasets } as DatasetsState);
340
322
 
341
- const testVariables = {
342
- [variableName("conflict")]: {
343
- name: variableName("conflict"),
344
- value: "string value",
345
- dataType: "string",
346
- declaredBy: [],
347
- usedBy: [],
348
- },
349
- };
350
- store.set(variablesAtom, testVariables);
323
+ setBindings([
324
+ { name: "conflict", type: "string", preview: "string value" },
325
+ ]);
351
326
 
352
327
  const input = "Use @data://conflict for analysis";
353
328
  const result = getAICompletionBody({ input });
@@ -375,7 +350,7 @@ describe("resolveChatContext", () => {
375
350
  latestEngineSelected: DUCKDB_ENGINE,
376
351
  connectionsMap: new Map(),
377
352
  });
378
- store.set(variablesAtom, {});
353
+ store.set(activeNotebookReplicaAtom, null);
379
354
  });
380
355
 
381
356
  it("returns no context when the input has no @-mentions", async () => {
@@ -390,15 +365,7 @@ describe("resolveChatContext", () => {
390
365
  });
391
366
 
392
367
  it("captures resolved @-context into a data part", async () => {
393
- store.set(variablesAtom, {
394
- [variableName("var1")]: {
395
- name: variableName("var1"),
396
- value: "string value",
397
- dataType: "string",
398
- declaredBy: [],
399
- usedBy: [],
400
- },
401
- });
368
+ setBindings([{ name: "var1", type: "string", preview: "string value" }]);
402
369
 
403
370
  const result = await resolveChatContext("inspect @variable://var1");
404
371
 
@@ -44,8 +44,6 @@ import {
44
44
  } from "@/core/config/config";
45
45
  import { requestClientAtom } from "@/core/network/requests";
46
46
  import { store } from "@/core/state/jotai";
47
- import { variablesAtom } from "@/core/variables/state";
48
- import type { Variables } from "@/core/variables/types";
49
47
  import type { CellActionsDropdownHandle } from "../../cell/cell-actions";
50
48
  import {
51
49
  useCellEditorNavigationProps,
@@ -464,8 +462,6 @@ describe("useCellNavigationProps", () => {
464
462
  });
465
463
 
466
464
  it("should add an import before and a SQL cell after when 'q' is pressed", () => {
467
- store.set(variablesAtom, {} as Variables);
468
-
469
465
  const { result } = renderWithProvider(() =>
470
466
  useCellNavigationProps(mockCellId, options),
471
467
  );
@@ -2,12 +2,12 @@
2
2
 
3
3
  import { createStore } from "jotai";
4
4
  import { beforeEach, describe, expect, it, vi } from "vitest";
5
+ import { setNotebookAnalysis } from "@/__tests__/notebook-analysis";
6
+ import { MockExecutions } from "@/__mocks__/executions";
5
7
  import { MockNotebook } from "@/__mocks__/notebook";
6
8
  import { MockRequestClient } from "@/__mocks__/requests";
7
9
  import { cellId } from "@/__tests__/branded";
8
10
  import { store } from "@/core/state/jotai";
9
- import { variablesAtom } from "@/core/variables/state";
10
- import type { Variables } from "@/core/variables/types";
11
11
  import {
12
12
  maybeAddAltairImport,
13
13
  maybeAddMarimoImport,
@@ -26,13 +26,12 @@ const Cell2 = cellId("2");
26
26
 
27
27
  describe("maybeAddMissingImport", () => {
28
28
  beforeEach(() => {
29
- store.set(variablesAtom, {} as Variables);
30
29
  store.set(notebookAtom, MockNotebook.notebookState({ cellData: {} }));
31
30
  });
32
31
 
33
- it("should not add an import if the variable is already in the variables state", () => {
32
+ it("skips the import when a cell declares the name", () => {
34
33
  const appStore = createStore();
35
- appStore.set(variablesAtom, { mo: {} } as Variables);
34
+ setNotebookAnalysis(appStore, { [Cell1]: { defs: ["mo"] } });
36
35
  const onAddImport = vi.fn();
37
36
  maybeAddMissingImport({
38
37
  moduleName: "marimo",
@@ -52,7 +51,7 @@ describe("maybeAddMissingImport", () => {
52
51
  "should not add an import if the import statement already exists in the notebook",
53
52
  (code) => {
54
53
  const appStore = createStore();
55
- appStore.set(variablesAtom, {} as Variables);
54
+
56
55
  appStore.set(
57
56
  notebookAtom,
58
57
  MockNotebook.notebookState({
@@ -72,9 +71,16 @@ describe("maybeAddMissingImport", () => {
72
71
  },
73
72
  );
74
73
 
75
- it("should add an import if the variable is not in the variables state and the import statement does not exist in the notebook", () => {
74
+ it("adds a missing import even when the name is still bound in the kernel", () => {
76
75
  const appStore = createStore();
77
- appStore.set(variablesAtom, {} as Variables);
76
+ MockExecutions.seed(appStore, [
77
+ {
78
+ ...MockExecutions.completed(Cell1),
79
+ bindings: [{ name: "mo", type: "module", preview: "marimo" }],
80
+ },
81
+ ]);
82
+ setNotebookAnalysis(appStore, { [Cell1]: { refs: ["mo"] } });
83
+
78
84
  appStore.set(
79
85
  notebookAtom,
80
86
  MockNotebook.notebookState({
@@ -96,7 +102,6 @@ describe("maybeAddMissingImport", () => {
96
102
  it("should not create a new cell if import already exists due to skipIfCodeExists", () => {
97
103
  const addImports = [maybeAddMarimoImport, maybeAddAltairImport];
98
104
  for (const addImport of addImports) {
99
- store.set(variablesAtom, {} as Variables);
100
105
  store.set(
101
106
  notebookAtom,
102
107
  MockNotebook.notebookState({
@@ -3,12 +3,11 @@
3
3
  import { act, renderHook, waitFor } from "@testing-library/react";
4
4
  import { createStore, Provider } from "jotai";
5
5
  import { beforeEach, describe, expect, it, vi } from "vitest";
6
+ import { setNotebookAnalysis } from "@/__tests__/notebook-analysis";
6
7
  import { MockExecutions } from "@/__mocks__/executions";
7
8
  import { MockNotebook } from "@/__mocks__/notebook";
8
- import { variableName } from "@/__tests__/branded";
9
9
  import { notebookAtom } from "@/core/cells/cells";
10
10
  import { CellId } from "@/core/cells/ids";
11
- import { variablesAtom } from "@/core/variables/state";
12
11
  import {
13
12
  usePendingDelete,
14
13
  usePendingDeleteService,
@@ -48,7 +47,6 @@ describe("pending-delete-service", () => {
48
47
  MockExecutions.seed(store, [MockExecutions.took(cellId, 1)]);
49
48
 
50
49
  store.set(notebookAtom, notebook);
51
- store.set(variablesAtom, {});
52
50
 
53
51
  const { result } = renderHook(
54
52
  () => {
@@ -82,7 +80,6 @@ describe("pending-delete-service", () => {
82
80
  MockExecutions.seed(store, [MockExecutions.took(cellId, 100_000)]);
83
81
 
84
82
  store.set(notebookAtom, notebook);
85
- store.set(variablesAtom, {});
86
83
 
87
84
  const { result: serviceResult } = renderHook(
88
85
  () => usePendingDeleteService(),
@@ -130,12 +127,9 @@ describe("pending-delete-service", () => {
130
127
  ]);
131
128
 
132
129
  store.set(notebookAtom, notebook);
133
- store.set(variablesAtom, {
134
- [variableName("x")]: {
135
- name: variableName("x"),
136
- declaredBy: [cell1Id],
137
- usedBy: [cell2Id],
138
- },
130
+ setNotebookAnalysis(store, {
131
+ [cell1Id]: { defs: ["x"] },
132
+ [cell2Id]: { refs: ["x"] },
139
133
  });
140
134
 
141
135
  // cell1 with dependencies
@@ -171,7 +165,6 @@ describe("pending-delete-service", () => {
171
165
  ]);
172
166
 
173
167
  store.set(notebookAtom, notebook);
174
- store.set(variablesAtom, {});
175
168
 
176
169
  const { result: serviceResult } = renderHook(
177
170
  () => usePendingDeleteService(),
@@ -3,6 +3,7 @@
3
3
  import { runCells } from "../executions";
4
4
  import { store } from "../state/jotai";
5
5
  import { variablesAtom } from "../variables/state";
6
+ import type { VariableName } from "../variables/types";
6
7
  import { notebookAtom } from "./cells";
7
8
  import type { CreateCell, CreateCellOptions } from "./actions";
8
9
  import { CellId } from "./ids";
@@ -23,10 +24,8 @@ export function maybeAddMissingImport({
23
24
  onAddImport: (importStatement: string) => void;
24
25
  appStore?: typeof store;
25
26
  }): boolean {
26
- // If variableName is already in the variables state,
27
- // then the import is not missing (or the name has been taken).
28
27
  const variables = appStore.get(variablesAtom);
29
- if (variableName in variables) {
28
+ if (variables[variableName as VariableName]?.declaredBy.length) {
30
29
  return false;
31
30
  }
32
31
 
@@ -1,6 +1,10 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
3
  import { beforeEach, describe, expect, it, vi } from "vitest";
4
+ import {
5
+ type AnalysisCells,
6
+ setNotebookAnalysis,
7
+ } from "@/__tests__/notebook-analysis";
4
8
  import { cellId, variableName } from "@/__tests__/branded";
5
9
  import {
6
10
  type DataSourceConnection,
@@ -13,8 +17,6 @@ import type { DataTable } from "@/core/kernel/messages";
13
17
  import { store } from "@/core/state/jotai";
14
18
  import { storageAtom } from "@/core/storage/state";
15
19
  import type { StorageNamespace } from "@/core/storage/types";
16
- import { variablesAtom } from "@/core/variables/state";
17
- import type { Variables } from "@/core/variables/types";
18
20
  import { Logger } from "@/utils/Logger";
19
21
  import { getLensEntities } from "../entities";
20
22
 
@@ -52,7 +54,7 @@ function seedStore(opts: {
52
54
  tables?: DataTable[];
53
55
  namespaces?: StorageNamespace[];
54
56
  connections?: DataSourceConnection[];
55
- variables?: Variables;
57
+ cells?: AnalysisCells;
56
58
  }) {
57
59
  store.set(datasetsAtom, {
58
60
  tables: opts.tables ?? [],
@@ -69,7 +71,7 @@ function seedStore(opts: {
69
71
  latestEngineSelected: DUCKDB_ENGINE,
70
72
  connectionsMap: new Map((opts.connections ?? []).map((c) => [c.name, c])),
71
73
  });
72
- store.set(variablesAtom, opts.variables ?? {});
74
+ setNotebookAnalysis(store, opts.cells ?? {});
73
75
  }
74
76
 
75
77
  describe("getLensEntities", () => {
@@ -107,13 +109,7 @@ describe("getLensEntities", () => {
107
109
  it("excludes entities declared by a different cell", () => {
108
110
  seedStore({
109
111
  tables: [table("df")],
110
- variables: {
111
- [variableName("df")]: {
112
- name: variableName("df"),
113
- declaredBy: [OTHER_CELL],
114
- usedBy: [],
115
- },
116
- },
112
+ cells: { [OTHER_CELL]: { defs: ["df"] } },
117
113
  });
118
114
 
119
115
  expect(getLensEntities(CELL)).toEqual(new Map());
@@ -4,6 +4,10 @@ import { python } from "@codemirror/lang-python";
4
4
  import { EditorState } from "@codemirror/state";
5
5
  import { EditorView } from "@codemirror/view";
6
6
  import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
7
+ import {
8
+ type AnalysisCells,
9
+ setNotebookAnalysis,
10
+ } from "@/__tests__/notebook-analysis";
7
11
  import { cellId, variableName } from "@/__tests__/branded";
8
12
  import { languageAdapterState } from "@/core/codemirror/language/extension";
9
13
  import { LanguageAdapters } from "@/core/codemirror/language/LanguageAdapters";
@@ -20,8 +24,6 @@ import type { DataTable } from "@/core/kernel/messages";
20
24
  import { store } from "@/core/state/jotai";
21
25
  import { storageAtom } from "@/core/storage/state";
22
26
  import type { StorageNamespace } from "@/core/storage/types";
23
- import { variablesAtom } from "@/core/variables/state";
24
- import type { Variables } from "@/core/variables/types";
25
27
  import { openLensTarget } from "../actions";
26
28
  import {
27
29
  CODE_LENS_HOVER_DELAY_MS,
@@ -77,7 +79,7 @@ function seedStore(opts: {
77
79
  tables?: DataTable[];
78
80
  namespaces?: StorageNamespace[];
79
81
  connections?: DataSourceConnection[];
80
- variables?: Variables;
82
+ cells?: AnalysisCells;
81
83
  }) {
82
84
  store.set(datasetsAtom, {
83
85
  tables: opts.tables ?? [],
@@ -99,7 +101,7 @@ function seedStore(opts: {
99
101
  ]),
100
102
  ),
101
103
  });
102
- store.set(variablesAtom, opts.variables ?? {});
104
+ setNotebookAnalysis(store, opts.cells ?? {});
103
105
  }
104
106
 
105
107
  describe("codeLensBundle", () => {
@@ -155,7 +157,7 @@ describe("codeLensBundle", () => {
155
157
  seedStore({ tables: withLens ? [DF_TABLE] : [] });
156
158
  const v = await mount("df = load()");
157
159
  const dispatch = vi.spyOn(v, "dispatch");
158
- store.set(variablesAtom, {});
160
+ setNotebookAnalysis(store, {});
159
161
  vi.advanceTimersByTime(300);
160
162
  await Promise.resolve();
161
163
  expect(dispatch).not.toHaveBeenCalled();
@@ -410,16 +412,9 @@ describe("codeLensBundle", () => {
410
412
  });
411
413
 
412
414
  it("only decorates the declaring cell", async () => {
413
- const dfName = variableName("df");
414
415
  seedStore({
415
416
  tables: [DF_TABLE],
416
- variables: {
417
- [dfName]: {
418
- name: dfName,
419
- declaredBy: [cellId("other-cell")],
420
- usedBy: [cellId("cell1")],
421
- },
422
- },
417
+ cells: { "other-cell": { defs: ["df"] }, cell1: { refs: ["df"] } },
423
418
  });
424
419
  const v = await mount("df = load()");
425
420