@marimo-team/islands 0.23.15-dev2 → 0.23.15-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 (42) hide show
  1. package/dist/{chat-ui-DinOvbWu.js → chat-ui-FiwuOgQU.js} +3094 -3094
  2. package/dist/{code-visibility-B-sydhvS.js → code-visibility-Bqg6aos7.js} +925 -842
  3. package/dist/{html-to-image-_wGfk8V-.js → html-to-image-JXL8cvmt.js} +2218 -2205
  4. package/dist/main.js +1066 -1073
  5. package/dist/{process-output-Mh4UrjwM.js → process-output-CnDIXtM-.js} +1 -1
  6. package/dist/{reveal-component-MK2nUbwt.js → reveal-component-BzkgqXit.js} +614 -602
  7. package/dist/style.css +1 -1
  8. package/package.json +1 -1
  9. package/src/components/chat/__tests__/chat-utils.test.ts +244 -1
  10. package/src/components/chat/__tests__/message-queue.test.tsx +121 -0
  11. package/src/components/chat/chat-panel.tsx +196 -67
  12. package/src/components/chat/chat-utils.ts +111 -2
  13. package/src/components/editor/SortableCell.tsx +6 -2
  14. package/src/components/editor/__tests__/output-persistence.test.tsx +241 -0
  15. package/src/components/editor/actions/__tests__/pair-with-agent-commands.test.ts +153 -0
  16. package/src/components/editor/actions/pair-with-agent-commands.ts +109 -0
  17. package/src/components/editor/actions/pair-with-agent-modal.tsx +20 -64
  18. package/src/components/editor/cell/cell-context-menu.tsx +7 -0
  19. package/src/components/editor/chrome/panels/packages-panel.tsx +11 -1
  20. package/src/components/editor/columns/__tests__/cell-column.test.tsx +105 -0
  21. package/src/components/editor/columns/cell-column.tsx +34 -4
  22. package/src/components/editor/columns/sortable-column.tsx +24 -4
  23. package/src/components/editor/notebook-cell.tsx +203 -106
  24. package/src/components/editor/renderers/__tests__/cells-renderer.test.tsx +66 -0
  25. package/src/components/editor/renderers/cell-array.tsx +26 -13
  26. package/src/components/editor/renderers/cells-renderer.tsx +8 -2
  27. package/src/components/editor/renderers/slides-layout/__tests__/plugin.test.ts +29 -0
  28. package/src/components/editor/renderers/slides-layout/types.ts +4 -0
  29. package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +19 -19
  30. package/src/components/slides/reveal-component.tsx +33 -4
  31. package/src/components/slides/slide-form.tsx +72 -0
  32. package/src/core/cells/__tests__/utils.test.ts +59 -0
  33. package/src/core/cells/utils.ts +51 -0
  34. package/src/css/app/Cell.css +10 -0
  35. package/src/hooks/__tests__/useHotkey.test.tsx +88 -0
  36. package/src/hooks/useHotkey.ts +29 -4
  37. package/src/plugins/impl/anywidget/__tests__/host.test.ts +6 -9
  38. package/src/plugins/impl/anywidget/__tests__/widget-binding.test.ts +22 -61
  39. package/src/plugins/impl/anywidget/model-proxy.ts +0 -13
  40. package/src/plugins/impl/anywidget/widget-binding.ts +4 -34
  41. package/src/plugins/impl/matplotlib/__tests__/matplotlib-renderer.test.ts +71 -3
  42. package/src/plugins/impl/matplotlib/matplotlib-renderer.ts +1 -0
