From 82268588f4309e9bd38baf185353c06936bbc00a Mon Sep 17 00:00:00 2001 From: "nekomimi.pet" Date: Mon, 19 Oct 2026 20:01:43 -0400 Subject: [PATCH] web: review on Pierre's diffs, with comments out on the canvas MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The review draws each diff with @pierre/diffs, highlighted by Shiki in Pierre's token colours over the canvas's own ground and diff colours. It loads with the first review, so the rest of the client stays small. The margin button beside a line starts a comment, hunk-style. Comments do not break the file open: the diff keeps a bare anchor under the lines, and the comment's card sits out on the canvas to the right of the window, level with its lines and tied to them. "send review" posts every comment as one message with the file, lines and quoted diff. A finished pick clears its selection, so the next comment lands on the lines it was asked for. The +a −r on a work line now opens the turn's review scrolled to the first file that stretch of work changed. --- robot-docs/web.md | 2 +- web/package-lock.json | 660 ++++++++++++++++++++++++++- web/package.json | 1 + web/src/lib/board.svelte.ts | 10 +- web/src/lib/chat/Chat.svelte | 2 +- web/src/lib/chat/WorkSteps.svelte | 41 +- web/src/lib/nodes/ReviewNode.svelte | 234 +++++++--- web/src/lib/review.svelte.ts | 101 ++++ web/src/lib/transcript.svelte.ts | 5 + web/src/lib/views/CommentNote.svelte | 126 +++++ web/src/lib/views/DiffView.svelte | 95 ++++ 11 files changed, 1200 insertions(+), 77 deletions(-) create mode 100644 web/src/lib/review.svelte.ts create mode 100644 web/src/lib/views/CommentNote.svelte create mode 100644 web/src/lib/views/DiffView.svelte diff --git a/robot-docs/web.md b/robot-docs/web.md index c9f92bb7c..a30a330ed 100644 --- a/robot-docs/web.md +++ b/robot-docs/web.md @@ -16,7 +16,7 @@ Words: a **board** is a named canvas of panels, and the open boards are the tabs A board is an open canvas. **Windows** sit anywhere on it; the view pans freely and zooms out to an overview. Svelte Flow draws, drags and resizes the windows; `board.svelte.ts` places new ones (right of the selected window, top-aligned, stepping past overlaps) and owns the viewport. The wheel is handled in `Canvas.svelte` rather than by Svelte Flow, because windows and canvas share the trackpad: a pinch (ctrl-wheel) zooms around the pointer anywhere, an up-down scroll over a window that can scroll scrolls it while the zoom is readable (60% and up), and every other scroll pans. + and − zoom in and out by 5 points (the buttons too), ⇧1 fits all windows, ⇧0 returns to 100%, M shows an overview map, ⌥←/⌥→ moves between windows. The view controls (zoom, fit, map) fade in while the view moves and fade out 4 s after it stops; hovering or focusing them keeps them, and once faded they let clicks through to the windows beneath. What a window shows is a **view**, each framed by `nodes/WindowFrame.svelte`: a session's chat, or a review of one turn's changes; files, terminals and agent-made pages are meant to follow. A view opened from a window names it as its `parent`, opens beside it, and the canvas draws a faint dashed line between them (the board derives Svelte Flow edges from those parents; every window carries invisible handles for them). -The review (`nodes/ReviewNode.svelte`, `review.ts`) opens from "review N files +a −r" on a turn's sign-off. It needs no daemon support beyond history: every tool call's trace records each file it changed, with the unified diff (`changes[].diff`, or `reason` when the file was binary, unreadable or too large). The window keeps the session, the turn and the turn's first history position, reads that turn's entries (`after=`, until the next turn starts), hydrates their traces, and shows the files with their counts, then each file's diffs in order with both line numbers. It is read-only so far; marking hunks, albedo's notes on them, and sending the marks back as one message are next. +The review (`nodes/ReviewNode.svelte`, `review.ts`, `review.svelte.ts`) opens from "review N files +a −r" on a turn's sign-off, or from the +a −r on any work line, which also scrolls it to the first file that stretch of work changed (`data.jump`). It needs no daemon support beyond history: every tool call's trace records each file it changed, with the unified diff (`changes[].diff`, or `reason` when the file was binary, unreadable or too large). The window keeps the session, the turn and the turn's first history position, reads that turn's entries (`after=`, until the next turn starts), hydrates their traces, and shows the files with their counts, then each file's diffs in order. Diffs are drawn by `@pierre/diffs` (Shiki highlighting, `pierre-dark`/`pierre-light` tokens over the canvas's own ground and diff colours; `views/DiffView.svelte`), loaded with the first review so the rest of the client stays small. The margin button beside a line (drag for several) starts a comment, hunk-style; comments never open the file up: the diff keeps a zero-height anchor under the lines, and the comment's card (`views/CommentNote.svelte`) sits out on the canvas to the right of the window, level with its lines and tied to them by a dashed line, stacked so cards never overlap and hidden while their lines are scrolled away. "send review" posts every comment as one message: the file and lines, the quoted diff lines, then the comment, after an optional overall note. Design rules the client keeps (from the design pass): surfaces separate by a step in tone, not by lines; only what floats (windows, the palette, the view controls, the overview map) casts a shadow; one accent, albedo's mauve by default and editable, used for focus and selection; no status dots; monospace only for code and tool commands. diff --git a/web/package-lock.json b/web/package-lock.json index a40051b4a..6d02dc325 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -6,6 +6,7 @@ "": { "name": "albedo-web", "dependencies": { + "@pierre/diffs": "^1.5.2", "marked": "^18.1.1" }, "devDependencies": { @@ -79,6 +80,72 @@ "url": "https://github.com/sponsors/oxc-project" } }, + "node_modules/@pierre/diffs": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@pierre/diffs/-/diffs-1.5.2.tgz", + "integrity": "sha512-QVxIWQEnNoko22k63maERzozd29+FtaUNpRrZiw603WMe5R1mFSED+jMtPkcVP3SDYS1DWg5K7sa7sJbr3xkNQ==", + "license": "apache-2.0", + "dependencies": { + "@pierre/theme": "2.0.0", + "@pierre/theming": "1.0.1", + "@shikijs/transformers": "^3.0.0 || ^4.0.0", + "diff": "9.0.0", + "hast-util-to-html": "9.0.5", + "lru_map": "0.4.1", + "shiki": "^3.0.0 || ^4.0.0" + }, + "peerDependencies": { + "react": "^18.3.1 || ^19.0.0", + "react-dom": "^18.3.1 || ^19.0.0" + }, + "peerDependenciesMeta": { + "react": { + "optional": true + }, + "react-dom": { + "optional": true + } + } + }, + "node_modules/@pierre/theme": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@pierre/theme/-/theme-2.0.0.tgz", + "integrity": "sha512-yNDd9GYLQl1mEUJR8AneJ5e4ohLIHQd/wZLWr4fagt78vS2RwwZNW530vVgHqXFAyFVcFlRmGUD5ramXH46OXw==", + "license": "apache-2.0", + "engines": { + "vscode": "^1.0.0" + } + }, + "node_modules/@pierre/theming": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@pierre/theming/-/theming-1.0.1.tgz", + "integrity": "sha512-WCI5Qd7iprDpISL9fBYOLe8RV53+b7mFNA3bPzl60/2CKCSrsKN8zEcep6Y3BAzvARlmca50zGjDodqPGiTUKA==", + "license": "apache-2.0", + "peerDependencies": { + "@pierre/theme": "^1.1.0 || ^2.0.0", + "@shikijs/themes": "^3.0.0 || ^4.0.0", + "react": "^18.3.1 || ^19.0.0", + "react-dom": "^18.3.1 || ^19.0.0", + "shiki": "^3.0.0 || ^4.0.0" + }, + "peerDependenciesMeta": { + "@pierre/theme": { + "optional": true + }, + "@shikijs/themes": { + "optional": true + }, + "react": { + "optional": true + }, + "react-dom": { + "optional": true + }, + "shiki": { + "optional": true + } + } + }, "node_modules/@rolldown/binding-android-arm-eabi": { "version": "1.2.14", "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm-eabi/-/binding-android-arm-eabi-1.2.14.tgz", @@ -341,6 +408,119 @@ "dev": true, "license": "MIT" }, + "node_modules/@shikijs/core": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/@shikijs/core/-/core-4.5.0.tgz", + "integrity": "sha512-6CIgwq+bt2JZ3OSjb/nBkkwEf/CfpHcbam+Mg5Pllco7HAGRQ2/EFhZrrJtbyNTgKwknfVS+llsXGygiDGwJWw==", + "license": "MIT", + "dependencies": { + "@shikijs/primitive": "4.5.0", + "@shikijs/types": "4.5.0", + "@shikijs/vscode-textmate": "^10.0.2", + "@types/hast": "^3.0.5", + "hast-util-to-html": "^9.0.5" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/@shikijs/engine-javascript": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/@shikijs/engine-javascript/-/engine-javascript-4.5.0.tgz", + "integrity": "sha512-Ed6UdEj84LyYkwnxM5CvSMWAD+id9ExTYri0/+x41U9zrgNifPSS9lZm0JqBP0VfYI8yr8tY5nbNq9+p9R0kFA==", + "license": "MIT", + "dependencies": { + "@shikijs/types": "4.5.0", + "@shikijs/vscode-textmate": "^10.0.2", + "oniguruma-to-es": "^4.3.6" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/@shikijs/engine-oniguruma": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/@shikijs/engine-oniguruma/-/engine-oniguruma-4.5.0.tgz", + "integrity": "sha512-dKVmbJecVdB9recl8a/CU4jdpNXyjJQrIcesIkpS70s5HS02ohpnCSpMUbotPnEUzbAcLQ+S4hwZYbkBBiTcJw==", + "license": "MIT", + "dependencies": { + "@shikijs/types": "4.5.0", + "@shikijs/vscode-textmate": "^10.0.2" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/@shikijs/langs": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/@shikijs/langs/-/langs-4.5.0.tgz", + "integrity": "sha512-wwBTqwduXSz0X4v9Qa2EWeFaYJEw1clCncWjoRNQRbVDu3SPRTRWucnouYapKj3b8Q+sk/41Vbc4B5c8nuYzLA==", + "license": "MIT", + "dependencies": { + "@shikijs/types": "4.5.0" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/@shikijs/primitive": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/@shikijs/primitive/-/primitive-4.5.0.tgz", + "integrity": "sha512-UM7ShlA8oz0OWxLLO8BmO9Ip6fVqdkt8yF0EH7nOCqHfrx1eEAzF0ZUVK7L+I8NEgeu1PEWSRlxaiPPeCb4iDg==", + "license": "MIT", + "dependencies": { + "@shikijs/types": "4.5.0", + "@shikijs/vscode-textmate": "^10.0.2", + "@types/hast": "^3.0.5" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/@shikijs/themes": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/@shikijs/themes/-/themes-4.5.0.tgz", + "integrity": "sha512-zGb87H3UBbpuI4yoh5UguB1XbU+2BDU3kflM7UfZ+Cy2hWo9lBtqjSVK20gmLY6ukYl040hAypGXMgud9vul8Q==", + "license": "MIT", + "dependencies": { + "@shikijs/types": "4.5.0" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/@shikijs/transformers": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/@shikijs/transformers/-/transformers-4.5.0.tgz", + "integrity": "sha512-LM7twi043qCC3gRyGQfjoC2/sowzbEltWuruyRtT3RlBlk1hKzWk9ETnU7RcDBoVWQBmC8Mebnr7p28W7kPoaA==", + "license": "MIT", + "dependencies": { + "@shikijs/core": "4.5.0", + "@shikijs/types": "4.5.0" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/@shikijs/types": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/@shikijs/types/-/types-4.5.0.tgz", + "integrity": "sha512-drtPrtD8N0DENyD2cyt6Ajy+IWsiCLgMxODwLTpvH1UsN6a9jf90tNTPjqwHvA+0Lzu9e0txk8DjfqH1p9UJRw==", + "license": "MIT", + "dependencies": { + "@shikijs/vscode-textmate": "^10.0.2", + "@types/hast": "^3.0.5" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/@shikijs/vscode-textmate": { + "version": "10.0.2", + "resolved": "https://registry.npmjs.org/@shikijs/vscode-textmate/-/vscode-textmate-10.0.2.tgz", + "integrity": "sha512-83yeghZ2xxin3Nj8z1NMd/NCuca+gsYXswywDy5bHvwlWL8tpTQmzGeUuHd9FC3E/SBEMvzJRwWEOz5gGes9Qg==", + "license": "MIT" + }, "node_modules/@svelte-put/shortcut": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/@svelte-put/shortcut/-/shortcut-4.2.0.tgz", @@ -460,17 +640,46 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/hast": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/@types/hast/-/hast-3.0.5.tgz", + "integrity": "sha512-rp/ezSWaD1m44dPKICGhiskI13nVr7qTloFwDa/IYkhhf5nzwP+zIQcIJh3WIFSBOy/H1PzB40jPjMDksN4F+g==", + "license": "MIT", + "dependencies": { + "@types/unist": "*" + } + }, + "node_modules/@types/mdast": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/@types/mdast/-/mdast-4.0.4.tgz", + "integrity": "sha512-kGaNbPh1k7AFzgpud/gMdvIm5xuECykRR+JnWKQno9TAXVa6WIVCGTPvYGekIDL4uwCZQSYbUxNBSb1aUo79oA==", + "license": "MIT", + "dependencies": { + "@types/unist": "*" + } + }, "node_modules/@types/node": { "version": "24.19.2", "resolved": "https://registry.npmjs.org/@types/node/-/node-24.19.2.tgz", "integrity": "sha512-93d49wCWJkCyN87MxLpNN6KXPCwFw7bVUg79mGUV1OS40JGWwVCr8n61DXCSqz7CV6/VfPkb7xec7uP2M+QHWQ==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "undici-types": ">=7.24.0 <7.24.7" } }, + "node_modules/@types/unist": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.3.tgz", + "integrity": "sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==", + "license": "MIT" + }, + "node_modules/@ungap/structured-clone": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.4.0.tgz", + "integrity": "sha512-1mEZtMKPM09vDmQt5y7YvmN2+DFTP7Tg0EWXdic8/C6VRnpb33e4ghisCIE3WZjsE2N8mf+QV1Zqh7ZFYLWInQ==", + "license": "ISC" + }, "node_modules/@xyflow/svelte": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/@xyflow/svelte/-/svelte-1.7.0.tgz", @@ -509,7 +718,6 @@ "integrity": "sha512-oJlA3XiRm7Cyk6qFD2Jn8ak9B7jSy0qy00ADO3+8dpT0LSjFihQYv4C02LFCSYJV3Q37xYwwRy5m+IpIiUzqWw==", "dev": true, "license": "MIT", - "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -537,6 +745,36 @@ "node": ">= 0.4" } }, + "node_modules/ccount": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/ccount/-/ccount-2.0.1.tgz", + "integrity": "sha512-eyrF0jiFpY+3drT6383f1qhkbGsLSifNAjA61IUjZjmLCWjItY6LB9ft9YhoDgwfmclB2zhu51Lc7+95b8NRAg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/character-entities-html4": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/character-entities-html4/-/character-entities-html4-2.1.0.tgz", + "integrity": "sha512-1v7fgQRj6hnSwFpq1Eu0ynr/CDEw0rXo2B61qXrLNdHZmPKgb7fqS1a2JwF0rISo9q77jDI8VMEHoApn8qDoZA==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/character-entities-legacy": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/character-entities-legacy/-/character-entities-legacy-3.0.0.tgz", + "integrity": "sha512-RpPp0asT/6ufRm//AJVwpViZbGM/MkjQFxJccQRHmISF/22NBtsHqAWmL+/pmkPWoIUJdWyeVleTl1wydHATVQ==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, "node_modules/chokidar": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-4.0.3.tgz", @@ -563,6 +801,16 @@ "node": ">=6" } }, + "node_modules/comma-separated-tokens": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/comma-separated-tokens/-/comma-separated-tokens-2.0.3.tgz", + "integrity": "sha512-Fu4hJdvzeylCfQPp9SGWidpzrMs7tTrlu6Vb8XGaRGck8QSNZJJp538Wrb60Lax4fPwR64ViY468OIUTbRlGZg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, "node_modules/d3-color": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/d3-color/-/d3-color-3.1.0.tgz", @@ -626,7 +874,6 @@ "integrity": "sha512-fmTRWbNMmsmWq6xJV8D19U/gw/bwrHfNXxrIN+HfZgnzqTHp9jOmKMhsTUjXOJnZOdZY9Q28y4yebKzqDKlxlQ==", "dev": true, "license": "ISC", - "peer": true, "engines": { "node": ">=12" } @@ -688,6 +935,15 @@ "node": ">=0.10.0" } }, + "node_modules/dequal": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", + "integrity": "sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/detect-libc": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", @@ -705,6 +961,28 @@ "dev": true, "license": "MIT" }, + "node_modules/devlop": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/devlop/-/devlop-1.1.0.tgz", + "integrity": "sha512-RWmIqhcFf1lRYBvNmr7qTNuyCt/7/ns2jbpp1+PalgE/rDQcBT0fioSMUpJ93irlUhC5hrg4cYqe6U+0ImW0rA==", + "license": "MIT", + "dependencies": { + "dequal": "^2.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/diff": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-9.0.0.tgz", + "integrity": "sha512-svtcdpS8CgJyqAjEQIXdb3OjhFVVYjzGAPO8WGCmRbrml64SPw/jJD4GoE98aR7r25A0XcgrK3F02yw9R/vhQw==", + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.3.1" + } + }, "node_modules/esm-env": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/esm-env/-/esm-env-1.2.2.tgz", @@ -763,6 +1041,52 @@ "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, + "node_modules/hast-util-to-html": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/hast-util-to-html/-/hast-util-to-html-9.0.5.tgz", + "integrity": "sha512-OguPdidb+fbHQSU4Q4ZiLKnzWo8Wwsf5bZfbvu7//a9oTYoqD/fWpe96NuHkoS9h0ccGOTe0C4NGXdtS0iObOw==", + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0", + "@types/unist": "^3.0.0", + "ccount": "^2.0.0", + "comma-separated-tokens": "^2.0.0", + "hast-util-whitespace": "^3.0.0", + "html-void-elements": "^3.0.0", + "mdast-util-to-hast": "^13.0.0", + "property-information": "^7.0.0", + "space-separated-tokens": "^2.0.0", + "stringify-entities": "^4.0.0", + "zwitch": "^2.0.4" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/hast-util-whitespace": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/hast-util-whitespace/-/hast-util-whitespace-3.0.0.tgz", + "integrity": "sha512-88JUN06ipLwsnv+dVn+OIYOvAuvBMy/Qoi6O7mQHxdPXpjy+Cd6xRkWwux7DKO+4sYILtLBRIKgsdpS2gQc7qw==", + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/html-void-elements": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/html-void-elements/-/html-void-elements-3.0.0.tgz", + "integrity": "sha512-bEqo66MRXsUGxWHV5IP0PUiAWwoEjba4VCzg0LjFJBpchPaTfyfCKTG6bc5F8ucKec3q5y6qOdGyYTSBEvhCrg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, "node_modules/is-reference": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-3.0.3.tgz", @@ -1041,6 +1365,12 @@ "dev": true, "license": "MIT" }, + "node_modules/lru_map": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/lru_map/-/lru_map-0.4.1.tgz", + "integrity": "sha512-I+lBvqMMFfqaV8CJCISjI3wbjmwVu/VyOoU7+qtu9d7ioW5klMgsTTiUOUp+DJvfTTzKXoPbyC6YfgkNcyPSOg==", + "license": "MIT" + }, "node_modules/magic-string": { "version": "1.4.3", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-1.4.3.tgz", @@ -1063,6 +1393,116 @@ "node": ">= 20" } }, + "node_modules/mdast-util-to-hast": { + "version": "13.2.1", + "resolved": "https://registry.npmjs.org/mdast-util-to-hast/-/mdast-util-to-hast-13.2.1.tgz", + "integrity": "sha512-cctsq2wp5vTsLIcaymblUriiTcZd0CwWtCbLvrOzYCDZoWyMNV8sZ7krj09FSnsiJi3WVsHLM4k6Dq/yaPyCXA==", + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0", + "@types/mdast": "^4.0.0", + "@ungap/structured-clone": "^1.0.0", + "devlop": "^1.0.0", + "micromark-util-sanitize-uri": "^2.0.0", + "trim-lines": "^3.0.0", + "unist-util-position": "^5.0.0", + "unist-util-visit": "^5.0.0", + "vfile": "^6.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/micromark-util-character": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/micromark-util-character/-/micromark-util-character-2.1.1.tgz", + "integrity": "sha512-wv8tdUTJ3thSFFFJKtpYKOYiGP2+v96Hvk4Tu8KpCAsTMs6yi+nVmGh1syvSCsaxz45J6Jbw+9DD6g97+NV67Q==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT", + "dependencies": { + "micromark-util-symbol": "^2.0.0", + "micromark-util-types": "^2.0.0" + } + }, + "node_modules/micromark-util-encode": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/micromark-util-encode/-/micromark-util-encode-2.0.1.tgz", + "integrity": "sha512-c3cVx2y4KqUnwopcO9b/SCdo2O67LwJJ/UyqGfbigahfegL9myoEFoDYZgkT7f36T0bLrM9hZTAaAyH+PCAXjw==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT" + }, + "node_modules/micromark-util-sanitize-uri": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/micromark-util-sanitize-uri/-/micromark-util-sanitize-uri-2.0.1.tgz", + "integrity": "sha512-9N9IomZ/YuGGZZmQec1MbgxtlgougxTodVwDzzEouPKo3qFWvymFHWcnDi2vzV1ff6kas9ucW+o3yzJK9YB1AQ==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT", + "dependencies": { + "micromark-util-character": "^2.0.0", + "micromark-util-encode": "^2.0.0", + "micromark-util-symbol": "^2.0.0" + } + }, + "node_modules/micromark-util-symbol": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/micromark-util-symbol/-/micromark-util-symbol-2.0.1.tgz", + "integrity": "sha512-vs5t8Apaud9N28kgCrRUdEed4UJ+wWNvicHLPxCa9ENlYuAY31M0ETy5y1vA33YoNPDFTghEbnh6efaE8h4x0Q==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT" + }, + "node_modules/micromark-util-types": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/micromark-util-types/-/micromark-util-types-2.0.3.tgz", + "integrity": "sha512-oxB2Ik03hI0gv+VNn9tnh1t1YEe9MDPptViAEgfdf3YQHsn0pzGTgCdlSCJXcwhqm8phaEuM7zeEu3QQzVBrPg==", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT" + }, "node_modules/mri": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz", @@ -1106,6 +1546,23 @@ "node": ">=12.20.0" } }, + "node_modules/oniguruma-parser": { + "version": "0.12.2", + "resolved": "https://registry.npmjs.org/oniguruma-parser/-/oniguruma-parser-0.12.2.tgz", + "integrity": "sha512-6HVa5oIrgMC6aA6WF6XyyqbhRPJrKR02L20+2+zpDtO5QAzGHAUGw5TKQvwi5vctNnRHkJYmjAhRVQF2EKdTQw==", + "license": "MIT" + }, + "node_modules/oniguruma-to-es": { + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/oniguruma-to-es/-/oniguruma-to-es-4.3.6.tgz", + "integrity": "sha512-csuQ9x3Yr0cEIs/Zgx/OEt9iBw9vqIunAPQkx19R/fiMq2oGVTgcMqO/V3Ybqefr1TBvosI6jU539ksaBULJyA==", + "license": "MIT", + "dependencies": { + "oniguruma-parser": "^0.12.2", + "regex": "^6.1.0", + "regex-recursion": "^6.0.2" + } + }, "node_modules/picocolors": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", @@ -1119,7 +1576,6 @@ "integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=12" }, @@ -1156,6 +1612,16 @@ "node": "^10 || ^12 || >=14" } }, + "node_modules/property-information": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/property-information/-/property-information-7.2.0.tgz", + "integrity": "sha512-IAtzIB6sUiWaJYrX9smp3V46pBGbBeLFRGdh25kg1334VcBlD8HzhPeNIWQH9zhGmo2itIe25EHt9dQP7G5hmg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, "node_modules/readdirp": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.1.2.tgz", @@ -1170,6 +1636,30 @@ "url": "https://paulmillr.com/funding/" } }, + "node_modules/regex": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/regex/-/regex-6.1.0.tgz", + "integrity": "sha512-6VwtthbV4o/7+OaAF9I5L5V3llLEsoPyq9P1JVXkedTP33c7MfCG0/5NOPcSJn0TzXcG9YUrR0gQSWioew3LDg==", + "license": "MIT", + "dependencies": { + "regex-utilities": "^2.3.0" + } + }, + "node_modules/regex-recursion": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/regex-recursion/-/regex-recursion-6.0.2.tgz", + "integrity": "sha512-0YCaSCq2VRIebiaUviZNs0cBz1kg5kVS2UKUfNIx8YVs1cN3AV7NTctO5FOKBA+UT2BPJIWZauYHPqJODG50cg==", + "license": "MIT", + "dependencies": { + "regex-utilities": "^2.3.0" + } + }, + "node_modules/regex-utilities": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/regex-utilities/-/regex-utilities-2.3.0.tgz", + "integrity": "sha512-8VhliFJAWRaUiVvREIiW2NXXTmHs4vMNnSzuJVhscgmGav3g9VDxLrQndI3dZZVVdp0ZO/5v0xmX516/7M9cng==", + "license": "MIT" + }, "node_modules/rolldown": { "version": "1.2.14", "resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.2.14.tgz", @@ -1217,6 +1707,25 @@ "node": ">=6" } }, + "node_modules/shiki": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/shiki/-/shiki-4.5.0.tgz", + "integrity": "sha512-OcRW72ngQvc+MSVWBRIovC/BTW589iUE/Vxav7VeM4RcY9MUjqB+IR6ILG1k9nuW6LiG/nct9uma4/MBtnZbmQ==", + "license": "MIT", + "dependencies": { + "@shikijs/core": "4.5.0", + "@shikijs/engine-javascript": "4.5.0", + "@shikijs/engine-oniguruma": "4.5.0", + "@shikijs/langs": "4.5.0", + "@shikijs/themes": "4.5.0", + "@shikijs/types": "4.5.0", + "@shikijs/vscode-textmate": "^10.0.2", + "@types/hast": "^3.0.5" + }, + "engines": { + "node": ">=20" + } + }, "node_modules/source-map-js": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.2.tgz", @@ -1227,13 +1736,36 @@ "node": ">=0.10.0" } }, + "node_modules/space-separated-tokens": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/space-separated-tokens/-/space-separated-tokens-2.0.2.tgz", + "integrity": "sha512-PEGlAwrG8yXGXRjW32fGbg66JAlOAwbObuqVoJpv/mRgoWDQfgH1wDPvtzWyUSNAXBGSk8h755YDbbcEy3SH2Q==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/stringify-entities": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/stringify-entities/-/stringify-entities-4.0.4.tgz", + "integrity": "sha512-IwfBptatlO+QCJUo19AqvrPNqlVMpW9YEL2LIVY+Rpv2qsjCGxaDLNRgeGsQWJhfItebuJhsGSLjaBbNSQ+ieg==", + "license": "MIT", + "dependencies": { + "character-entities-html4": "^2.0.0", + "character-entities-legacy": "^3.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, "node_modules/svelte": { "version": "5.57.2", "resolved": "https://registry.npmjs.org/svelte/-/svelte-5.57.2.tgz", "integrity": "sha512-1YiPCAXT0Ct6g1vOMmSLa0Nsc3QRMvtDF32ihgglGVrugIuIK38RyDiFNXVDhtQ81TJjSO57NdMw6DyYLqSGDQ==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@jridgewell/remapping": "^2.3.5", "@jridgewell/sourcemap-codec": "^1.6.0", @@ -1307,13 +1839,22 @@ "url": "https://github.com/sponsors/SuperchupuDev" } }, + "node_modules/trim-lines": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/trim-lines/-/trim-lines-3.0.1.tgz", + "integrity": "sha512-kRj8B+YHZCc9kQYdWfJB2/oUl9rA99qbowYYBtr4ui4mZyAQ2JpvVBd/6U2YloATfqBhBTSMhTpgBHtU0Mf3Rg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, "node_modules/typescript": { "version": "5.9.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", "dev": true, "license": "Apache-2.0", - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -1329,13 +1870,108 @@ "dev": true, "license": "MIT" }, + "node_modules/unist-util-is": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.1.tgz", + "integrity": "sha512-LsiILbtBETkDz8I9p1dQ0uyRUWuaQzd/cuEeS1hoRSyW5E5XGmTzlwY1OrNzzakGowI9Dr/I8HVaw4hTtnxy8g==", + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/unist-util-position": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/unist-util-position/-/unist-util-position-5.0.0.tgz", + "integrity": "sha512-fucsC7HjXvkB5R3kTCO7kUjRdrS0BJt3M/FPxmHMBOm8JQi2BsHAHFsy27E0EolP8rp0NzXsJ+jNPyDWvOJZPA==", + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/unist-util-stringify-position": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/unist-util-stringify-position/-/unist-util-stringify-position-4.0.0.tgz", + "integrity": "sha512-0ASV06AAoKCDkS2+xw5RXJywruurpbC4JZSm7nr7MOt1ojAzvyyaO+UxZf18j8FCF6kmzCZKcAgN/yu2gm2XgQ==", + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/unist-util-visit": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-5.1.0.tgz", + "integrity": "sha512-m+vIdyeCOpdr/QeQCu2EzxX/ohgS8KbnPDgFni4dQsfSCtpz8UqDyY5GjRru8PDKuYn7Fq19j1CQ+nJSsGKOzg==", + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0", + "unist-util-is": "^6.0.0", + "unist-util-visit-parents": "^6.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/unist-util-visit-parents": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-6.0.2.tgz", + "integrity": "sha512-goh1s1TBrqSqukSc8wrjwWhL0hiJxgA8m4kFxGlQ+8FYQ3C/m11FcTs4YYem7V664AhHVvgoQLk890Ssdsr2IQ==", + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0", + "unist-util-is": "^6.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/vfile": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/vfile/-/vfile-6.0.3.tgz", + "integrity": "sha512-KzIbH/9tXat2u30jf+smMwFCsno4wHVdNmzFyL+T/L3UGqqk6JKfVqOFOZEpZSHADH1k40ab6NUIXZq422ov3Q==", + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0", + "vfile-message": "^4.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/vfile-message": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/vfile-message/-/vfile-message-4.0.3.tgz", + "integrity": "sha512-QTHzsGd1EhbZs4AsQ20JX1rC3cOlt/IWJruk893DfLRr57lcnOeMaWG4K0JrRta4mIJZKth2Au3mM3u03/JWKw==", + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0", + "unist-util-stringify-position": "^4.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, "node_modules/vite": { "version": "8.3.4", "resolved": "https://registry.npmjs.org/vite/-/vite-8.3.4.tgz", "integrity": "sha512-IftLE8phJhdNRIGNEV4JCCvfNScoZQVfcXaN8TQropWGJtOHcu+iAB9pHcuGvmEb/kddw0LBe/jS8ztdC6xdiQ==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "lightningcss": "^1.33.0", "picomatch": "^4.0.7", @@ -1434,6 +2070,16 @@ "integrity": "sha512-msJxIvYDYcoNL+PJsu+7qmpDWsYmAxTY+2TNYXXF0hzBzBk0BMecOqDOG/EckUoKCuKwObfbugIl8QpqHDXeFA==", "dev": true, "license": "MIT" + }, + "node_modules/zwitch": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/zwitch/-/zwitch-2.0.4.tgz", + "integrity": "sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } } } } diff --git a/web/package.json b/web/package.json index bda140160..fd7c9d470 100644 --- a/web/package.json +++ b/web/package.json @@ -19,6 +19,7 @@ "vite": "^8.3.4" }, "dependencies": { + "@pierre/diffs": "^1.5.2", "marked": "^18.1.1" } } diff --git a/web/src/lib/board.svelte.ts b/web/src/lib/board.svelte.ts index b70edc6b8..6edddccc5 100644 --- a/web/src/lib/board.svelte.ts +++ b/web/src/lib/board.svelte.ts @@ -12,7 +12,8 @@ import type { Edge, Node, Viewport, useSvelteFlow } from '@xyflow/svelte'; // papers each one spread around it. export type SessionWindow = Node<{ sessionId: string; parent?: string }, 'session'>; /** The changes one turn made, walked file by file. `from` is the turn's first history position. */ -export type ReviewWindow = Node<{ sessionId: string; turnId: string; from: number; parent?: string }, 'review'>; +/** `jump` asks the window to bring one file into view; `at` makes each ask new. */ +export type ReviewWindow = Node<{ sessionId: string; turnId: string; from: number; parent?: string; jump?: { path: string; at: number } }, 'review'>; export type Window = SessionWindow | ReviewWindow; type Flow = ReturnType; @@ -114,8 +115,11 @@ export class Board { } /** Opens the review of one turn's changes beside the window it was asked from. */ - openReview(sessionId: string, turnId: string, from: number, parent?: string) { - this.#open({ id: `review:${sessionId}:${turnId}`, type: 'review', data: { sessionId, turnId, from, parent } }, 640); + openReview(sessionId: string, turnId: string, from: number, parent?: string, path?: string) { + const id = `review:${sessionId}:${turnId}`; + const jump = path ? { path, at: Date.now() } : undefined; + this.#open({ id, type: 'review', data: { sessionId, turnId, from, parent, jump } }, 640); + if (jump) this.nodes = this.nodes.map((node) => (node.id === id && node.type === 'review' ? { ...node, data: { ...node.data, jump } } : node)); } #open(window: Pick | Pick, width = SIZE.width) { diff --git a/web/src/lib/chat/Chat.svelte b/web/src/lib/chat/Chat.svelte index 21b16ccb8..e305ad41a 100644 --- a/web/src/lib/chat/Chat.svelte +++ b/web/src/lib/chat/Chat.svelte @@ -151,7 +151,7 @@ {:else if group.kind === 'work'} - + {:else if group.kind === 'end'}

{face(group.mood, group.seed)} diff --git a/web/src/lib/chat/WorkSteps.svelte b/web/src/lib/chat/WorkSteps.svelte index cf0d3fc27..0f532ea7f 100644 --- a/web/src/lib/chat/WorkSteps.svelte +++ b/web/src/lib/chat/WorkSteps.svelte @@ -1,5 +1,6 @@

+
+ {#if summary.added || summary.removed} + + {/if} +
{#if open}
{#each steps as step (step.key)} @@ -110,10 +122,29 @@ flex: none; color: var(--danger); } + .head { + display: flex; + align-items: center; + gap: 2px; + min-width: 0; + } + .head .summary { + flex: 1; + width: auto; + } .counts { flex: none; - margin-left: 4px; + padding: 2px 6px; + font: inherit; font-variant-numeric: tabular-nums; + background: none; + border: 0; + border-radius: 6px; + cursor: pointer; + transition: background-color 120ms ease; + } + .counts:hover { + background: var(--hover); } .added { color: var(--added); diff --git a/web/src/lib/nodes/ReviewNode.svelte b/web/src/lib/nodes/ReviewNode.svelte index 1cb0c490f..7a84f61b1 100644 --- a/web/src/lib/nodes/ReviewNode.svelte +++ b/web/src/lib/nodes/ReviewNode.svelte @@ -2,12 +2,22 @@ import type { NodeProps } from '@xyflow/svelte'; import type { ReviewWindow } from '../board.svelte'; import { namer } from '../burst'; - import { parseDiff, readTurn, turnChanges, type FileChanges } from '../review'; + import { readTurn, turnChanges, type FileChanges } from '../review'; import { sessions } from '../sessions.svelte'; + import type { DiffLineAnnotation } from '@pierre/diffs'; + import { useViewport } from '@xyflow/svelte'; + import { Review, type Note } from '../review.svelte'; + import CommentNote from '../views/CommentNote.svelte'; import WindowFrame from './WindowFrame.svelte'; - // A turn's changes, file by file, read from its history. Read-only for - // now; marks and albedo's notes on each hunk come next. + // The highlighter is large; it loads with the first review. + const DiffView = import('../views/DiffView.svelte').then((module) => module.default); + + // A turn's changes, file by file, read from its history and highlighted. + // The margin beside any line starts a comment on it (drag to cover + // several); "send review" posts every comment as one message. Comments do + // not break the file open: each sits out on the canvas to the right of the + // window, level with its lines, tied to them by a short line. let { id, data, selected }: NodeProps = $props(); const session = $derived(sessions.byId.get(data.sessionId)); const name = $derived(namer(session?.workspace ?? '')); @@ -15,6 +25,8 @@ let files = $state(null); let error = $state(null); let body = $state(); + // svelte-ignore state_referenced_locally + const review = new Review(data.sessionId, () => files ?? []); $effect(() => { const { sessionId, turnId, from } = data; @@ -27,11 +39,81 @@ const added = $derived(files?.reduce((sum, file) => sum + file.added, 0) ?? 0); const removed = $derived(files?.reduce((sum, file) => sum + file.removed, 0) ?? 0); + // Scrolls only the body: scrollIntoView would also scroll the canvas + // behind the window, which is not meant to scroll at all. function jump(index: number) { - body?.querySelector(`[data-file="${index}"]`)?.scrollIntoView({ behavior: 'smooth', block: 'start' }); + const target = body?.querySelector(`[data-file="${index}"]`); + if (!body || !target) return; + const zoom = viewport.current.zoom || 1; + const top = body.scrollTop + (target.getBoundingClientRect().top - body.getBoundingClientRect().top) / zoom - 8; + body.scrollTo({ top, behavior: 'smooth' }); + } + + // Asked from a work line in the chat: bring that file into view. + $effect(() => { + const path = data.jump?.path; + data.jump?.at; + const index = files?.findIndex((file) => file.path === path) ?? -1; + if (index >= 0) requestAnimationFrame(() => jump(index)); + }); + + // Where each comment's lines are, in the window's own pixels, measured + // from the anchors the diffs leave; read again as the body scrolls or the + // diffs redraw. + const viewport = useViewport(); + let node = $state(); + let places = $state>({}); + let frame = 0; + + function anchor(annotation: DiffLineAnnotation) { + const element = document.createElement('div'); + element.dataset.commentAnchor = annotation.metadata.id; + return element; + } + + function measure() { + cancelAnimationFrame(frame); + frame = requestAnimationFrame(() => { + if (!node || !body) return; + const zoom = viewport.current.zoom || 1; + const origin = node.getBoundingClientRect(); + const visible = body.getBoundingClientRect(); + const next: typeof places = {}; + for (const element of node.querySelectorAll('[data-comment-anchor]')) { + const at = element.getBoundingClientRect().top; + next[element.dataset.commentAnchor!] = { y: (at - origin.top) / zoom, shown: at >= visible.top - 4 && at <= visible.bottom + 4 }; + } + places = next; + }); + } + + // Cards keep their order down the margin and never overlap. + const CARD_GAP = 8; + let heights = $state>({}); + const cards = $derived.by(() => { + let floor = -Infinity; + return review.comments + .filter((comment) => places[comment.id]?.shown) + .sort((a, b) => places[a.id].y - places[b.id].y) + .map((comment) => { + const line = places[comment.id].y; + const top = Math.max(line - 14, floor); + floor = top + (heights[comment.id] ?? 60) + CARD_GAP; + return { comment, line, top }; + }); + }); + + $effect(() => { + review.comments; + measure(); + }); + + function count(path: string) { + return review.added.filter((comment) => comment.path === path).length; } +
{#snippet meta()} {#if files} @@ -40,7 +122,7 @@ {/if} {/snippet} -
+
{#if error}

(。•︿•。) couldn't read this turn: {error}

{:else if !files} @@ -52,6 +134,7 @@ {#each files as file, index (file.path)} {/each} @@ -63,29 +146,60 @@ {#if change.reason}

no diff to show: {change.reason}

{:else} -
- {#each parseDiff(change.diff) as line, row (row)} - {#if line.kind === 'hunk'} -
{line.text || '···'}
- {:else} -
- {line.old ?? ''} - {line.new ?? ''} - {line.kind === 'add' ? '+' : line.kind === 'remove' ? '−' : ''} - {line.text} -
- {/if} - {/each} -
+ {#await DiffView then View} + review.start(file.path, step, range)} onrender={measure} /> + {/await} {/if} {/each} {/each} {/if}
+ {#if files?.length} +
+ + {#if review.error}not sent{/if} + +
+ {/if} +{#each cards as card (card.comment.id)} + +
+ +
+{/each} +
+ diff --git a/web/src/lib/review.svelte.ts b/web/src/lib/review.svelte.ts new file mode 100644 index 000000000..71538a424 --- /dev/null +++ b/web/src/lib/review.svelte.ts @@ -0,0 +1,101 @@ +import type { DiffLineAnnotation, SelectedLineRange } from '@pierre/diffs'; +import { sendMessage, uuidv7 } from './api'; +import { parseDiff, type FileChanges } from './review'; + +// A review's comments, kept while its window is open. Each sits under the +// lines it is about in one of the turn's diffs; sending gathers them into +// one message, the way a code review goes back to its author. + +export interface Comment { + id: string; + path: string; + /** Which of the file's diffs in the turn, in order. */ + change: number; + side: 'additions' | 'deletions'; + start: number; + end: number; + text: string; + /** Still being written; not part of the review until added. */ + draft: boolean; +} + +/** What a diff's anchor carries: the comment it stands for. */ +export type Note = { id: string }; + +export class Review { + comments = $state([]); + summary = $state(''); + sending = $state(false); + sent = $state(false); + error = $state(null); + + constructor( + readonly sessionId: string, + readonly files: () => FileChanges[], + ) {} + + added = $derived(this.comments.filter((comment) => !comment.draft)); + + /** The notes one diff carries, for the renderer. */ + notesFor(path: string, change: number): DiffLineAnnotation[] { + return this.comments + .filter((comment) => comment.path === path && comment.change === change) + .map((comment) => ({ side: comment.side, lineNumber: comment.end, metadata: { id: comment.id } })); + } + + start(path: string, change: number, range: SelectedLineRange) { + const side = range.endSide ?? range.side ?? 'additions'; + const [start, end] = range.start <= range.end ? [range.start, range.end] : [range.end, range.start]; + this.comments = [...this.comments.filter((comment) => !(comment.draft && !comment.text.trim())), { id: uuidv7(), path, change, side, start, end, text: '', draft: true }]; + } + + save(id: string, text: string) { + if (!text.trim()) return this.remove(id); + this.comments = this.comments.map((comment) => (comment.id === id ? { ...comment, text: text.trim(), draft: false } : comment)); + } + + edit(id: string) { + this.comments = this.comments.map((comment) => (comment.id === id ? { ...comment, draft: true } : comment)); + } + + remove(id: string) { + this.comments = this.comments.filter((comment) => comment.id !== id); + } + + /** The review as one message: each comment with the lines it is about. */ + message(): string { + const parts = ['Review of your changes:']; + if (this.summary.trim()) parts.push(this.summary.trim()); + const files = this.files(); + for (const comment of this.added) { + const diff = files.find((file) => file.path === comment.path)?.changes[comment.change]?.diff ?? ''; + const lines = parseDiff(diff).filter( + (line) => line.kind !== 'hunk' && (comment.side === 'additions' ? line.new : line.old) !== null && within(comment, comment.side === 'additions' ? line.new! : line.old!), + ) as { kind: 'add' | 'remove' | 'context'; text: string }[]; + const where = `${comment.path}:${comment.start === comment.end ? comment.start : `${comment.start}-${comment.end}`}${comment.side === 'deletions' ? ' (removed lines)' : ''}`; + const quoted = lines.map((line) => (line.kind === 'add' ? '+' : line.kind === 'remove' ? '-' : ' ') + line.text).join('\n'); + parts.push(`${where}\n\`\`\`diff\n${quoted}\n\`\`\`\n${comment.text}`); + } + return parts.join('\n\n'); + } + + async send() { + if (!this.added.length && !this.summary.trim()) return; + this.sending = true; + this.error = null; + try { + await sendMessage(this.sessionId, uuidv7(), this.message()); + this.comments = this.comments.filter((comment) => comment.draft); + this.summary = ''; + this.sent = true; + } catch (error) { + this.error = String((error as Error).message ?? error); + } finally { + this.sending = false; + } + } +} + +function within(comment: Comment, line: number) { + return line >= comment.start && line <= comment.end; +} diff --git a/web/src/lib/transcript.svelte.ts b/web/src/lib/transcript.svelte.ts index 1ceacdb2f..6f0dcf3f7 100644 --- a/web/src/lib/transcript.svelte.ts +++ b/web/src/lib/transcript.svelte.ts @@ -291,6 +291,11 @@ export class Transcript { this.pending = this.pending.filter((send) => send.id !== id); } + /** Where a turn starts among the loaded entries, for a review of it. */ + turnStart(turnId: string): number | null { + return this.entries.find((entry) => entry.turn_id === turnId)?.position ?? null; + } + /** Puts tool entries' full arguments and output in place of their references. */ async expand(...entries: HistoryEntry[]) { const waiting = entries.filter((entry) => !entry.content_complete && !this.#expanding.has(entry.id) && referenced(entry)); diff --git a/web/src/lib/views/CommentNote.svelte b/web/src/lib/views/CommentNote.svelte new file mode 100644 index 000000000..7b4333250 --- /dev/null +++ b/web/src/lib/views/CommentNote.svelte @@ -0,0 +1,126 @@ + + +
+ {comment.start === comment.end ? `line ${comment.start}` : `lines ${comment.start}–${comment.end}`}{comment.side === 'deletions' ? ' (removed)' : ''} + {#if comment.draft} + +
+ {#each quick as phrase (phrase)} + + {/each} + + + +
+ {:else} +

{comment.text}

+
+ + + +
+ {/if} +
+ + diff --git a/web/src/lib/views/DiffView.svelte b/web/src/lib/views/DiffView.svelte new file mode 100644 index 000000000..4317ff36b --- /dev/null +++ b/web/src/lib/views/DiffView.svelte @@ -0,0 +1,95 @@ + + +
+ + -- knotmirror 0.0.1