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

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 (83) hide show
  1. package/dist/{ErrorBoundary-CYipPzuL.js → ErrorBoundary-C5X_T831.js} +1 -1
  2. package/dist/{chat-ui-b1ERxzeA.js → chat-ui-qZdDDrzU.js} +3 -3
  3. package/dist/{code-visibility-D2uVdtAQ.js → code-visibility-7FxdzbDq.js} +2 -2
  4. package/dist/{common-d-UA4Z2n.js → common-D-iTRwaQ.js} +3 -3
  5. package/dist/{data-grid-overlay-editor-BfZIG_OX.js → data-grid-overlay-editor-DoWUW2oW.js} +1 -1
  6. package/dist/{error-entries-Bl8fzLQc.js → error-entries-DhI0hGvj.js} +448 -450
  7. package/dist/{feedback-button-Ct0bgfAh.js → feedback-button-OUiV15AL.js} +3 -3
  8. package/dist/{glide-data-editor-D9EGRA-V.js → glide-data-editor-CFouYM6e.js} +3 -3
  9. package/dist/{globals-UnK9bjY3.js → globals-B_U6Frqj.js} +1 -1
  10. package/dist/{html-to-image-D6A1lg0A.js → html-to-image-B803aaWE.js} +1 -1
  11. package/dist/main.js +3213 -3203
  12. package/dist/{number-overlay-editor-DMasuqqm.js → number-overlay-editor-CiQQjf9m.js} +1 -1
  13. package/dist/{process-output-w5omHedc.js → process-output-CnCLfvnL.js} +2 -2
  14. package/dist/{reveal-component-v6w_cxzA.js → reveal-component-B73BObRc.js} +2 -2
  15. package/package.json +1 -1
  16. package/src/__mocks__/executions.ts +20 -19
  17. package/src/__mocks__/notebook.ts +1 -1
  18. package/src/__tests__/branded.ts +4 -0
  19. package/src/components/editor/actions/__tests__/name-cell-input.test.tsx +1 -1
  20. package/src/components/editor/cell/__tests__/useRunCells.test.tsx +5 -5
  21. package/src/components/editor/chrome/wrapper/__tests__/document-sync-status.test.tsx +5 -2
  22. package/src/components/tracing/tracing-keyboard.test.tsx +4 -3
  23. package/src/core/ai/context/providers/__tests__/error.test.ts +6 -3
  24. package/src/core/cells/__tests__/actions.test.ts +2 -2
  25. package/src/core/cells/__tests__/arrange.test.ts +1 -1
  26. package/src/core/cells/__tests__/harness.ts +9 -7
  27. package/src/core/cells/__tests__/layout.test.ts +1 -1
  28. package/src/core/cells/__tests__/runs.test.ts +14 -14
  29. package/src/core/cells/__tests__/utils.test.ts +3 -2
  30. package/src/core/cells/actions.ts +6 -6
  31. package/src/core/cells/cells.ts +1 -1
  32. package/src/core/cells/document.ts +1 -2
  33. package/src/core/cells/execution-console.ts +3 -3
  34. package/src/core/cells/ids.ts +2 -4
  35. package/src/core/cells/runs.ts +7 -5
  36. package/src/core/cells/session.ts +8 -5
  37. package/src/core/executions/__tests__/atoms.test.ts +7 -4
  38. package/src/core/executions/__tests__/freshness.test.ts +57 -53
  39. package/src/core/executions/__tests__/interrupt.test.ts +4 -3
  40. package/src/core/executions/__tests__/output-lifecycle.test.ts +3 -3
  41. package/src/core/executions/__tests__/output.test.ts +5 -3
  42. package/src/core/executions/__tests__/run.test.ts +4 -4
  43. package/src/core/executions/__tests__/select.test.ts +75 -67
  44. package/src/core/executions/atoms.ts +2 -2
  45. package/src/core/executions/freshness.ts +5 -5
  46. package/src/core/executions/output.ts +15 -21
  47. package/src/core/executions/select.ts +17 -9
  48. package/src/core/export/__tests__/hooks.test.ts +1 -1
  49. package/src/core/meta/__tests__/code-visibility.test.tsx +3 -2
  50. package/src/core/notebook/document/__tests__/codemirror.test.ts +8 -6
  51. package/src/core/notebook/document/__tests__/draft.test.ts +56 -58
  52. package/src/core/notebook/document/__tests__/fixtures.ts +8 -7
  53. package/src/core/notebook/document/__tests__/hooks.test.tsx +39 -35
  54. package/src/core/notebook/document/__tests__/lifecycle-scenarios.test.ts +8 -5
  55. package/src/core/notebook/document/__tests__/model.test.ts +8 -5
  56. package/src/core/notebook/document/__tests__/protocol-fixtures.ts +2 -2
  57. package/src/core/notebook/document/__tests__/recovery-scenarios.test.ts +37 -32
  58. package/src/core/notebook/document/__tests__/scenarios.test.ts +49 -45
  59. package/src/core/notebook/document/__tests__/state.test.ts +59 -56
  60. package/src/core/notebook/document/__tests__/submission.test.ts +15 -12
  61. package/src/core/notebook/document/__tests__/test-host.ts +3 -2
  62. package/src/core/notebook/document/__tests__/user.ts +7 -3
  63. package/src/core/notebook/document/draft.ts +29 -11
  64. package/src/core/notebook/document/state.ts +7 -6
  65. package/src/core/notebook/replica/__tests__/document.test.ts +9 -5
  66. package/src/core/notebook/replica/__tests__/executions.test.ts +16 -11
  67. package/src/core/notebook/replica/__tests__/fixtures.ts +6 -2
  68. package/src/core/notebook/replica/__tests__/replica.test.ts +7 -2
  69. package/src/core/notebook/replica/__tests__/results.test.ts +23 -19
  70. package/src/core/notebook/replica/execution-state.ts +2 -2
  71. package/src/core/notebook/replica/replica.ts +2 -2
  72. package/src/core/notebook/replica/resources/analysis.ts +1 -1
  73. package/src/core/notebook/replica/resources/document.ts +9 -8
  74. package/src/core/notebook/replica/resources/executions.ts +2 -2
  75. package/src/core/notebook/replica/resources/results.ts +2 -2
  76. package/src/core/saving/__tests__/document.test.tsx +1 -1
  77. package/src/core/saving/__tests__/state.test.ts +2 -2
  78. package/src/core/session/__tests__/useNotebookSession.hook.test.tsx +9 -4
  79. package/src/core/session/useNotebookReplica.ts +1 -1
  80. package/src/core/session/useNotebookSession.tsx +1 -1
  81. package/src/core/transports/__tests__/static.test.ts +3 -2
  82. package/src/core/transports/static.ts +2 -2
  83. package/src/core/wasm/bridge.ts +5 -4