@@ -0,0 +1,241 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+ import { render } from "@testing-library/react";
3
+ import { createStore, Provider } from "jotai";
4
+ import { beforeAll, describe, expect, it } from "vitest";
5
+ import { SetupMocks } from "@/__mocks__/common";
6
+ import { MockNotebook } from "@/__mocks__/notebook";
7
+ import { MockRequestClient } from "@/__mocks__/requests";
8
+ import { cellId } from "@/__tests__/branded";
9
+ import { TooltipProvider } from "@/components/ui/tooltip";
10
+ import { notebookAtom } from "@/core/cells/cells";
11
+ import type { CellRuntimeState } from "@/core/cells/types";
12
+ import { createCellRuntimeState } from "@/core/cells/types";
13
+ import { defaultUserConfig } from "@/core/config/config-schema";
14
+ import type { AppMode } from "@/core/mode";
15
+ import { requestClientAtom } from "@/core/network/requests";
16
+ import { Cell } from "../notebook-cell";
17
+
18
+ const cid = cellId("test");
19
+
20
+ function createTestWrapper() {
21
+ const store = createStore();
22
+ store.set(requestClientAtom, MockRequestClient.create());
23
+ const wrapper = ({ children }: { children: React.ReactNode }) => (
24
+ <Provider store={store}>{children}</Provider>
25
+ );
26
+ return { wrapper, store };
27
+ }
28
+
29
+ function seedNotebook(
30
+ store: ReturnType<typeof createStore>,
31
+ runtimeOverrides: Partial<CellRuntimeState> = {},
32
+ ) {
33
+ const notebook = MockNotebook.notebookState({
34
+ cellData: {
35
+ [cid]: {
36
+ code: "1 + 1",
37
+ name: "test_cell",
38
+ edited: false,
39
+ serializedEditorState: null,
40
+ config: {
41
+ disabled: false,
42
+ hide_code: false,
43
+ column: null,
44
+ },
45
+ },
46
+ },
47
+ });
48
+ notebook.cellRuntime[cid] = createCellRuntimeState({
49
+ status: "idle",
50
+ output: {
51
+ channel: "output",
52
+ mimetype: "text/html",
53
+ data: "<span>persist me</span>",
54
+ timestamp: 0,
55
+ },
56
+ ...runtimeOverrides,
57
+ });
58
+ store.set(notebookAtom, notebook);
59
+ }
60
+
61
+ function renderCell(mode: AppMode) {
62
+ return (
63
+ <TooltipProvider>
64
+ <Cell
65
+ cellId={cid}
66
+ mode={mode}
67
+ canDelete={true}
68
+ userConfig={defaultUserConfig()}
69
+ isCollapsed={false}
70
+ collapseCount={0}
71
+ canMoveX={false}
72
+ theme="light"
73
+ showPlaceholder={false}
74
+ />
75
+ </TooltipProvider>
76
+ );
77
+ }
78
+
79
+ beforeAll(() => {
80
+ SetupMocks.resizeObserver();
81
+ global.HTMLDivElement.prototype.scrollIntoView = () => {
82
+ // do nothing
83
+ };
84
+ });
85
+
86
+ describe("output persistence across mode changes", () => {
87
+ it("preserves the output DOM node when toggling edit <-> present", () => {
88
+ const { store, wrapper } = createTestWrapper();
89
+ seedNotebook(store);
90
+
91
+ const { container, rerender } = render(renderCell("edit"), { wrapper });
92
+
93
+ const outputNode = container.querySelector<HTMLElement>(
94
+ '[data-cell-role="output"]',
95
+ );
96
+ expect(outputNode).toBeTruthy();
97
+ // A property survives only if the exact DOM node instance survives.
98
+ (outputNode as HTMLElement & { __sentinel?: string }).__sentinel = "alive";
99
+
100
+ rerender(renderCell("present"));
101
+ const presentNode = container.querySelector<HTMLElement>(
102
+ '[data-cell-role="output"]',
103
+ );
104
+ expect(presentNode).toBe(outputNode);
105
+ expect(presentNode?.isConnected).toBe(true);
106
+ expect(
107
+ (presentNode as HTMLElement & { __sentinel?: string }).__sentinel,
108
+ ).toBe("alive");
109
+
110
+ // Edit chrome is hidden but stays mounted while presenting
111
+ const tray = container.querySelector<HTMLElement>(
112
+ "[data-testid='cell-tray']",
113
+ );
114
+ expect(tray).toBeTruthy();
115
+ expect(tray?.hidden).toBe(true);
116
+ // Present styling is applied
117
+ expect(
118
+ container
119
+ .querySelector(`[data-cell-id="${cid}"]`)
120
+ ?.classList.contains("published"),
121
+ ).toBe(true);
122
+
123
+ rerender(renderCell("edit"));
124
+ expect(container.querySelector('[data-cell-role="output"]')).toBe(
125
+ outputNode,
126
+ );
127
+ expect(
128
+ container.querySelector<HTMLElement>("[data-testid='cell-tray']")?.hidden,
129
+ ).toBe(false);
130
+ expect(
131
+ container
132
+ .querySelector(`[data-cell-id="${cid}"]`)
133
+ ?.classList.contains("published"),
134
+ ).toBe(false);
135
+ });
136
+
137
+ it("hides all edit chrome while presenting", () => {
138
+ const { store, wrapper } = createTestWrapper();
139
+ seedNotebook(store);
140
+
141
+ const { container, rerender } = render(renderCell("edit"), { wrapper });
142
+
143
+ // Returns true when the element is not visible: either gone from the DOM or
144
+ // inside a `hidden` ancestor. Edit chrome may unmount while presenting (only
145
+ // the cell *output* is contractually kept mounted — see the DOM-node test
146
+ // above); either way it must not be visible.
147
+ const isHidden = (testId: string) => {
148
+ const el = container.querySelector(`[data-testid='${testId}']`);
149
+ return el === null || el.closest("[hidden]") !== null;
150
+ };
151
+
152
+ // Everything visible in edit mode
153
+ const editChrome = [
154
+ "cell-tray",
155
+ "drag-button",
156
+ "cell-actions-button",
157
+ "delete-button",
158
+ "create-cell-button",
159
+ "console-output-area",
160
+ ];
161
+ for (const testId of editChrome) {
162
+ expect({ testId, hidden: isHidden(testId) }).toEqual({
163
+ testId,
164
+ hidden: false,
165
+ });
166
+ }
167
+
168
+ rerender(renderCell("present"));
169
+ for (const testId of editChrome) {
170
+ expect({ testId, hidden: isHidden(testId) }).toEqual({
171
+ testId,
172
+ hidden: true,
173
+ });
174
+ }
175
+
176
+ rerender(renderCell("edit"));
177
+ for (const testId of editChrome) {
178
+ expect({ testId, hidden: isHidden(testId) }).toEqual({
179
+ testId,
180
+ hidden: false,
181
+ });
182
+ }
183
+ });
184
+
185
+ it("does not dim edited-but-not-run outputs as stale while presenting", () => {
186
+ const { store, wrapper } = createTestWrapper();
187
+ seedNotebook(store);
188
+ // Mark the cell as edited without re-running it
189
+ const notebook = store.get(notebookAtom);
190
+ notebook.cellData[cid] = { ...notebook.cellData[cid], edited: true };
191
+ store.set(notebookAtom, { ...notebook });
192
+
193
+ const { container, rerender } = render(renderCell("edit"), { wrapper });
194
+ expect(container.querySelector(".marimo-output-stale")).toBeTruthy();
195
+
196
+ // The read view never dims pending edits; present mode matches it
197
+ rerender(renderCell("present"));
198
+ expect(container.querySelector(".marimo-output-stale")).toBeFalsy();
199
+
200
+ rerender(renderCell("edit"));
201
+ expect(container.querySelector(".marimo-output-stale")).toBeTruthy();
202
+ });
203
+
204
+ it("hides errored cells while presenting without unmounting them", () => {
205
+ const { store, wrapper } = createTestWrapper();
206
+ seedNotebook(store, {
207
+ errored: true,
208
+ output: {
209
+ channel: "marimo-error",
210
+ mimetype: "application/vnd.marimo+error",
211
+ data: [{ type: "exception", exception_type: "ValueError", msg: "!" }],
212
+ timestamp: 0,
213
+ },
214
+ });
215
+
216
+ const { container, rerender } = render(renderCell("edit"), { wrapper });
217
+
218
+ const outputNode = container.querySelector<HTMLElement>(
219
+ '[data-cell-role="output"]',
220
+ );
221
+ expect(outputNode).toBeTruthy();
222
+
223
+ const getSortableWrapper = () =>
224
+ container.querySelector<HTMLElement>(`[data-cell-id="${cid}"]`)
225
+ ?.parentElement;
226
+ expect(getSortableWrapper()?.hidden).toBe(false);
227
+
228
+ rerender(renderCell("present"));
229
+ // Still mounted, but hidden
230
+ expect(container.querySelector('[data-cell-role="output"]')).toBe(
231
+ outputNode,
232
+ );
233
+ expect(getSortableWrapper()?.hidden).toBe(true);
234
+
235
+ rerender(renderCell("edit"));
236
+ expect(container.querySelector('[data-cell-role="output"]')).toBe(
237
+ outputNode,
238
+ );
239
+ expect(getSortableWrapper()?.hidden).toBe(false);
240
+ });
241
+ });
@@ -0,0 +1,153 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { afterEach, describe, expect, it, vi } from "vitest";
4
+ import {
5
+ type ConnectionInfo,
6
+ getMarimoCommand,
7
+ getRawPrompt,
8
+ getTerminalCommand,
9
+ maskToken,
10
+ shellQuote,
11
+ } from "../pair-with-agent-commands";
12
+
13
+ const CONNECTION: ConnectionInfo = {
14
+ url: "http://localhost:8000",
15
+ sessionId: "s_ab12cd",
16
+ };
17
+
18
+ describe("shellQuote", () => {
19
+ it("quotes an empty string", () => {
20
+ expect(shellQuote("")).toBe("''");
21
+ });
22
+
23
+ it("leaves shell-safe values untouched", () => {
24
+ expect(shellQuote("http://localhost:8000")).toBe("http://localhost:8000");
25
+ expect(shellQuote("s_ab12cd")).toBe("s_ab12cd");
26
+ });
27
+
28
+ it("quotes values with shell metacharacters", () => {
29
+ expect(shellQuote("http://host:8000?a=1&b=2")).toBe(
30
+ "'http://host:8000?a=1&b=2'",
31
+ );
32
+ expect(shellQuote("has space")).toBe("'has space'");
33
+ expect(shellQuote("$(rm -rf /)")).toBe("'$(rm -rf /)'");
34
+ });
35
+
36
+ it("escapes embedded single quotes without breaking out", () => {
37
+ // Closes the quote, emits a literal ' via "'", then reopens: '"'"'
38
+ expect(shellQuote("a'b")).toBe(`'a'"'"'b'`);
39
+ });
40
+ });
41
+
42
+ describe("getMarimoCommand", () => {
43
+ afterEach(() => {
44
+ vi.unstubAllEnvs();
45
+ });
46
+
47
+ it("uses the local checkout in dev", () => {
48
+ vi.stubEnv("DEV", true);
49
+ expect(getMarimoCommand()).toBe("uv run marimo");
50
+ });
51
+
52
+ it("uses uvx outside of dev", () => {
53
+ vi.stubEnv("DEV", false);
54
+ expect(getMarimoCommand()).toBe("uvx marimo@latest");
55
+ });
56
+ });
57
+
58
+ describe("getTerminalCommand", () => {
59
+ it("includes the url and session for each agent", () => {
60
+ expect(getTerminalCommand("claude", CONNECTION, false)).toBe(
61
+ `claude "$(uv run marimo pair prompt --url http://localhost:8000 --session s_ab12cd --claude)"`,
62
+ );
63
+ expect(getTerminalCommand("codex", CONNECTION, false)).toBe(
64
+ `codex "$(uv run marimo pair prompt --url http://localhost:8000 --session s_ab12cd --codex)"`,
65
+ );
66
+ expect(getTerminalCommand("opencode", CONNECTION, false)).toBe(
67
+ `opencode --prompt "$(uv run marimo pair prompt --url http://localhost:8000 --session s_ab12cd --opencode)"`,
68
+ );
69
+ });
70
+
71
+ it("always targets the given session, not a random one", () => {
72
+ const command = getTerminalCommand("claude", CONNECTION, false);
73
+ expect(command).toContain("--session s_ab12cd");
74
+ });
75
+
76
+ it("shell-escapes a url containing metacharacters", () => {
77
+ const command = getTerminalCommand(
78
+ "claude",
79
+ { url: "http://host:8000?file=a&b", sessionId: "s_ab12cd" },
80
+ false,
81
+ );
82
+ expect(command).toContain("--url 'http://host:8000?file=a&b'");
83
+ });
84
+
85
+ it("adds --with-token before the agent flag when requested", () => {
86
+ const command = getTerminalCommand("claude", CONNECTION, true);
87
+ expect(command).toContain("--with-token --claude");
88
+ });
89
+
90
+ it("omits --with-token when not requested", () => {
91
+ expect(getTerminalCommand("claude", CONNECTION, false)).not.toContain(
92
+ "--with-token",
93
+ );
94
+ });
95
+ });
96
+
97
+ describe("getRawPrompt", () => {
98
+ it("references the session-scoped execute-code command", () => {
99
+ const prompt = getRawPrompt(CONNECTION, null);
100
+ expect(prompt).toContain(
101
+ "execute-code.sh --url http://localhost:8000 --session s_ab12cd",
102
+ );
103
+ expect(prompt).toContain(
104
+ "Connect to the notebook at: http://localhost:8000 (session s_ab12cd)",
105
+ );
106
+ });
107
+
108
+ it("omits the token hint when there is no token", () => {
109
+ const prompt = getRawPrompt(CONNECTION, null);
110
+ expect(prompt).not.toContain("--token");
111
+ expect(prompt).not.toContain("auth token");
112
+ });
113
+
114
+ it("includes a session-scoped token hint when a token is present", () => {
115
+ const prompt = getRawPrompt(CONNECTION, "secret-token");
116
+ expect(prompt).toContain(
117
+ "execute-code.sh --url http://localhost:8000 --session s_ab12cd --token secret-token",
118
+ );
119
+ });
120
+
121
+ it("shell-escapes a token containing a single quote", () => {
122
+ const prompt = getRawPrompt(CONNECTION, "tok'en");
123
+ expect(prompt).toContain(`--token 'tok'"'"'en'`);
124
+ });
125
+
126
+ it("matches the CLI prompt shape", () => {
127
+ const prompt = getRawPrompt(CONNECTION, null);
128
+ expect(prompt).toMatchInlineSnapshot(`
129
+ "Use the /marimo-pair skill to pair-program on a running marimo notebook.
130
+
131
+ Connect to the notebook at: http://localhost:8000 (session s_ab12cd)
132
+
133
+ Use \`execute-code.sh --url http://localhost:8000 --session s_ab12cd\` from the marimo-pair skill to execute code in the notebook.
134
+
135
+ Once you are connected, send a fun toast (mo.status.toast(...)) to the user inside marimo letting them know you're ready to pair."
136
+ `);
137
+ });
138
+ });
139
+
140
+ describe("maskToken", () => {
141
+ it("masks short tokens entirely", () => {
142
+ expect(maskToken("ab")).toBe("****");
143
+ expect(maskToken("abcd")).toBe("****");
144
+ });
145
+
146
+ it("reveals only the last four characters", () => {
147
+ expect(maskToken("abcdefgh")).toBe("****efgh");
148
+ });
149
+
150
+ it("caps the number of mask characters at eight", () => {
151
+ expect(maskToken("0123456789abcdef")).toBe("********cdef");
152
+ });
153
+ });
@@ -0,0 +1,109 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { assertNever } from "@/utils/assertNever";
4
+
5
+ export type AgentTab = "claude" | "codex" | "opencode" | "prompt";
6
+
7
+ export const TERMINAL_TABS = ["claude", "codex", "opencode"] as const;
8
+
9
+ export const AGENT_TABS = ["claude", "codex", "opencode", "prompt"] as const;
10
+
11
+ export const AGENT_LABELS: Record<AgentTab, string> = {
12
+ claude: "Claude",
13
+ codex: "Codex",
14
+ opencode: "OpenCode",
15
+ prompt: "Prompt",
16
+ };
17
+
18
+ export const SKILL_INSTALL = "npx skills add marimo-team/marimo-pair";
19
+
20
+ /** How to invoke marimo: from the local checkout in dev, else via uvx. */
21
+ export function getMarimoCommand(): string {
22
+ return import.meta.env.DEV ? "uv run marimo" : "uvx marimo@latest";
23
+ }
24
+
25
+ /**
26
+ * POSIX-quote a value for safe embedding in a shell command. These commands are
27
+ * meant to be copied into a terminal, so a url/token containing shell
28
+ * metacharacters (`'`, `&`, `$(...)`, ...) must not break out of its argument.
29
+ *
30
+ * Mirrors Python's `shlex.quote` (used on the CLI side in
31
+ * `marimo/_cli/pair/commands.py`) so both sides produce identical commands:
32
+ * values that are already shell-safe are left as-is for readability, and
33
+ * anything else is single-quoted with embedded quotes escaped as `'"'"'`.
34
+ */
35
+ export function shellQuote(value: string): string {
36
+ if (value === "") {
37
+ return "''";
38
+ }
39
+ // Same "safe" character set as CPython's shlex.quote (ASCII \w plus a few).
40
+ if (/^[\w@%+=:,./-]+$/.test(value)) {
41
+ return value;
42
+ }
43
+ return `'${value.replaceAll("'", `'"'"'`)}'`;
44
+ }
45
+
46
+ /** Identifies the specific running notebook to pair on. */
47
+ export interface ConnectionInfo {
48
+ url: string;
49
+ /**
50
+ * The current session id, so agents connect to *this* notebook rather than
51
+ * guessing when multiple sessions are open on the same server.
52
+ */
53
+ sessionId: string;
54
+ }
55
+
56
+ /**
57
+ * The shell command that wraps an agent CLI, delegating prompt generation to
58
+ * `marimo pair prompt` so the terminal and CLI stay in sync.
59
+ */
60
+ export function getTerminalCommand(
61
+ agent: Exclude<AgentTab, "prompt">,
62
+ { url, sessionId }: ConnectionInfo,
63
+ withToken: boolean,
64
+ ): string {
65
+ const tokenFlag = withToken ? " --with-token" : "";
66
+ const base = `${getMarimoCommand()} pair prompt --url ${shellQuote(url)} --session ${shellQuote(sessionId)}${tokenFlag}`;
67
+ switch (agent) {
68
+ case "claude":
69
+ return `claude "$(${base} --claude)"`;
70
+ case "codex":
71
+ return `codex "$(${base} --codex)"`;
72
+ case "opencode":
73
+ return `opencode --prompt "$(${base} --opencode)"`;
74
+ default:
75
+ assertNever(agent);
76
+ }
77
+ }
78
+
79
+ /**
80
+ * The raw prompt for the "Prompt" tab. Mirrors the output of
81
+ * `marimo pair prompt` (see `marimo/_cli/pair/commands.py`) so pasting it into
82
+ * an agent behaves the same as the terminal commands.
83
+ */
84
+ export function getRawPrompt(
85
+ { url, sessionId }: ConnectionInfo,
86
+ token: string | null,
87
+ ): string {
88
+ const executeCmd = `execute-code.sh --url ${shellQuote(url)} --session ${shellQuote(sessionId)}`;
89
+ const tokenHint = token
90
+ ? `\n\nUse this auth token when calling \`execute-code.sh\`: \`${executeCmd} --token ${shellQuote(token)}\`.`
91
+ : "";
92
+ return [
93
+ "Use the /marimo-pair skill to pair-program on a running marimo notebook.",
94
+ "",
95
+ `Connect to the notebook at: ${url} (session ${sessionId})`,
96
+ "",
97
+ `Use \`${executeCmd}\` from the marimo-pair skill to execute code in the notebook.${tokenHint}`,
98
+ "",
99
+ "Once you are connected, send a fun toast (mo.status.toast(...)) to the user inside marimo letting them know you're ready to pair.",
100
+ ].join("\n");
101
+ }
102
+
103
+ /** Mask all but the last 4 chars of a token for display. */
104
+ export function maskToken(token: string): string {
105
+ if (token.length <= 4) {
106
+ return "****";
107
+ }
108
+ return `${"*".repeat(Math.min(token.length - 4, 8))}${token.slice(-4)}`;
109
+ }
@@ -14,67 +14,20 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
14
14
  import { copyToClipboard } from "@/utils/copy";
