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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
improvement: show better diff for ACP (#6828)
Myles Scolnickb3c17cd86603
diff --git a/frontend/package.json b/frontend/package.jsonindex 1f383482fb..525312a345 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -28,6 +28,7 @@"@codemirror/language-data": "^6.5.1","@codemirror/legacy-modes": "^6.5.2","@codemirror/lint": "^6.9.0",+ "@codemirror/merge": "^6.11.0","@codemirror/search": "^6.5.11","@codemirror/state": "^6.5.2","@codemirror/theme-one-dark": "^6.1.3",@@ -55,8 +56,8 @@"@marimo-team/codemirror-sql": "^0.2.3","@marimo-team/llm-info": "workspace:*","@marimo-team/marimo-api": "workspace:*",- "@marimo-team/smart-cells": "workspace:*","@marimo-team/react-slotz": "^0.2.0",+ "@marimo-team/smart-cells": "workspace:*","@mui/material": "^6.5.0","@open-rpc/client-js": "^1.8.1","@paralleldrive/cuid2": "^2.2.2",diff --git a/frontend/src/components/chat/acp/blocks.tsx b/frontend/src/components/chat/acp/blocks.tsxindex 4b49279539..3fcdea8d76 100644--- a/frontend/src/components/chat/acp/blocks.tsx+++ b/frontend/src/components/chat/acp/blocks.tsx@@ -1,4 +1,5 @@/* Copyright 2024 Marimo. All rights reserved. */+import type {ContentBlock,ToolCallContent,@@ -22,6 +23,7 @@ import {} from "lucide-react";import React from "react";import { mergeToolCalls } from "use-acp";+import { ReadonlyDiff } from "@/components/editor/code/readonly-diff";import { JsonOutput } from "@/components/editor/output/JsonOutput";import { Button } from "@/components/ui/button";import {@@ -584,42 +586,16 @@ export const DiffBlocks = (props: {return (<divkey={item.path}- className="border rounded-md overflow-hidden bg-[var(--gray-2)] max-h-64 overflow-y-auto scrollbar-thin"+ className="border rounded-md overflow-hidden bg-[var(--gray-2)] overflow-y-auto scrollbar-thin">{/* File path header */}<div className="px-2 py-1 bg-[var(--gray-2)] border-b text-xs font-medium text-[var(--gray-11)]">{item.path}</div>-- <div className="font-mono text-xs">- {/* Removed lines */}- {item.oldText && (- <div className="px-3 py-1 border-b bg-[var(--red-2)] border-b-[var(--red-6)]">- <div className="flex">- <span className="text-[var(--red-11)] select-none mr-2">- -- </span>- <pre className="text-[var(--red-11)] px-1 rounded whitespace-pre-wrap break-words flex-1 line-through opacity-80">- {item.oldText}- </pre>- </div>- </div>- )}-- {/* Added lines */}- {item.newText && (- <div className="px-3 py-1 bg-[var(--grass-2)] border-b-[var(--grass-6)]">- <div className="flex">- <span className="text-[var(--grass-11)] select-none mr-2">- +- </span>- <pre className="text-[var(--grass-11)] px-1 rounded whitespace-pre-wrap break-words flex-1 italic opacity-90">- {item.newText}- </pre>- </div>- </div>- )}- </div>+ <ReadonlyDiff+ original={item.oldText || ""}+ modified={item.newText || ""}+ /></div>);})}diff --git a/frontend/src/components/editor/code/readonly-diff.tsx b/frontend/src/components/editor/code/readonly-diff.tsxnew file mode 100644index 0000000000..eb653bb1c8--- /dev/null+++ b/frontend/src/components/editor/code/readonly-diff.tsx@@ -0,0 +1,48 @@+import { unifiedMergeView } from "@codemirror/merge";+import { EditorView } from "@codemirror/view";+import CodeMirror from "@uiw/react-codemirror";+import { memo, useMemo } from "react";+import { useTheme } from "@/theme/useTheme";++export const ReadonlyDiff = memo(+ (props: { original: string; modified: string }) => {+ const { theme } = useTheme();++ const extensions = useMemo(() => {+ return [+ EditorView.lineWrapping,+ unifiedMergeView({+ original: props.original,+ mergeControls: false,+ }),+ ];+ }, [props.original, props.modified, theme]);++ return (+ <CodeMirror+ className="cm font-mono"+ style={+ {+ "--marimo-code-editor-font-size": "10px",+ } as React.CSSProperties+ }+ extensions={extensions}+ readOnly={true}+ basicSetup={{+ lineNumbers: false,+ foldGutter: false,+ dropCursor: false,+ highlightActiveLineGutter: false,+ allowMultipleSelections: false,+ indentOnInput: false,+ bracketMatching: false,+ closeBrackets: false,+ autocompletion: false,+ }}+ theme={theme === "dark" ? "dark" : "light"}+ value={props.modified}+ />+ );+ },+);+ReadonlyDiff.displayName = "ReadonlyDiff";diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex ba1ce248a1..6a1c192893 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -69,6 +69,9 @@ importers:'@codemirror/lint':specifier: ^6.9.0version: 6.9.0+ '@codemirror/merge':+ specifier: ^6.11.0+ version: 6.11.0'@codemirror/search':specifier: ^6.5.11version: 6.5.11@@ -1148,8 +1151,8 @@ packages:'@codemirror/[email protected]':resolution: {integrity: sha512-wZxW+9XDytH3SKvS8cQzMyQCaaazH8XL1EMHleHe00wVzsv7NBQKVW2yzEHrRhmM7ZOhVdItPbvlRBvMp9ej7A==}- '@codemirror/[email protected]':- resolution: {integrity: sha512-rmHzVkt5FnCtsi0IgvDIDjh/J4LmbfOboB7FMvVl21IHO0p1QM6jSwjkBjBD3D+c+T79OabEqoduCqvJCBV8Yg==}+ '@codemirror/[email protected]':+ resolution: {integrity: sha512-Wu5Camx8u0jKA4yV3IxcWGMIoXUxuptsbWW9kTje8d/NInnnALeyQaxcVssJznp9FRnu4As3qsBhacERyB9p6w==}'@codemirror/[email protected]':resolution: {integrity: sha512-KmWepDE6jUdL6n8cAAqIpRmLPBZ5ZKnicE8oGU/s3QrAVID+0VhLFrzUucVKHG5035/BSykhExDL/Xm7dHthiA==}@@ -10848,7 +10851,7 @@ snapshots:'@codemirror/view': 6.38.5crelt: 1.0.6- '@codemirror/[email protected]':+ '@codemirror/[email protected]':dependencies:'@codemirror/language': 6.11.3'@codemirror/state': 6.5.2@@ -19466,7 +19469,7 @@ snapshots:[email protected](@babel/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])([email protected])([email protected]([email protected]))([email protected]):dependencies:'@babel/runtime': 7.27.6- '@codemirror/merge': 6.10.2+ '@codemirror/merge': 6.11.0'@codemirror/state': 6.5.2'@codemirror/theme-one-dark': 6.1.3'@codemirror/view': 6.38.5