Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

break: remove marimo new PROMPT (#11629)

Akshay Agrawal3d14c1d23433
diff --git a/docs/vercel.json b/docs/vercel.json
index ab3290876f..f197db1f82 100644
--- a/docs/vercel.json
+++ b/docs/vercel.json
@@ -717,7 +717,7 @@
},
{
"source": "/guides/generate_with_ai/text_to_notebook/",
- "destination": "/cli/#marimo-new",
+ "destination": "/guides/generate_with_ai/",
"permanent": true
},
{
diff --git a/marimo/_ai/text_to_notebook.py b/marimo/_ai/text_to_notebook.py
deleted file mode 100644
index e2b394897b..0000000000
--- a/marimo/_ai/text_to_notebook.py
+++ /dev/null
@@ -1,100 +0,0 @@
-# Copyright 2026 Marimo. All rights reserved.
-from __future__ import annotations
-
-import datetime
-import urllib.parse
-
-from marimo._cli.print import bold, green, muted
-from marimo._config.cli_state import (
- get_cli_state,
- write_cli_state,
-)
-from marimo._utils import requests
-from marimo._utils.print import print_
-
-TERMS = """
-Before using marimo's Text-To-Notebook AI feature, you should know:
-
-1. Your prompt will be sent to marimo's API at `https://ai.marimo.app/`
-2. The API uses OpenAI/Anthropic's models to convert your prompt into a notebook
-3. Your prompt is securely stored for caching purposes (fast response times)
-4. No personal data beyond the prompt itself is collected
-5. You can revoke consent at any time by modifying ~/.marimo/state.toml
-"""
-
-TERMS_LAST_UPDATED = datetime.date(2025, 4, 1)
-
-
-def text_to_notebook(prompt: str) -> str:
- """
- Generate a notebook from a text prompt.
-
- Args:
- prompt: The text prompt to generate a notebook from.
-
- Returns:
- The generated notebook as a string.
-
- Raises:
- ValueError: If the user has not accepted the terms.
- RuntimeError: If the API request fails.
- """
- # Check if the user has accepted the terms
- state = get_cli_state()
- if not state:
- raise RuntimeError(
- "Failed to get CLI configuration at ~/.marimo/state.toml"
- )
-
- if _should_show_terms(state.accepted_text_to_notebook_terms_at):
- # User hasn't accepted terms
- print_(bold(TERMS))
- print_(bold("Do you accept these terms? (y/N)"))
-
- response = input().strip().lower()
- if response != "y":
- raise ValueError("Terms not accepted.")
-
- # Update state with acceptance
- today = datetime.datetime.now().date().strftime("%Y-%m-%d")
- state.accepted_text_to_notebook_terms_at = today
-
- write_cli_state(state)
-
- # Call the API
- try:
- url = f"https://ai.marimo.app/api/notebook.py?prompt={urllib.parse.quote(prompt)}"
- print_(muted("Generating notebook this may take a few seconds..."))
-
- # Create a request with a proper User-Agent header
- headers = {"User-Agent": requests.MARIMO_USER_AGENT}
- result = requests.get(url, headers=headers).raise_for_status().text()
-
- print_(green("Notebook generated successfully."))
-
- # Check if the response is valid
- if "marimo.App" not in result:
- raise RuntimeError(
- "Invalid response from API: missing 'marimo.App' key"
- )
-
- return result
-
- except Exception as e:
- raise RuntimeError(f"Failed to generate notebook: {e!s}") from e
-
-
-def _should_show_terms(last_accepted_at: str | None) -> bool:
- """
- Determine if the terms should be shown to the user.
-
- Args:
- last_accepted_at (Optional[str]): The date the user last accepted the terms.
-
- Returns:
- bool: Whether the terms should be shown to the user.
- """
- if not last_accepted_at:
- return True
- last_accepted_date = datetime.date.fromisoformat(last_accepted_at)
- return last_accepted_date < TERMS_LAST_UPDATED
diff --git a/marimo/_cli/cli.py b/marimo/_cli/cli.py
index bbba663061..508d9d7cab 100644
--- a/marimo/_cli/cli.py
+++ b/marimo/_cli/cli.py
@@ -1,7 +1,6 @@
# Copyright 2026 Marimo. All rights reserved.
from __future__ import annotations
-import atexit
import json
import os
import shutil
@@ -637,41 +636,7 @@ def edit(
)
-# To make this more readable at 80 character terminal width, the bullet
-# that overflows is moved to the end, and _key_value_bullets is called
-# twice.
-new_help_msg = "\n".join(
- [
- "\b",
- "Create an empty notebook, or generate from a prompt with AI",
- "",
- _key_value_bullets(
- [
- (
- "marimo new",
- "Create an empty notebook",
- ),
- (
- "marimo new prompt.txt",
- "Generate a notebook from a prompt in a file.",
- ),
- ]
- ),
- _key_value_bullets(
- [
- (
- 'marimo new "Plot an interactive 3D surface with matplotlib."',
- "Generate a notebook from a prompt.",
- ),
- ]
- ),
- "",
- "Visit https://marimo.app/ai for more prompt examples.",
- ]
-)
-
-
[email protected](cls=SandboxCommand, help=new_help_msg)
[email protected](cls=SandboxCommand, help="Create an empty notebook.")
@click.option(
"-p",
"--port",
@@ -750,7 +715,6 @@ new_help_msg = "\n".join(
type=float,
help="Enable a global timeout to shut down the server after specified number of minutes of no connection",
)
[email protected]("prompt", required=False)
def new(
port: int | None,
host: str,
@@ -764,68 +728,16 @@ def new(
no_sandbox: bool,
skew_protection: bool,
timeout: float | None,
- prompt: str | None,
) -> None:
from marimo._cli.sandbox import ensure_server_environment, resolve_sandbox
sandbox_backend = resolve_sandbox(sandbox, no_sandbox, name=None)
ensure_server_environment(sandbox_backend)
- workspace: NotebookWorkspace | None = None
-
- if prompt is None:
- # We support unix-style prompting, cat prompt.txt | marimo new
- prompt = _get_stdin_contents()
-
- if prompt is not None:
- import tempfile
-
- from marimo._ai.text_to_notebook import text_to_notebook
-
- try:
- _maybe_path = Path(prompt)
- if _maybe_path.is_file():
- prompt = _maybe_path.read_text(encoding="utf-8")
- except OSError:
- # is_file() fails when, for example, the "filename" (prompt) is too long
- pass
-
- temp_file = None
- try:
- notebook_content = text_to_notebook(prompt)
- # On Windows, NamedTemporaryFile cannot be reopened unless
- # delete=False.
- with tempfile.NamedTemporaryFile(
- suffix=".py", mode="w", encoding="utf-8", delete=False
- ) as temp_file:
- temp_file.write(notebook_content)
- workspace = infer_workspace(temp_file.name)
-
- def _cleanup() -> None:
- try:
- os.unlink(temp_file.name)
- except Exception:
- pass
-
- atexit.register(_cleanup)
- except Exception as e:
- if temp_file is not None:
- try:
- os.unlink(temp_file.name)
- except Exception:
- pass
-
- raise click.ClickException(
- f"Failed to generate notebook: {e!s}"
- ) from e
-
- if workspace is None:
- workspace = EmptyWorkspace()
-
base_url = validators.check_proxy_base_url(proxy, base_url)
start(
- workspace=workspace,
+ workspace=EmptyWorkspace(),
development_mode=GLOBAL_SETTINGS.DEVELOPMENT_MODE,
quiet=GLOBAL_SETTINGS.QUIET,
host=host,
diff --git a/marimo/_config/cli_state.py b/marimo/_config/cli_state.py
index d68db62614..239dd7eea0 100644
--- a/marimo/_config/cli_state.py
+++ b/marimo/_config/cli_state.py
@@ -10,7 +10,6 @@ from marimo._utils.config.config import ConfigReader
class MarimoCLIState:
latest_version: str | None = None
last_checked_at: str | None = None
- accepted_text_to_notebook_terms_at: str | None = None
notices: list[str] | None = None
diff --git a/tests/_cli/test_cli.py b/tests/_cli/test_cli.py
index d8e01c61b7..3a549a434d 100644
--- a/tests/_cli/test_cli.py
+++ b/tests/_cli/test_cli.py
@@ -40,6 +40,7 @@ from marimo._config.manager import get_default_config_manager
from marimo._dependencies.dependencies import DependencyManager
from marimo._server.workspace import (
DirectoryWorkspace,
+ EmptyWorkspace,
FixedFilesWorkspace,
)
from marimo._templates import get_version
@@ -867,6 +868,28 @@ def test_cli_edit_skip_update_check(tmp_path: Path) -> None:
)
[email protected]("stdin", ["", "Plot a sine wave"])
+def test_cli_new_creates_empty_notebook(stdin: str) -> None:
+ with patch("marimo._cli.cli.start") as start:
+ result = CliRunner().invoke(
+ cli_main, ["new", "--no-sandbox", "--headless"], input=stdin
+ )
+
+ assert result.exit_code == 0, result.output
+ start.assert_called_once()
+ assert isinstance(start.call_args.kwargs["workspace"], EmptyWorkspace)
+
+
[email protected]("prompt", ["Plot a sine wave", "prompt.txt"])
+def test_cli_new_rejects_prompt(prompt: str) -> None:
+ with patch("marimo._cli.cli.start") as start:
+ result = CliRunner().invoke(cli_main, ["new", prompt])
+
+ assert result.exit_code == 2
+ assert "unexpected extra argument" in result.output.lower()
+ start.assert_not_called()
+
+
def test_cli_new() -> None:
port = _get_port()
p = subprocess.Popen(