15
15
  import { Events } from "@/utils/events";
16
16
  import { Tooltip } from "@/components/ui/tooltip";
17
- import { assertNever } from "@/utils/assertNever";
18
17
  import { asRemoteURL, useRuntimeManager } from "@/core/runtime/config";
19
18
  import { API } from "@/core/network/api";
20
-
21
- type AgentTab = "claude" | "codex" | "opencode" | "prompt";
22
-
23
- const TERMINAL_TABS = ["claude", "codex", "opencode"] as const;
24
-
25
- function getMarimoCommand(): string {
26
- return import.meta.env.DEV ? "uv run marimo" : "uvx marimo@latest";
27
- }
28
-
29
- function getTerminalCommand(
30
- agent: Exclude<AgentTab, "prompt">,
31
- url: string,
32
- withToken: boolean,
33
- ): string {
34
- const tokenFlag = withToken ? " --with-token" : "";
35
- const base = `${getMarimoCommand()} pair prompt --url '${url}'${tokenFlag}`;
36
- switch (agent) {
37
- case "claude":
38
- return `claude "$(${base} --claude)"`;
39
- case "codex":
40
- return `codex "$(${base} --codex)"`;
41
- case "opencode":
42
- return `opencode --prompt "$(${base} --opencode)"`;
43
- default:
44
- assertNever(agent);
45
- }
46
- }
47
-
48
- function getRawPrompt(url: string, token: string | null): string {
49
- const tokenHint = token
50
- ? `\n\nUse this auth token when calling \`execute-code.sh\`: \`execute-code.sh --url '${url}' --token '${token}'\`.`
51
- : "";
52
- return [
53
- "Use the /marimo-pair skill to pair-program on a running marimo notebook.",
54
- "",
55
- `Connect to the notebook at: ${url}`,
56
- "",
57
- `Use \`execute-code.sh --url ${url}\` from the marimo-pair skill to execute code in the notebook.${tokenHint}`,
58
- "",
59
- "Once you are connected, send a fun toast (mo.status.toast(...)) to the user inside marimo letting them know you're ready to pair.",
60
- ].join("\n");
61
- }
62
-
63
- function maskToken(token: string): string {
64
- if (token.length <= 4) {
65
- return "****";
66
- }
67
- return `${"*".repeat(Math.min(token.length - 4, 8))}${token.slice(-4)}`;
68
- }
69
-
70
- const SKILL_INSTALL = "npx skills add marimo-team/marimo-pair";
71
-
72
- const AGENT_LABELS: Record<AgentTab, string> = {
73
- claude: "Claude",
74
- codex: "Codex",
75
- opencode: "OpenCode",
76
- prompt: "Prompt",
77
- };
19
+ import { getSessionId } from "@/core/kernel/session";
20
+ import {
21
+ AGENT_LABELS,
22
+ AGENT_TABS,
23
+ type AgentTab,
24
+ type ConnectionInfo,
25
+ getRawPrompt,
26
+ getTerminalCommand,
27
+ maskToken,
28
+ SKILL_INSTALL,
29
+ TERMINAL_TABS,
30
+ } from "./pair-with-agent-commands";
78
31
 