@@ -13,14 +13,19 @@ import {
13
13
  queuedOrRunningCount,
14
14
  runningCellIds,
15
15
  } from "../select";
16
+ import { cellId, runId } from "@/__tests__/branded";
17
+
18
+ const C1 = cellId("c1");
19
+ const C2 = cellId("c2");
20
+ const C9 = cellId("c9");
16
21
 
17
22
  it("counts only distinct disabled ancestors in a cycle", () => {
18
- const analysis: Protocol.Analysis = {
23
+ const analysis: Protocol.AnalysisOutput = {
19
24
  notebook_id: "n1",
20
25
  document_etag: "v1",
21
26
  cells: {
22
- a: { defs: [], refs: [], parents: ["b"], diagnostics: [] },
23
- b: { defs: [], refs: [], parents: ["a"], diagnostics: [] },
27
+ a: { defs: [], refs: [], parents: [cellId("b")], diagnostics: [] },
28
+ b: { defs: [], refs: [], parents: [cellId("a")], diagnostics: [] },
24
29
  },
25
30
  };
26
31
  const disabled = (id: string) =>
@@ -38,20 +43,20 @@ const T0 = "2026-10-01T09:20:11Z";
38
43
  const T1 = "2026-10-01T09:20:12.500Z";
39
44
  const T2 = "2026-10-01T09:20:20Z";
40
45
 
41
- const QUEUED: Protocol.ExecutionState = { status: "queued" };
42
- const RUNNING: Protocol.ExecutionState = {
46
+ const QUEUED: Protocol.ExecutionStateOutput = { status: "queued" };
47
+ const RUNNING: Protocol.ExecutionStateOutput = {
43
48
  status: "running",
44
49
  started_at: T0,
45
50
  };
46
51
 
47
52
  function record(
48
- overrides: Partial<Protocol.Execution> & { id: string },
49
- ): Protocol.Execution {
53
+ overrides: Partial<Protocol.ExecutionOutput> & { id: string },
54
+ ): Protocol.ExecutionOutput {
50
55
  return {
51
- run_id: "run-1",
56
+ run_id: runId("run-1"),
52
57
  runtime_id: "r1",
53
58
  caused_by_id: null,
54
- cell_id: "c1",
59
+ cell_id: C1,
55
60
  code_fingerprint: "0f71456db2ea83f4",
56
61
  created_at: null,
57
62
  state: {
@@ -65,7 +70,9 @@ function record(
65
70
  };
66
71
  }
67
72
 
68
- function execution(overrides: Partial<Protocol.Execution> & { id: string }) {
73
+ function execution(
74
+ overrides: Partial<Protocol.ExecutionOutput> & { id: string },
75
+ ) {
69
76
  return {
70
77
  record: record(overrides),
71
78
  output: null,
@@ -79,12 +86,12 @@ function run(
79
86
  cells: string[],
80
87
  status: Protocol.RunState["status"],
81
88
  id = "run-1",
82
- ): Protocol.Run {
89
+ ): Protocol.RunOutput {
83
90
  return {
84
- id,
91
+ id: runId(id),
85
92
  notebook_id: "n1",
86
93
  runtime_id: "r1",
87
- origin: { kind: "cells", cell_ids: cells },
94
+ origin: { kind: "cells", cell_ids: cells.map(cellId) },
88
95
  created_at: "2026-10-01T09:20:00Z",
89
96
  state:
90
97
  status === "completed"
@@ -100,7 +107,7 @@ function run(
100
107
  };
101
108
  }
102
109
 
103
- const CELLS = ["c1", "c2", "c3", "c4", "c5"];
110
+ const CELLS = ["c1", "c2", "c3", "c4", "c5"].map(cellId);
104
111
 
105
112
  /** Inputs whose document has `CELLS`, with `disabled` kept from running. */
106
113
  function inputs({
@@ -113,11 +120,11 @@ function inputs({
113
120
  runtimeId = null,
114
121
  }: {
115
122
  executions?: Execution[];
116
- runs?: Protocol.Run[];
123
+ runs?: Protocol.RunOutput[];
117
124
  results?: Results;
118
- requested?: ReadonlySet<string>;
125
+ requested?: ReadonlySet<Protocol.CellId>;
119
126
  disabled?: readonly string[];
120
- blocked?: ReadonlySet<string>;
127
+ blocked?: ReadonlySet<Protocol.CellId>;
121
128
  runtimeId?: string | null;
122
129
  }): CellExecutionInputs {
123
130
  const stream: Executions = {
@@ -150,7 +157,7 @@ function inputs({
150
157
 
151
158
  describe("cellExecutionView", () => {
152
159
  it("is idle with no outcome before a cell runs", () => {
153
- expect(cellExecutionView(inputs({}), "c1")).toEqual({
160
+ expect(cellExecutionView(inputs({}), C1)).toEqual({
154
161
  status: "idle",
155
162
  blocked: false,
156
163
  shownBlock: null,
@@ -170,7 +177,7 @@ describe("cellExecutionView", () => {
170
177
  }),
171
178
  ],
172
179
  });
173
- expect(cellExecutionView(queued, "c1").status).toBe("queued");
180
+ expect(cellExecutionView(queued, C1).status).toBe("queued");
174
181
  const running = inputs({
175
182
  executions: [
176
183
  execution({
@@ -178,9 +185,9 @@ describe("cellExecutionView", () => {
178
185
  state: { status: "running", started_at: T2 },
179
186
  }),
180
187
  ],
181
- results: new Map([["c1", execution({ id: "e0" })]]),
188
+ results: new Map([[C1, execution({ id: "e0" })]]),
182
189
  });
183
- expect(cellExecutionView(running, "c1")).toEqual({
190
+ expect(cellExecutionView(running, C1)).toEqual({
184
191
  status: "running",
185
192
  blocked: false,
186
193
  shownBlock: null,
@@ -195,8 +202,8 @@ describe("cellExecutionView", () => {
195
202
  const result = execution({ id: "e1" });
196
203
  const produced = (runtimeId: string | null) =>
197
204
  cellExecutionView(
198
- inputs({ results: new Map([["c1", result]]), runtimeId }),
199
- "c1",
205
+ inputs({ results: new Map([[C1, result]]), runtimeId }),
206
+ C1,
200
207
  ).live;
201
208
  expect(produced("r1")).toBe(true);
202
209
  // A restart replaces the runtime and keeps the results.
@@ -207,31 +214,31 @@ describe("cellExecutionView", () => {
207
214
  expect(
208
215
  cellExecutionView(
209
216
  inputs({
210
- results: new Map([["c1", execution({ id: "e1", runtime_id: null })]]),
217
+ results: new Map([[C1, execution({ id: "e1", runtime_id: null })]]),
211
218
  runtimeId: "r1",
212
219
  }),
213
- "c1",
220
+ C1,
214
221
  ).live,
215
222
  ).toBe(false);
216
223
  });
217
224
 
218
225
  it("reports how the last completed execution ended, with its timing", () => {
219
- const completedWith = (outcome: Protocol.ExecutionOutcome) => ({
226
+ const completedWith = (outcome: Protocol.ExecutionOutcomeOutput) => ({
220
227
  status: "completed" as const,
221
228
  started_at: T0,
222
229
  completed_at: T1,
223
230
  outcome,
224
231
  depends_on: {},
225
232
  });
226
- const ended = (outcome: Protocol.ExecutionOutcome) =>
233
+ const ended = (outcome: Protocol.ExecutionOutcomeOutput) =>
227
234
  cellExecutionView(
228
235
  inputs({
229
236
  executions: [execution({ id: "e1", state: completedWith(outcome) })],
230
237
  results: new Map([
231
- ["c1", execution({ id: "e1", state: completedWith(outcome) })],
238
+ [C1, execution({ id: "e1", state: completedWith(outcome) })],
232
239
  ]),
233
240
  }),
234
- "c1",
241
+ C1,
235
242
  );
236
243
  const value = ended({ kind: "succeeded" });
237
244
  expect(value).toEqual({
@@ -243,7 +250,7 @@ describe("cellExecutionView", () => {
243
250
  duration: 1500,
244
251
  live: true,
245
252
  });
246
- const error = (kind: string): Protocol.ExecutionOutcome => ({
253
+ const error = (kind: string): Protocol.ExecutionOutcomeOutput => ({
247
254
  kind: "failed",
248
255
  error: {
249
256
  kind,
@@ -257,7 +264,7 @@ describe("cellExecutionView", () => {
257
264
  },
258
265
  });
259
266
  expect(ended(error("exception")).outcome).toBe("failed");
260
- const skipped: Protocol.ExecutionOutcome = {
267
+ const skipped: Protocol.ExecutionOutcomeOutput = {
261
268
  kind: "skipped",
262
269
  reason: "ancestor-stopped",
263
270
  message: "",
@@ -270,25 +277,25 @@ describe("cellExecutionView", () => {
270
277
  it("reads as queued from a request the stream has not shown a run for", () => {
271
278
  const requested = inputs({
272
279
  executions: [execution({ id: "e1" })],
273
- results: new Map([["c1", execution({ id: "e1" })]]),
274
- requested: new Set(["c1"]),
280
+ results: new Map([[C1, execution({ id: "e1" })]]),
281
+ requested: new Set([C1]),
275
282
  });
276
- expect(cellExecutionView(requested, "c1").status).toBe("queued");
277
- expect(cellExecutionView(requested, "c1").outcome).toBeNull();
283
+ expect(cellExecutionView(requested, C1).status).toBe("queued");
284
+ expect(cellExecutionView(requested, C1).outcome).toBeNull();
278
285
 
279
- const fresh = inputs({ requested: new Set(["c1"]) });
280
- expect(cellExecutionView(fresh, "c1").status).toBe("queued");
286
+ const fresh = inputs({ requested: new Set([C1]) });
287
+ expect(cellExecutionView(fresh, C1).status).toBe("queued");
281
288
  });
282
289
 
283
290
  it("reads as queued from an unfinished run that names the cell until it is planned", () => {
284
- const result = new Map([["c1", execution({ id: "e1" })]]);
291
+ const result = new Map([[C1, execution({ id: "e1" })]]);
285
292
  const accepted = inputs({
286
293
  runs: [run(["c1"], "queued", "run-2")],
287
294
  executions: [execution({ id: "e1" })],
288
295
  results: result,
289
296
  });
290
- expect(cellExecutionView(accepted, "c1").status).toBe("queued");
291
- expect(cellExecutionView(accepted, "c1").outcome).toBeNull();
297
+ expect(cellExecutionView(accepted, C1).status).toBe("queued");
298
+ expect(cellExecutionView(accepted, C1).outcome).toBeNull();
292
299
 
293
300
  // The cell's execution in the run takes over once the kernel plans it.
294
301
  const planned = inputs({
@@ -296,66 +303,65 @@ describe("cellExecutionView", () => {
296
303
  executions: [
297
304
  execution({
298
305
  id: "e2",
299
- run_id: "run-2",
306
+ run_id: runId("run-2"),
300
307
  state: RUNNING,
301
308
  }),
302
309
  ],
303
310
  results: result,
304
311
  });
305
- expect(cellExecutionView(planned, "c1").status).toBe("running");
312
+ expect(cellExecutionView(planned, C1).status).toBe("running");
306
313
 
307
314
  const done = inputs({
308
315
  runs: [run(["c1", "c2"], "running", "run-2")],
309
- executions: [execution({ id: "e2", run_id: "run-2" })],
310
- results: new Map([["c1", execution({ id: "e2", run_id: "run-2" })]]),
316
+ executions: [execution({ id: "e2", run_id: runId("run-2") })],
317
+ results: new Map([[C1, execution({ id: "e2", run_id: runId("run-2") })]]),
311
318
  });
312
- expect(cellExecutionView(done, "c1").status).toBe("idle");
313
- expect(cellExecutionView(done, "c1").outcome).toBe("succeeded");
314
- expect(cellExecutionView(done, "c2").status).toBe("queued");
319
+ expect(cellExecutionView(done, C1).status).toBe("idle");
320
+ expect(cellExecutionView(done, C1).outcome).toBe("succeeded");
321
+ expect(cellExecutionView(done, C2).status).toBe("queued");
315
322
 
316
323
  // The stream let the execution go while its run goes on with other cells.
317
324
  const retained = inputs({
318
325
  runs: [run(["c1", "c2"], "running", "run-2")],
319
- results: new Map([["c1", execution({ id: "e2", run_id: "run-2" })]]),
326
+ results: new Map([[C1, execution({ id: "e2", run_id: runId("run-2") })]]),
320
327
  });
321
- expect(cellExecutionView(retained, "c1").status).toBe("idle");
322
- expect(cellExecutionView(retained, "c2").status).toBe("queued");
328
+ expect(cellExecutionView(retained, C1).status).toBe("idle");
329
+ expect(cellExecutionView(retained, C2).status).toBe("queued");
323
330
 
324
331
  // A later run names the cell again while the earlier one's result stands.
325
332
  const again = inputs({
326
333
  runs: [run(["c1"], "running", "run-2"), run(["c1"], "queued", "run-3")],
327
- executions: [execution({ id: "e2", run_id: "run-2" })],
328
- results: new Map([["c1", execution({ id: "e2", run_id: "run-2" })]]),
334
+ executions: [execution({ id: "e2", run_id: runId("run-2") })],
335
+ results: new Map([[C1, execution({ id: "e2", run_id: runId("run-2") })]]),
329
336
  });
330
- expect(cellExecutionView(again, "c1").status).toBe("queued");
337
+ expect(cellExecutionView(again, C1).status).toBe("queued");
331
338
 
332
339
  const over = inputs({ runs: [run(["c1"], "completed")] });
333
- expect(cellExecutionView(over, "c1").status).toBe("idle");
340
+ expect(cellExecutionView(over, C1).status).toBe("idle");
334
341
  });
335
342
 
336
343
  it("does not read as queued a named cell a run cannot reach", () => {
337
344
  const runs = [run(["c1", "c9"], "queued")];
338
345
  expect(
339
- cellExecutionView(inputs({ runs, disabled: ["c1"] }), "c1").status,
346
+ cellExecutionView(inputs({ runs, disabled: ["c1"] }), C1).status,
340
347
  ).toBe("idle");
341
348
  expect(
342
- cellExecutionView(inputs({ runs, blocked: new Set(["c1"]) }), "c1")
343
- .status,
349
+ cellExecutionView(inputs({ runs, blocked: new Set([C1]) }), C1).status,
344
350
  ).toBe("idle");
345
351
  // The document no longer has c9.
346
- expect(cellExecutionView(inputs({ runs }), "c9").status).toBe("idle");
352
+ expect(cellExecutionView(inputs({ runs }), C9).status).toBe("idle");
347
353
  expect(
348
- cellExecutionView(inputs({ requested: new Set(["c9"]) }), "c9").status,
354
+ cellExecutionView(inputs({ requested: new Set([C9]) }), C9).status,
349
355
  ).toBe("idle");
350
356
  });
351
357
 
352
358
  it("shows a blocked cell as disabled transitively, with its last outcome", () => {
353
359
  const view = cellExecutionView(
354
360
  inputs({
355
- results: new Map([["c1", execution({ id: "e1" })]]),
356
- blocked: new Set(["c1"]),
361
+ results: new Map([[C1, execution({ id: "e1" })]]),
362
+ blocked: new Set([C1]),
357
363
  }),
358
- "c1",
364
+ C1,
359
365
  );
360
366
  expect(view.status).toBe("idle");
361
367
  expect(view.blocked).toBe(true);
@@ -369,10 +375,10 @@ describe("notebook-level views", () => {
369
375
  execution({ id: "e1", state: RUNNING }),
370
376
  execution({
371
377
  id: "e2",
372
- cell_id: "c2",
378
+ cell_id: C2,
373
379
  state: QUEUED,
374
380
  }),
375
- execution({ id: "e3", cell_id: "c3" }),
381
+ execution({ id: "e3", cell_id: cellId("c3") }),
376
382
  execution({
377
383
  id: "s1",
378
384
  cell_id: null,
@@ -380,8 +386,10 @@ describe("notebook-level views", () => {
380
386
  }),
381
387
  ],
382
388
  runs: [run(["c1", "c2", "c5"], "running"), run(["c5"], "queued", "run-2")],
383
- results: new Map([["c5", execution({ id: "e5", cell_id: "c5" })]]),
384
- requested: new Set(["c2", "c4"]),
389
+ results: new Map([
390
+ [cellId("c5"), execution({ id: "e5", cell_id: cellId("c5") })],
391
+ ]),
392
+ requested: new Set([C2, cellId("c4")]),
385
393
  });
386
394
 
387
395
  it("counts unfinished executions and cells awaiting a run the kernel has not planned", () => {
@@ -399,7 +407,7 @@ describe("notebook-level views", () => {
399
407
  cell_id: null,
400
408
  state: RUNNING,
401
409
  }),
402
- execution({ id: "e3", cell_id: "c3" }),
410
+ execution({ id: "e3", cell_id: cellId("c3") }),
403
411
  ],
404
412
  });
405
413
  expect(anyRunning(scratch.executions)).toBe(true);
@@ -42,7 +42,7 @@ const NO_EXECUTIONS: Executions = {
42
42
  scratch: null,
43
43
  };
44
44
  const NO_RESULTS: Results = new Map();
45
- const NO_CELLS: ReadonlyMap<Protocol.CellId, Protocol.Cell> = new Map();
45
+ const NO_CELLS: ReadonlyMap<Protocol.CellId, Protocol.CellOutput> = new Map();
46
46
  const NO_REQUESTS: ReadonlySet<RunRequest> = new Set();
47
47
  const NO_REQUESTED: ReadonlySet<Protocol.CellId> = new Set();
48
48
  const NO_BLOCKED: ReadonlySet<Protocol.CellId> = new Set();
@@ -380,7 +380,7 @@ export function withdrawRequest(store: Store, request: RunRequest): void {
380
380
  export function acceptRun(
381
381
  store: Store,
382
382
  request: RunRequest,
383
- run: Protocol.Run,
383
+ run: Protocol.RunOutput,
384
384
  ): void {
385
385
  const waitingAtom = atom(
386
386
  (get) =>
@@ -38,7 +38,7 @@ const CURRENT: CellFreshness = { sourceChanged: false, inputsChanged: false };
38
38
  /** What freshness is derived from. */
39
39
  export interface CellFreshnessInputs {
40
40
  /** The document's cells, for the fingerprint of each cell's source. */
41
- readonly cells: ReadonlyMap<Protocol.CellId, Protocol.Cell>;
41
+ readonly cells: ReadonlyMap<Protocol.CellId, Protocol.CellOutput>;
42
42
  /** The stream's executions, for the variables currently bound. */
43
43
  readonly executions: Executions;
44
44
  /** Each cell's last completed record, the result being compared. */
@@ -81,7 +81,7 @@ export function freshnessOf(inputs: CellFreshnessInputs): CellFreshnessLookup {
81
81
 
82
82
  /** Whether a value the record read has changed, or one upstream has. */
83
83
  function inputsChanged(
84
- record: Protocol.Execution,
84
+ record: Protocol.ExecutionOutput,
85
85
  visiting: ReadonlySet<Protocol.ExecutionId>,
86
86
  ): boolean {
87
87
  const path = new Set(visiting).add(record.id);
@@ -135,8 +135,8 @@ export function freshnessOf(inputs: CellFreshnessInputs): CellFreshnessLookup {
135
135
 
136
136
  /** Compare against pending work before the result it will replace. */
137
137
  function sourceChanged(
138
- cell: Protocol.Cell,
139
- result: Protocol.Execution,
138
+ cell: Protocol.CellOutput,
139
+ result: Protocol.ExecutionOutput,
140
140
  ): boolean {
141
141
  const latest = inputs.executions.latest.get(cell.id);
142
142
  const pending = latest === undefined ? undefined : recordOf(latest);
@@ -148,7 +148,7 @@ export function freshnessOf(inputs: CellFreshnessInputs): CellFreshnessLookup {
148
148
  }
149
149
 
150
150
  function ofRecord(
151
- record: Protocol.Execution,
151
+ record: Protocol.ExecutionOutput,
152
152
  visiting: ReadonlySet<Protocol.ExecutionId>,
153
153
  ): CellFreshness {
154
154
  const known = memo.get(record.id);
@@ -53,16 +53,11 @@ const NO_CELLS: ReadonlyMap<Protocol.CellId, Protocol.Cell> = new Map();
53
53
 
54
54
  const ERROR_MIMETYPE = "application/vnd.marimo+error";
55
55
 
56
- /** The protocol's ids are plain strings; the editor brands them. */
57
- function brand(id: Protocol.CellId): CellId {
58
- return id as CellId;
59
- }
60
-
61
56
  function related(
62
- cells: readonly Protocol.Related[],
57
+ cells: readonly Protocol.RelatedOutput[],
63
58
  ): HostDiagnostic["related"] {
64
59
  return cells.map(({ cell_id, message }) => ({
65
- cell_id: brand(cell_id),
60
+ cell_id: cell_id,
66
61
  message,
67
62
  }));
68
63
  }
@@ -71,12 +66,12 @@ function seconds(iso: string | null): number {
71
66
  return iso === null ? 0 : Date.parse(iso) / 1000;
72
67
  }
73
68
 
74
- function endedAt(record: Protocol.Execution): number {
69
+ function endedAt(record: Protocol.ExecutionOutput): number {
75
70
  return seconds(completedAt(record) ?? startedAt(record));
76
71
  }
77
72
 
78
73
  function valueOutput(
79
- record: Protocol.Execution,
74
+ record: Protocol.ExecutionOutput,
80
75
  value: Protocol.Media,
81
76
  ): CellOutput {
82
77
  return {
@@ -88,7 +83,7 @@ function valueOutput(
88
83
  }
89
84
 
90
85
  function errorOutput(
91
- record: Protocol.Execution,
86
+ record: Protocol.ExecutionOutput,
92
87
  data: CellError[],
93
88
  ): CellOutput {
94
89
  return {
@@ -100,9 +95,8 @@ function errorOutput(
100
95
  }
101
96
 
102
97
  /** The cell an exception was blamed on, which is the one cell the host relates to it. */
103
- function raisingCell(error: Protocol.Error): CellId | null {
104
- const raised = error.related.at(0);
105
- return raised === undefined ? null : brand(raised.cell_id);
98
+ function raisingCell(error: Protocol.ErrorOutput): CellId | null {
99
+ return error.related.at(0)?.cell_id ?? null;
106
100
  }
107
101
 
108
102
  /**
@@ -112,7 +106,7 @@ function raisingCell(error: Protocol.Error): CellId | null {
112
106
  * which the renderer treats with their own affordances. Every other kind
113
107
  * is a diagnostic.
114
108
  */
115
- export function cellError(error: Protocol.Error): CellError {
109
+ export function cellError(error: Protocol.ErrorOutput): CellError {
116
110
  switch (error.kind) {
117
111
  case "exception":
118
112
  return {
@@ -142,8 +136,8 @@ export function cellError(error: Protocol.Error): CellError {
142
136
 
143
137
  /** The notice a skipped cell shows in place of a value. */
144
138
  function skippedOutput(
145
- record: Protocol.Execution,
146
- outcome: Protocol.ExecutionSkippedOutcome,
139
+ record: Protocol.ExecutionOutput,
140
+ outcome: Protocol.ExecutionSkippedOutcomeOutput,
147
141
  ): CellOutput {
148
142
  const cause = outcome.related[0];
149
143
  if (cause !== undefined && outcome.reason === "upstream-stopped") {
@@ -151,7 +145,7 @@ function skippedOutput(
151
145
  {
152
146
  type: "ancestor-stopped",
153
147
  msg: outcome.message,
154
- raising_cell: brand(cause.cell_id),
148
+ raising_cell: cause.cell_id,
155
149
  },
156
150
  ]);
157
151
  }
@@ -163,8 +157,8 @@ function skippedOutput(
163
157
  {
164
158
  type: "ancestor-prevented",
165
159
  msg: outcome.message,
166
- raising_cell: brand(cause.cell_id),
167
- blamed_cell: blamed === undefined ? null : brand(blamed.cell_id),
160
+ raising_cell: cause.cell_id,
161
+ blamed_cell: blamed === undefined ? null : blamed.cell_id,
168
162
  },
169
163
  ]);
170
164
  }
@@ -186,7 +180,7 @@ function skippedOutput(
186
180
  * the execution's own until an edit is confirmed.
187
181
  */
188
182
  export function executionSource(
189
- record: Protocol.Execution,
183
+ record: Protocol.ExecutionOutput,
190
184
  cells: ReadonlyMap<Protocol.CellId, Protocol.Cell> = NO_CELLS,
191
185
  ): string | undefined {
192
186
  const cell = record.cell_id === null ? undefined : cells.get(record.cell_id);
@@ -309,7 +303,7 @@ export function cellOutputsView(
309
303
  for (const cellId of cellIds) {
310
304
  const output = cellOutputView(inputs, cellId);
311
305
  if (output !== null) {
312
- outputs.set(brand(cellId), output);
306
+ outputs.set(cellId, output);
313
307
  }
314
308
  }
315
309
  return outputs;
@@ -43,7 +43,10 @@ export interface CellExecutionInputs {
43
43
  * The cells of the confirmed document. A run can only reach a cell the
44
44
  * document has, and the kernel sets aside one the document has disabled.
45
45
  */
46
- readonly cells: ReadonlyMap<Protocol.CellId, Pick<Protocol.Cell, "config">>;
46
+ readonly cells: ReadonlyMap<
47
+ Protocol.CellId,
48
+ Pick<Protocol.CellOutput, "config">
49
+ >;
47
50
  /**
48
51
  * Cells this browser has asked to run, while the stream has not yet
49
52
  * shown the run.
@@ -76,19 +79,24 @@ function latestOf(
76
79
 
77
80
  /** Cells with a distinct disabled ancestor in the host's dependency graph. */
78
81
  export function blockedDescendants(
79
- analysis: Protocol.Analysis,
80
- cells: Iterable<Protocol.Cell>,
82
+ analysis: Protocol.AnalysisOutput,
83
+ cells: Iterable<Protocol.CellOutput>,
81
84
  ): ReadonlySet<Protocol.CellId> {
82
85
  const blocked = new Set<Protocol.CellId>();
83
- const roots = [...cells].filter((cell) => cell.config.disabled);
86
+ const documentCells = [...cells];
87
+ const roots = documentCells.filter((cell) => cell.config.disabled);
84
88
  if (roots.length === 0) {
85
89
  return blocked;
86
90
  }
87
- const children = new Map<Protocol.CellId, Protocol.CellId[]>();
88
- for (const id of Object.keys(analysis.cells)) {
89
- children.set(id, []);
90
- }
91
- for (const [id, { parents }] of Object.entries(analysis.cells)) {
91
+ const children = new Map<Protocol.CellId, Protocol.CellId[]>(
92
+ documentCells.map(({ id }) => [id, []]),
93
+ );
94
+ for (const { id } of documentCells) {
95
+ const entry = analysis.cells[id];
96
+ if (!entry) {
97
+ continue;
98
+ }
99
+ const { parents } = entry;
92
100
  if (parents === undefined) {
93
101
  return blocked;
94
102
  }
@@ -53,7 +53,7 @@ describe("useEnrichCellOutputs", () => {
53
53
  /** A completed execution per cell that shows its `output`. */
54
54
  const createMockCellRuntimes = (
55
55
  cells: Record<string, { output: CellOutput | null }>,
56
- ): Array<Protocol.Execution | Protocol.Output> =>
56
+ ): Array<Protocol.ExecutionOutput | Protocol.Output> =>
57
57
  Object.entries(cells).flatMap(([cellId, { output }]) =>
58
58
  output === null
59
59
  ? []
@@ -1,5 +1,6 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
+ import { cellId } from "@/__tests__/branded";
3
4
  import { renderHook } from "@testing-library/react";
4
5
  import type * as Protocol from "@marimo-team/client/protocol";
5
6
  import { atom, createStore, Provider } from "jotai";
@@ -28,8 +29,8 @@ interface StoreOpts {
28
29
  }
29
30
 
30
31
  function document(codes: ReadonlyArray<string | null>): Document {
31
- const cells = codes.map((code, index): Protocol.Cell => ({
32
- id: `cell-${index}` as Protocol.CellId,
32
+ const cells = codes.map((code, index): Protocol.CellOutput => ({
33
+ id: cellId(`cell-${index}`),
33
34
  notebook_id: "nb",
34
35
  code,
35
36
  name: "_",
@@ -35,6 +35,8 @@ import { createDocumentModel } from "../model";
35
35
  import { fakeBackend } from "../../replica/__tests__/fixtures";
36
36
  import { cell, document, withCells } from "./fixtures";
37
37
 
38
+ const C1 = brandedCellId("c1");
39
+
38
40
  const views: EditorView[] = [];
39
41
  const lifetimes: AbortController[] = [];
40
42
 
@@ -117,7 +119,7 @@ function languages(id: CellId) {
117
119
 
118
120
  function setup({
119
121
  initial = document(),
120
- cellId = "c1",
122
+ cellId = brandedCellId("c1"),
121
123
  doc = "",
122
124
  adapters = false,
123
125
  }: {
@@ -193,10 +195,10 @@ describe("cellCodeBinding", () => {
193
195
  await settle();
194
196
  // Another subscriber normalizes code synchronously, inside the push.
195
197
  const unsubscribe = store.sub(model.documentAtom, () => {
196
- const code = store.get(model.documentAtom)?.cells.get("c1")?.code;
198
+ const code = store.get(model.documentAtom)?.cells.get(C1)?.code;
197
199
  if (code?.includes(" + ")) {
198
200
  const normalized = code.replaceAll(" + ", "+");
199
- store.set(model.editAtom, (tx) => tx.setCode("c1", normalized));
201
+ store.set(model.editAtom, (tx) => tx.setCode(C1, normalized));
200
202
  }
201
203
  });
202
204
  type(" + 1");
@@ -282,7 +284,7 @@ describe("cellCodeBinding", () => {
282
284
  });
283
285
 
284
286
  it("follows a cell once its code is available", async () => {
285
- const absent = setup({ cellId: "c3" });
287
+ const absent = setup({ cellId: brandedCellId("c3") });
286
288
  const withheld = setup({
287
289
  initial: withCells(document(), { c1: cell("c1", "", { code: null }) }),
288
290
  });
@@ -316,7 +318,7 @@ describe("cellCodeBinding", () => {
316
318
  });
317
319
 
318
320
  it("leaves the editor alone for an absent cell or withheld source", async () => {
319
- const absent = setup({ cellId: "c9", doc: "local" });
321
+ const absent = setup({ cellId: brandedCellId("c9"), doc: "local" });
320
322
  const withheld = setup({
321
323
  initial: withCells(document(), { c1: cell("c1", "", { code: null }) }),
322
324
  doc: "local",
@@ -519,7 +521,7 @@ describe("cellCodeBinding", () => {
519
521
  switchLanguage(view, { language: "python" });
520
522
  await settle();
521
523
 
522
- store.set(model.editAtom, (tx) => tx.setName("c1", "renamed"));
524
+ store.set(model.editAtom, (tx) => tx.setName(C1, "renamed"));
523
525
  await settle();
524
526
 
525
527
  expect(language(view)).toBe("python");