Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
feat(agentic-ide): git change markers and language services in the editor
rubenluetke10-beepaac98a3bd86d
diff --git a/jarvis/ui/web/frontend/src/components/agentic/editor/EditorSurface.tsx b/jarvis/ui/web/frontend/src/components/agentic/editor/EditorSurface.tsxindex 9dabc62312..c385311127 100644--- a/jarvis/ui/web/frontend/src/components/agentic/editor/EditorSurface.tsx+++ b/jarvis/ui/web/frontend/src/components/agentic/editor/EditorSurface.tsx@@ -4,7 +4,8 @@ import { Loader2 } from "lucide-react";import { fill, useT } from "@/i18n";import { cn } from "@/lib/utils";import { useCodeEditorStore, type EditorTab } from "@/store/codeEditor";-import { languageFor, loadFile, loadHead, modelOf, rememberViewState, viewStateOf } from "./editorModels";+import { languageFor, loadFile, loadHead, loadHeadText, modelOf, rememberViewState, viewStateOf } from "./editorModels";+import { gutterChanges } from "./lineDiff";import { EDITOR_OPTIONS, applyTheme, monaco } from "./monacoRuntime";import { renderKindOf } from "./fileKinds";import { ExtractedPreview, MediaViewer, Notice, RenderedPreview } from "./FileViewers";@@ -118,6 +119,53 @@ export default function EditorSurface({editor.focus();}, [tab.key, tab.fileKey, tab.mode, ready]);+ // Gutter markers against the last commit: green added, blue modified, a red+ // notch where lines were deleted. Recomputed shortly after each edit.+ useEffect(() => {+ const editor = editorRef.current;+ const model = modelOf(tab.fileKey);+ if (tab.mode !== "edit" || !ready || !editor || !model) return;+ let alive = true;+ let base: string | null = null;+ let timer: number | undefined;+ const collection = editor.createDecorationsCollection();+ const paint = () => {+ if (!alive || base === null || editor.getModel() !== model) {+ collection.clear();+ return;+ }+ const lines = model.getLineCount();+ const changes = gutterChanges(base, model.getValue()) ?? [];+ collection.set(+ changes.map((change) => {+ const below = change.kind === "deleted" && change.start > lines;+ const start = Math.min(change.start, lines);+ return {+ range: new monaco.Range(start, 1, Math.min(change.end, lines), 1),+ options: {+ isWholeLine: true,+ linesDecorationsClassName: below ? "jarvis-gutter-deleted-below" : `jarvis-gutter-${change.kind}`,+ },+ };+ }),+ );+ };+ void loadHeadText(tab.fileKey).then((text) => {+ base = text;+ paint();+ });+ const listener = model.onDidChangeContent(() => {+ window.clearTimeout(timer);+ timer = window.setTimeout(paint, 250);+ });+ return () => {+ alive = false;+ window.clearTimeout(timer);+ listener.dispose();+ collection.clear();+ };+ }, [tab.key, tab.fileKey, tab.mode, ready]);+// Diff tabs: the committed text on the left, the live (editable) buffer on the right.useEffect(() => {if (tab.mode !== "diff" || !ready) return;diff --git a/jarvis/ui/web/frontend/src/components/agentic/editor/editorGutter.css b/jarvis/ui/web/frontend/src/components/agentic/editor/editorGutter.cssnew file mode 100644index 0000000000..704562ec76--- /dev/null+++ b/jarvis/ui/web/frontend/src/components/agentic/editor/editorGutter.css@@ -0,0 +1,26 @@+/* Gutter markers against the last commit (see lineDiff.ts), in theme colours. */+.monaco-editor .jarvis-gutter-added,+.monaco-editor .jarvis-gutter-modified {+ margin-left: 3px;+ width: 3px !important;+}+.monaco-editor .jarvis-gutter-added {+ background: hsl(var(--success));+}+.monaco-editor .jarvis-gutter-modified {+ background: hsl(var(--info));+}+.monaco-editor .jarvis-gutter-deleted::before,+.monaco-editor .jarvis-gutter-deleted-below::before {+ content: "";+ position: absolute;+ left: 2px;+ border: 4px solid transparent;+ border-left-color: hsl(var(--destructive));+}+.monaco-editor .jarvis-gutter-deleted::before {+ top: -4px;+}+.monaco-editor .jarvis-gutter-deleted-below::before {+ bottom: -4px;+}diff --git a/jarvis/ui/web/frontend/src/components/agentic/editor/editorModels.ts b/jarvis/ui/web/frontend/src/components/agentic/editor/editorModels.tsindex 3d3c3999f8..671d273b37 100644--- a/jarvis/ui/web/frontend/src/components/agentic/editor/editorModels.ts+++ b/jarvis/ui/web/frontend/src/components/agentic/editor/editorModels.ts@@ -324,6 +324,17 @@ export function loadHead(fileKey: string): Promise<Monaco.editor.ITextModel | nureturn load;}+/** The file's committed text for the gutter markers; null when git has none. */+export async function loadHeadText(fileKey: string): Promise<string | null> {+ const file = store().files[fileKey];+ if (!file) return null;+ try {+ return await fetchHeadText(file.workspaceId, file.path);+ } catch {+ return null; // no markers is the honest answer when git cannot say+ }+}+/*** Write a buffer to disk.*diff --git a/jarvis/ui/web/frontend/src/components/agentic/editor/lineDiff.test.ts b/jarvis/ui/web/frontend/src/components/agentic/editor/lineDiff.test.tsnew file mode 100644index 0000000000..c15c4fd145--- /dev/null+++ b/jarvis/ui/web/frontend/src/components/agentic/editor/lineDiff.test.ts@@ -0,0 +1,31 @@+import { describe, expect, it } from "vitest";++import { gutterChanges } from "./lineDiff";++describe("gutter changes", () => {+ it("marks nothing for an unchanged file", () => {+ expect(gutterChanges("a\nb\n", "a\nb\n")).toEqual([]);+ });++ it("marks added, modified and deleted lines in current-file coordinates", () => {+ const base = ["one", "two", "three", "four", "five"].join("\n");+ const current = ["one", "TWO", "three", "new a", "new b", "four"].join("\n");+ expect(gutterChanges(base, current)).toEqual([+ { kind: "modified", start: 2, end: 2 },+ { kind: "added", start: 4, end: 5 },+ { kind: "deleted", start: 7, end: 7 },+ ]);+ });++ it("treats CRLF and LF alike", () => {+ expect(gutterChanges("a\r\nb\r\n", "a\nb\n")).toEqual([]);+ });++ it("marks a deletion at the start before the first remaining line", () => {+ expect(gutterChanges("x\na\nb", "a\nb")).toEqual([{ kind: "deleted", start: 1, end: 1 }]);+ });++ it("reads an empty base as a rewrite of its one empty line", () => {+ expect(gutterChanges("", "a\nb")).toEqual([{ kind: "modified", start: 1, end: 2 }]);+ });+});diff --git a/jarvis/ui/web/frontend/src/components/agentic/editor/lineDiff.ts b/jarvis/ui/web/frontend/src/components/agentic/editor/lineDiff.tsnew file mode 100644index 0000000000..11363213c9--- /dev/null+++ b/jarvis/ui/web/frontend/src/components/agentic/editor/lineDiff.ts@@ -0,0 +1,115 @@+/**+ * Which lines of a buffer differ from the last commit, for the editor's+ * gutter markers: added (green), modified (blue) and deleted (a red notch+ * between two lines).+ *+ * A line-based Myers diff (O((N+M)·D)) over the two texts. Large rewrites are+ * not worth marking line by line, so the search gives up beyond a budget of+ * differences and the caller simply shows no markers.+ */+export type GutterKind = "added" | "modified" | "deleted";++export interface GutterChange {+ kind: GutterKind;+ /** 1-based first line in the current text (for "deleted": the line after the gap). */+ start: number;+ /** 1-based last line, inclusive (equals `start` for "deleted"). */+ end: number;+}++/** More differences than this and no markers are drawn. */+export const MAX_EDIT_DISTANCE = 4000;++const splitLines = (text: string) => text.split(/\r\n|\r|\n/);++/** The shortest edit script as [kind, oldIndex, newIndex] steps. */+function editScript(a: string[], b: string[]): ("=" | "-" | "+")[] | null {+ const n = a.length;+ const m = b.length;+ const max = Math.min(n + m, MAX_EDIT_DISTANCE);+ const offset = max + 1;+ const trace: Int32Array[] = [];+ let v = new Int32Array(2 * max + 3);+ for (let d = 0; d <= max; d += 1) {+ const next = v.slice();+ for (let k = -d; k <= d; k += 2) {+ let x =+ k === -d || (k !== d && v[offset + k - 1] < v[offset + k + 1]) ? v[offset + k + 1] : v[offset + k - 1] + 1;+ let y = x - k;+ while (x < n && y < m && a[x] === b[y]) {+ x += 1;+ y += 1;+ }+ next[offset + k] = x;+ if (x >= n && y >= m) {+ trace.push(next);+ return backtrack(trace, n, m, offset);+ }+ }+ trace.push(next);+ v = next;+ }+ return null;+}++function backtrack(trace: Int32Array[], n: number, m: number, offset: number): ("=" | "-" | "+")[] {+ const steps: ("=" | "-" | "+")[] = [];+ let x = n;+ let y = m;+ for (let d = trace.length - 1; d > 0; d -= 1) {+ const v = trace[d - 1];+ const k = x - y;+ const down = k === -d || (k !== d && v[offset + k - 1] < v[offset + k + 1]);+ const prevK = down ? k + 1 : k - 1;+ const prevX = v[offset + prevK];+ const prevY = prevX - prevK;+ while (x > prevX && y > prevY) {+ steps.push("=");+ x -= 1;+ y -= 1;+ }+ steps.push(down ? "+" : "-");+ x = prevX;+ y = prevY;+ }+ while (x > 0 && y > 0) {+ steps.push("=");+ x -= 1;+ y -= 1;+ }+ return steps.reverse();+}++/** The gutter markers for `current` against `base`; null when there are too many. */+export function gutterChanges(base: string, current: string): GutterChange[] | null {+ if (base === current) return [];+ const a = splitLines(base);+ const b = splitLines(current);+ const steps = editScript(a, b);+ if (!steps) return null;+ const changes: GutterChange[] = [];+ let line = 1; // 1-based line in `current`+ let index = 0;+ while (index < steps.length) {+ if (steps[index] === "=") {+ line += 1;+ index += 1;+ continue;+ }+ let removed = 0;+ let added = 0;+ while (index < steps.length && steps[index] !== "=") {+ if (steps[index] === "-") removed += 1;+ else added += 1;+ index += 1;+ }+ if (added === 0) {+ changes.push({ kind: "deleted", start: line, end: line });+ } else {+ const kind: GutterKind = removed > 0 ? "modified" : "added";+ changes.push({ kind, start: line, end: line + added - 1 });+ line += added;+ }+ }+ return changes;+}diff --git a/jarvis/ui/web/frontend/src/components/agentic/editor/monacoRuntime.ts b/jarvis/ui/web/frontend/src/components/agentic/editor/monacoRuntime.tsindex 309482bb55..91e18fa8b0 100644--- a/jarvis/ui/web/frontend/src/components/agentic/editor/monacoRuntime.ts+++ b/jarvis/ui/web/frontend/src/components/agentic/editor/monacoRuntime.ts@@ -6,20 +6,27 @@* time someone opens a file. Everything is bundled locally: no CDN, so the* editor works offline.*- * Deliberately lean: the editor core with all its editing features, syntax- * highlighting for every language Monaco ships, and the JSON language service.- * The TypeScript, CSS and HTML language services would add about 9 MB of- * workers for completions that the coding agents beside the editor already- * provide.+ * It carries the editor core with all its editing features, syntax+ * highlighting for every language Monaco ships, and the language services for+ * JSON, CSS/SCSS/Less, HTML and TypeScript/JavaScript (completions, hovers,+ * formatting, syntax errors). Each service runs in its own web worker, and a+ * worker only starts when a file of its language opens.*/import * as monaco from "monaco-editor/editor/editor.api";import "monaco-editor/features/register.all";import "monaco-editor/languages/definitions/register.all";import "monaco-editor/languages/features/json/register";+import "monaco-editor/languages/features/css/register";+import "monaco-editor/languages/features/html/register";+import { javascriptDefaults, typescriptDefaults, JsxEmit, ModuleKind, ModuleResolutionKind, ScriptTarget } from "monaco-editor/languages/features/typescript/register";import EditorWorker from "monaco-editor/editor/editor.worker?worker";import JsonWorker from "monaco-editor/languages/features/json/json.worker?worker";+import CssWorker from "monaco-editor/languages/features/css/css.worker?worker";+import HtmlWorker from "monaco-editor/languages/features/html/html.worker?worker";+import TsWorker from "monaco-editor/languages/features/typescript/ts.worker?worker";import { setMonaco } from "./editorModels";+import "./editorGutter.css";declare global {interface Window {@@ -29,10 +36,31 @@ declare global {self.MonacoEnvironment = {getWorker(_workerId: string, label: string) {- return label === "json" ? new JsonWorker() : new EditorWorker();+ if (label === "json") return new JsonWorker();+ if (label === "css" || label === "scss" || label === "less") return new CssWorker();+ if (label === "html" || label === "handlebars" || label === "razor") return new HtmlWorker();+ if (label === "typescript" || label === "javascript") return new TsWorker();+ return new EditorWorker();},};+// The editor sees one file at a time, not the project: its imports cannot be+// resolved, so type errors would paint every import red. Syntax errors,+// completions and hovers stay on; the agents and the project's own build+// check the types.+for (const defaults of [typescriptDefaults, javascriptDefaults]) {+ defaults.setDiagnosticsOptions({ noSemanticValidation: true, noSyntaxValidation: false });+ defaults.setCompilerOptions({+ target: ScriptTarget.ESNext,+ module: ModuleKind.ESNext,+ moduleResolution: ModuleResolutionKind.NodeJs,+ jsx: JsxEmit.ReactJSX,+ allowJs: true,+ allowNonTsExtensions: true,+ esModuleInterop: true,+ });+}+setMonaco(monaco);let probe: CanvasRenderingContext2D | null | undefined;