79
32
  function useAuthToken(): string | null {
80
33
  const [token, setToken] = useState<string | null>(null);
@@ -98,7 +51,10 @@ export const PairWithAgentModal: React.FC<{
98
51
  const runtimeManager = useRuntimeManager();
99
52
  const authToken = useAuthToken();
100
53
  const hasToken = Boolean(authToken);
101
- const remoteUrl = runtimeManager.httpURL.toString();
54
+ const connection: ConnectionInfo = {
55
+ url: runtimeManager.httpURL.toString(),
56
+ sessionId: getSessionId(),
57
+ };
102
58
 
103
59
  return (
104
60
  <DialogContent className="sm:max-w-2xl">
@@ -125,7 +81,7 @@ export const PairWithAgentModal: React.FC<{
125
81
  onValueChange={(v) => setActiveTab(v as AgentTab)}
126
82
  >
127
83
  <TabsList className="w-full">
128
- {(["claude", "codex", "opencode", "prompt"] as const).map((tab) => (
84
+ {AGENT_TABS.map((tab) => (
129
85
  <TabsTrigger key={tab} value={tab} className="flex-1">
130
86
  {AGENT_LABELS[tab]}
131
87
  </TabsTrigger>
@@ -147,7 +103,7 @@ export const PairWithAgentModal: React.FC<{
147
103
  </Step>
148
104
  <Step index={2} title="Run in your terminal">
149
105
  <CommandBlock
150
- command={getTerminalCommand(tab, remoteUrl, hasToken)}
106
+ command={getTerminalCommand(tab, connection, hasToken)}
151
107
  />
152
108
  </Step>
153
109
  {hasToken && authToken && (
@@ -179,9 +135,9 @@ export const PairWithAgentModal: React.FC<{
179
135
  }
180
136
  >
181
137
  <CommandBlock
182
- command={getRawPrompt(remoteUrl, authToken)}
138
+ command={getRawPrompt(connection, authToken)}
183
139
  display={getRawPrompt(
184
- remoteUrl,
140
+ connection,
185
141
  authToken ? maskToken(authToken) : null,
186
142
  )}
187
143
  multiline={true}
@@ -39,12 +39,18 @@ interface Props extends Pick<
39
39
  "cellId" | "getEditorView"
40
40
  > {
41
41
  children: React.ReactNode;
42
+ /**
43
+ * If true, the custom context menu is disabled and the native one is used
44
+ * (e.g. while presenting).
45
+ */
46
+ disabled?: boolean;
42
47
  }
43
48
 
44
49
  export const CellActionsContextMenu = ({
45
50
  children,
46
51
  cellId,
47
52
  getEditorView,
53
+ disabled,
48
54
  }: Props) => {
49
55
  const cellData = useCellData(cellId);
50
56
  const cellRuntime = useCellRuntime(cellId);
@@ -187,6 +193,7 @@ export const CellActionsContextMenu = ({
187
193
  return (
188
194
  <ContextMenu>
189
195
  <ContextMenuTrigger
196
+ disabled={disabled}
190
197
  onContextMenu={(evt) => {
191
198
  if (evt.target instanceof HTMLImageElement) {
192
199
  setImageRightClicked(evt.target);
@@ -303,6 +303,16 @@ const PackagesList: React.FC<{
303
303
  onSuccess: () => void;
304
304
  packages: { name: string; version: string }[];
305
305
  }> = ({ onSuccess, packages }) => {
306
+ // Sort case-insensitively so packages are strictly alphabetical
307
+ // regardless of capitalization (package managers sort inconsistently).
308
+ const sortedPackages = React.useMemo(
309
+ () =>
310
+ packages.toSorted((a, b) =>
311
+ a.name.localeCompare(b.name, undefined, { sensitivity: "base" }),
312
+ ),
313
+ [packages],
314
+ );
315
+
306
316
  if (packages.length === 0) {
307
317
  return (
308
318
  <PanelEmptyState
@@ -323,7 +333,7 @@ const PackagesList: React.FC<{
323
333
  </TableRow>
324
334
  </TableHeader>
325
335
  <TableBody>
326
- {packages.map((item) => (
336
+ {sortedPackages.map((item) => (
327
337
  <TableRow
328
338
  key={item.name}
329
339
  className="group"