Mike0021 commited on
Commit
8b7d861
·
verified ·
1 Parent(s): 9049cfe

Pi Web fork: diffs with @pierre /diffs (diffs.com) and Shiki in web workers

Browse files
Files changed (1) hide show
  1. piweb/hf-design.patch +1753 -150
piweb/hf-design.patch CHANGED
@@ -94,6 +94,19 @@ index d4d7df6..25f95bd 100644
94
  @media (max-width: 720px) {
95
  body { padding: 0; background: #fff; }
96
  main { min-height: 100vh; padding: 28px 22px; box-shadow: none; }
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  diff --git a/app/favicon.ico b/app/favicon.ico
98
  index 2da6b7dc00c64c59ef23cff153a6051478ad9315..b407f41443e3e94f4204a1862227e0d457f7d823 100644
99
  GIT binary patch
@@ -3421,7 +3434,7 @@ index 0000000..8d003fe
3421
  +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
3422
  +OTHER DEALINGS IN THE FONT SOFTWARE.
3423
  diff --git a/app/globals.css b/app/globals.css
3424
- index d6b5535..65e3c08 100644
3425
  --- a/app/globals.css
3426
  +++ b/app/globals.css
3427
  @@ -24,46 +24,109 @@
@@ -4172,7 +4185,7 @@ index d6b5535..65e3c08 100644
4172
  background: var(--bg-panel);
4173
  }
4174
  .markdown-frontmatter-title {
4175
- @@ -2474,3 +2555,422 @@ span.token.table {
4176
  display: none !important;
4177
  }
4178
  }
@@ -4469,45 +4482,52 @@ index d6b5535..65e3c08 100644
4469
  +
4470
  +/* A diff in a tool call (MessageView UnifiedFilesView): line number, mark, code;
4471
  + added and removed lines tinted, no rules between them. */
4472
- +.unified-diff {
4473
- + max-height: 560px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4474
  + overflow: auto;
4475
- + padding: 6px 0;
4476
- + font-family: var(--font-mono);
4477
  + font-weight: var(--font-mono-weight);
4478
- + font-size: calc(12px + var(--chat-font-size-offset, 0px));
4479
- + line-height: 1.6;
4480
  +}
4481
- +.unified-diff-file + .unified-diff-file { margin-top: 8px; }
4482
- +.unified-diff-path {
4483
- + padding: 2px 12px 4px;
4484
  + overflow: hidden;
4485
  + color: var(--text-muted);
 
 
4486
  + text-overflow: ellipsis;
4487
  + white-space: nowrap;
4488
  +}
4489
- +.unified-diff-line { display: flex; min-width: 0; }
4490
- +.unified-diff-line.is-added { background: color-mix(in srgb, var(--success) 14%, transparent); }
4491
- +.unified-diff-line.is-removed { background: color-mix(in srgb, var(--danger) 14%, transparent); }
4492
- +.unified-diff-no {
4493
- + flex: none;
4494
- + width: 44px;
4495
- + padding-right: 8px;
4496
- + color: var(--text-dim);
4497
- + text-align: right;
4498
- + user-select: none;
4499
- +}
4500
- +.unified-diff-mark { flex: none; width: 16px; color: var(--text-dim); user-select: none; }
4501
- +.unified-diff-line.is-added .unified-diff-mark { color: var(--success); }
4502
- +.unified-diff-line.is-removed .unified-diff-mark { color: var(--danger); }
4503
- +.unified-diff-line.is-empty .unified-diff-text { color: var(--text-dim); }
4504
- +.unified-diff-text {
4505
- + flex: 1;
4506
- + min-width: 0;
4507
- + padding-right: 12px;
4508
- + color: var(--text);
4509
- + white-space: pre-wrap;
4510
- + overflow-wrap: anywhere;
4511
  +}
4512
  +
4513
  +/* An error or a cut-off reply under the agent's text: a tinted note, no outline. */
@@ -8873,6 +8893,253 @@ index 6c540a4..57ffd84 100644
8873
  border: "1px solid var(--border)",
8874
  background: "var(--bg-panel)",
8875
  color: "var(--text-muted)",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8876
  diff --git a/components/DirectoryPicker.tsx b/components/DirectoryPicker.tsx
8877
  index 433cd89..344b0c2 100644
8878
  --- a/components/DirectoryPicker.tsx
@@ -9387,17 +9654,26 @@ index b46d21a..8a8b640 100644
9387
 
9388
  export function FolderIcon({ size = 14, open = false }: IconProps & { open?: boolean }) {
9389
  diff --git a/components/FileViewer.tsx b/components/FileViewer.tsx
9390
- index 9426211..ce8ff16 100644
9391
  --- a/components/FileViewer.tsx
9392
  +++ b/components/FileViewer.tsx
9393
- @@ -6,6 +6,7 @@ import SyntaxHighlighter from "react-syntax-highlighter/dist/esm/prism-light";
9394
  import renderSyntaxNode from "react-syntax-highlighter/dist/esm/create-element";
9395
  import { vs } from "react-syntax-highlighter/dist/cjs/styles/prism";
9396
  import { vscDarkPlus } from "react-syntax-highlighter/dist/cjs/styles/prism";
9397
  +import { neutralCodeTheme } from "@/lib/neutral-code-theme";
 
9398
  import ReactMarkdown from "react-markdown";
9399
  import { useTheme } from "@/hooks/useTheme";
9400
  import { usePrismLanguages } from "@/hooks/usePrismLanguages";
 
 
 
 
 
 
 
 
9401
  @@ -34,6 +35,8 @@ import {
9402
  type FileViewerDisplayMode as DisplayMode,
9403
  type FileViewerState,
@@ -9464,7 +9740,7 @@ index 9426211..ce8ff16 100644
9464
  );
9465
  }
9466
 
9467
- @@ -252,11 +259,7 @@ function DownloadLink({ filePath, sourceSessionId }: { filePath: string; sourceS
9468
  aria-label={t("i18n.downloadFile")}
9469
  className="file-viewer-icon-button"
9470
  >
@@ -9477,7 +9753,218 @@ index 9426211..ce8ff16 100644
9477
  </a>
9478
  );
9479
  }
9480
- @@ -1442,7 +1445,7 @@ function TextFileViewer({
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9481
  <SyntaxHighlighter
9482
  className={wrapLines ? "file-source-view is-wrapped" : "file-source-view"}
9483
  language={language === "text" || !prismReady ? "plaintext" : language}
@@ -9486,7 +9973,7 @@ index 9426211..ce8ff16 100644
9486
  showLineNumbers
9487
  lineNumberStyle={{
9488
  ...FILE_LINE_NUMBER_STYLE,
9489
- @@ -1708,12 +1711,7 @@ function TextFileViewer({
9490
  color: wrapLines ? "var(--text)" : "var(--text-muted)",
9491
  }}
9492
  >
@@ -9500,7 +9987,7 @@ index 9426211..ce8ff16 100644
9500
  </button>
9501
  </>
9502
  )}
9503
- @@ -1733,7 +1731,7 @@ function TextFileViewer({
9504
  gap: 10,
9505
  padding: "5px 8px",
9506
  border: "1px solid var(--border)",
@@ -9509,6 +9996,15 @@ index 9426211..ce8ff16 100644
9509
  color: "var(--text-dim)",
9510
  fontSize: 11,
9511
  }}
 
 
 
 
 
 
 
 
 
9512
  diff --git a/components/FontSettings.tsx b/components/FontSettings.tsx
9513
  index 7e4c208..960fc5e 100644
9514
  --- a/components/FontSettings.tsx
@@ -9685,15 +10181,10 @@ index 515b033..eeb4c1e 100644
9685
 
9686
  test("collapses a displayed custom message from its header alone", () => {
9687
  diff --git a/components/MessageView.tsx b/components/MessageView.tsx
9688
- index f2ff1de..d98d368 100644
9689
  --- a/components/MessageView.tsx
9690
  +++ b/components/MessageView.tsx
9691
- @@ -1,10 +1,11 @@
9692
- "use client";
9693
-
9694
- -import { memo, useState, useRef, useEffect, useMemo } from "react";
9695
- +import { memo, useState, useRef, useEffect, useLayoutEffect, useMemo } from "react";
9696
- import ReactMarkdown from "react-markdown";
9697
  import { MarkdownBody } from "./MarkdownBody";
9698
  import { ImagePreview } from "./ImagePreview";
9699
  import { ThinkingIcon } from "./ThinkingIcon";
@@ -9701,7 +10192,14 @@ index f2ff1de..d98d368 100644
9701
  import { copyText } from "@/lib/clipboard";
9702
  import { useI18n } from "@/hooks/useI18n";
9703
  import { parseCompactionSummary } from "@/lib/compaction-summary";
9704
- @@ -35,6 +36,8 @@ import type {
 
 
 
 
 
 
 
9705
  ToolCallContent,
9706
  ThinkingContent,
9707
  } from "@/lib/types";
@@ -9710,7 +10208,7 @@ index f2ff1de..d98d368 100644
9710
 
9711
  // CJK chars ~1 token each (GLM/DeepSeek/GPT-o200k); other chars ~4 chars/token.
9712
  const CJK_PATTERN = /[\u3000-\u30ff\u3400-\u9fff\uf900-\ufaff\u{20000}-\u{2fa1f}\uac00-\ud7af]/u;
9713
- @@ -122,7 +125,7 @@ function SafeMarkdownBody({ children, className, ...props }: React.ComponentProp
9714
  margin: "4px 0",
9715
  padding: "7px 10px",
9716
  border: "1px solid var(--border)",
@@ -9719,7 +10217,7 @@ index f2ff1de..d98d368 100644
9719
  background: "var(--bg-panel)",
9720
  color: "var(--text-muted)",
9721
  cursor: "pointer",
9722
- @@ -213,6 +216,19 @@ interface Props {
9723
  onCompact?: () => void;
9724
  isCompacting?: boolean;
9725
  compactError?: string | null;
@@ -9739,7 +10237,7 @@ index f2ff1de..d98d368 100644
9739
  }
9740
 
9741
  export function getModelDisplayName(
9742
- @@ -280,12 +296,12 @@ function haveSameRelevantToolResults(
9743
  return true;
9744
  }
9745
 
@@ -9754,7 +10252,7 @@ index f2ff1de..d98d368 100644
9754
  }
9755
  if (message.role === "toolResult") {
9756
  // Rendered inline under its toolCall — skip standalone rendering if paired
9757
- @@ -322,9 +338,18 @@ export const MessageView = memo(function MessageView({ message, isStreaming, too
9758
  && prev.sessionId === next.sessionId
9759
  && prev.onCompact === next.onCompact
9760
  && prev.isCompacting === next.isCompacting
@@ -9774,7 +10272,7 @@ index f2ff1de..d98d368 100644
9774
  function UserMessageView({ message, cwd, onOpenFile, entryId, onFork, forking, onEditContent, onCancelEdit, isEditing }: {
9775
  message: UserMessage;
9776
  cwd?: string;
9777
- @@ -337,7 +362,6 @@ function UserMessageView({ message, cwd, onOpenFile, entryId, onFork, forking, o
9778
  isEditing?: boolean;
9779
  }) {
9780
  const { t } = useI18n();
@@ -9782,7 +10280,7 @@ index f2ff1de..d98d368 100644
9782
  const [copied, setCopied] = useState(false);
9783
  const [expanded, setExpanded] = useState(false);
9784
 
9785
- @@ -391,7 +415,7 @@ function UserMessageView({ message, cwd, onOpenFile, entryId, onFork, forking, o
9786
  <img
9787
  src={src}
9788
  alt=""
@@ -9791,7 +10289,7 @@ index f2ff1de..d98d368 100644
9791
  />
9792
  </ImagePreview>
9793
  );
9794
- @@ -409,228 +433,120 @@ function UserMessageView({ message, cwd, onOpenFile, entryId, onFork, forking, o
9795
  };
9796
 
9797
  return (
@@ -10123,7 +10621,7 @@ index f2ff1de..d98d368 100644
10123
  </div>
10124
  );
10125
  }
10126
- @@ -652,6 +568,8 @@ function AssistantMessageView({
10127
  onCompact,
10128
  isCompacting,
10129
  compactError,
@@ -10132,7 +10630,7 @@ index f2ff1de..d98d368 100644
10132
  }: {
10133
  message: AssistantMessage;
10134
  isStreaming?: boolean;
10135
- @@ -669,6 +587,8 @@ function AssistantMessageView({
10136
  onCompact?: () => void;
10137
  isCompacting?: boolean;
10138
  compactError?: string | null;
@@ -10141,7 +10639,7 @@ index f2ff1de..d98d368 100644
10141
  }) {
10142
  const { t } = useI18n();
10143
  const time = showTimestamp ? formatTime(message.timestamp) : null;
10144
- @@ -679,7 +599,6 @@ function AssistantMessageView({
10145
  const providerError = getAssistantErrorMessage(message, { isStreaming });
10146
  const truncated = isAssistantTruncated(message, { isStreaming });
10147
  const unansweredTruncation = truncated && !hasAssistantAnswer(message);
@@ -10149,7 +10647,7 @@ index f2ff1de..d98d368 100644
10149
  const [copied, setCopied] = useState(false);
10150
  const streamStartRef = useRef<StreamRateStart | null>(null);
10151
  const rateKey = streamRateKey(message);
10152
- @@ -803,123 +722,59 @@ function AssistantMessageView({
10153
 
10154
  if (blocks.length === 0 && !isStreaming && !providerError && !truncated) return null;
10155
 
@@ -10298,7 +10796,7 @@ index f2ff1de..d98d368 100644
10298
  )}
10299
  </div>
10300
  )}
10301
- @@ -928,51 +783,28 @@ function AssistantMessageView({
10302
  <TurnWrittenFiles files={writtenFiles} onOpenFile={onOpenFile} />
10303
  )}
10304
 
@@ -10368,7 +10866,7 @@ index f2ff1de..d98d368 100644
10368
  </div>
10369
  );
10370
  }
10371
- @@ -1052,62 +884,34 @@ export function ThinkingBlock({ block, duration, sessionId, entryId, blockIndex
10372
  }, [expanded, block.deferred, content, sessionId, entryId, blockIndex]);
10373
 
10374
  return (
@@ -10455,7 +10953,7 @@ index f2ff1de..d98d368 100644
10455
  </div>
10456
  );
10457
  }
10458
- @@ -1176,136 +980,131 @@ function ToolCallBlock({ block, result, duration, onOpenSubagent }: { block: Too
10459
  const subagent = isSubagentToolDetails(result?.details) ? result.details : null;
10460
  const codemodeCallCount = codemode ? codemode.calls.length + codemode.omitted : 0;
10461
 
@@ -10633,7 +11131,7 @@ index f2ff1de..d98d368 100644
10633
  + {/* ── Applied-patch split diff ── */}
10634
  + {patchFiles && (
10635
  + <div style={{ background: "var(--bg)" }}>
10636
- + <SplitFilesView files={patchFiles} />
10637
  + </div>
10638
  + )}
10639
  +
@@ -10681,7 +11179,7 @@ index f2ff1de..d98d368 100644
10681
  interface ResultDiff {
10682
  text: string;
10683
  }
10684
- @@ -1316,7 +1115,6 @@ function PairedDiffResult({ diff }: {
10685
  return (
10686
  <div
10687
  style={{
@@ -10689,86 +11187,163 @@ index f2ff1de..d98d368 100644
10689
  background: "var(--bg)",
10690
  }}
10691
  >
10692
- @@ -1331,7 +1129,78 @@ function SplitPatchView({ text }: { text: string }) {
10693
- return <SplitFilesView files={files} />;
10694
  }
10695
 
10696
- +/** Side by side only where both halves have room for code: 960px or more. */
10697
- +const SPLIT_DIFF_MIN_WIDTH = 960;
10698
- +
10699
- +/**
10700
- + * A diff in the transcript: unified, one column with a line number, as Claude
10701
- + * Desktop shows edits, in the default 720px column; side by side once the chat
10702
- + * column is wide enough for two halves of code.
10703
- + */
10704
- function SplitFilesView({ files }: { files: SplitDiffFile[] }) {
10705
- + const ref = useRef<HTMLDivElement | null>(null);
10706
- + const [wide, setWide] = useState(false);
10707
- + useLayoutEffect(() => {
10708
- + const el = ref.current;
10709
- + if (!el || typeof ResizeObserver === "undefined") return;
10710
- + const update = () => setWide(el.clientWidth >= SPLIT_DIFF_MIN_WIDTH);
10711
- + update();
10712
- + const observer = new ResizeObserver(update);
10713
- + observer.observe(el);
10714
- + return () => observer.disconnect();
10715
- + }, []);
10716
- + return (
10717
- + <div ref={ref} style={{ minWidth: 0 }}>
10718
- + {wide ? <SideBySideFilesView files={files} /> : <UnifiedFilesView files={files} />}
10719
- + </div>
10720
- + );
10721
- +}
10722
- +
10723
- +/** One column: removed lines, then the lines that replaced them, each with its line number. */
10724
- +function UnifiedFilesView({ files }: { files: SplitDiffFile[] }) {
10725
- + const showFileHeaders = files.length > 1;
10726
- + return (
10727
- + <div className="unified-diff">
10728
- + {files.map((file, fileIndex) => {
10729
- + const lines: { key: string; cell: SplitDiffCell }[] = [];
10730
- + let added: SplitDiffCell[] = [];
10731
- + const flush = () => {
10732
- + for (const cell of added) lines.push({ key: `a${lines.length}`, cell });
10733
- + added = [];
10734
- + };
10735
- + file.rows.forEach((row) => {
10736
- + if (row.type === "hunk") {
10737
- + flush();
10738
- + if (lines.length > 0) lines.push({ key: `h${lines.length}`, cell: { type: "empty", lineNo: null, text: "⋯" } });
10739
- + return;
10740
- + }
10741
- + if (row.left.type === "context") {
10742
- + flush();
10743
- + lines.push({ key: `c${lines.length}`, cell: row.right.type === "context" ? row.right : row.left });
10744
- + return;
10745
- + }
10746
- + if (row.left.type === "removed") lines.push({ key: `r${lines.length}`, cell: row.left });
10747
- + if (row.right.type === "added") added.push(row.right);
10748
- + });
10749
- + flush();
10750
- + return (
10751
- + <div key={fileIndex} className="unified-diff-file">
10752
- + {showFileHeaders && <div className="unified-diff-path" title={file.newPath || file.oldPath}>{file.newPath || file.oldPath}</div>}
10753
- + {lines.map(({ key, cell }) => (
10754
- + <div key={key} className={`unified-diff-line is-${cell.type}`}>
10755
- + <span className="unified-diff-no">{cell.lineNo ?? ""}</span>
10756
- + <span className="unified-diff-mark">{cell.type === "added" ? "+" : cell.type === "removed" ? "-" : ""}</span>
10757
- + <span className="unified-diff-text">{cell.text || "\u00a0"}</span>
10758
- + </div>
10759
- + ))}
10760
- + </div>
10761
- + );
10762
- + })}
10763
- + </div>
10764
- + );
10765
- +}
10766
- +
10767
- +function SideBySideFilesView({ files }: { files: SplitDiffFile[] }) {
10768
- const { t } = useI18n();
10769
- const showFileHeaders = files.length > 1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10770
 
10771
- @@ -1483,12 +1352,12 @@ function PatchTextView({ text }: { text: string }) {
 
10772
  const bg =
10773
  kind === "added" ? "rgba(34,197,94,0.12)" :
10774
  kind === "removed" ? "rgba(248,113,113,0.13)" :
@@ -10783,7 +11358,7 @@ index f2ff1de..d98d368 100644
10783
  "var(--text)";
10784
 
10785
  return (
10786
- @@ -1502,7 +1371,7 @@ function PatchTextView({ text }: { text: string }) {
10787
  : kind === "removed"
10788
  ? "3px solid #f87171"
10789
  : kind === "hunk"
@@ -10792,7 +11367,7 @@ index f2ff1de..d98d368 100644
10792
  : "3px solid transparent",
10793
  }}
10794
  >
10795
- @@ -1587,7 +1456,6 @@ function ResultImages({ images, isError }: { images: ImageContent[]; isError: bo
10796
  flexWrap: "wrap",
10797
  padding: "10px",
10798
  background: "var(--bg)",
@@ -10800,7 +11375,7 @@ index f2ff1de..d98d368 100644
10800
  }}
10801
  >
10802
  {images.map((image, index) => {
10803
- @@ -1608,7 +1476,7 @@ function ResultImages({ images, isError }: { images: ImageContent[]; isError: bo
10804
  display: "block",
10805
  maxWidth: "min(100%, 720px)",
10806
  maxHeight: 520,
@@ -10809,7 +11384,7 @@ index f2ff1de..d98d368 100644
10809
  objectFit: "contain",
10810
  border: "1px solid var(--border)",
10811
  }}
10812
- @@ -1629,8 +1497,7 @@ function PairedResult({ text, isEmpty, isError }: {
10813
  return (
10814
  <div
10815
  style={{
@@ -10819,7 +11394,7 @@ index f2ff1de..d98d368 100644
10819
  }}
10820
  >
10821
  <pre
10822
- @@ -1668,7 +1535,7 @@ function CompactionMessageView({ message }: { message: CustomMessage }) {
10823
  <div
10824
  style={{
10825
  border: "1px solid var(--border)",
@@ -10828,7 +11403,7 @@ index f2ff1de..d98d368 100644
10828
  overflow: "hidden",
10829
  background: "var(--bg)",
10830
  }}
10831
- @@ -1710,9 +1577,7 @@ function CompactionMessageView({ message }: { message: CustomMessage }) {
10832
  textAlign: "left",
10833
  }}
10834
  >
@@ -10839,7 +11414,7 @@ index f2ff1de..d98d368 100644
10839
  <span style={{ minWidth: 0 }}>
10840
  <span style={{ display: "block", fontSize: "calc(15px + var(--chat-font-size-offset, 0px))", fontWeight: 700, lineHeight: 1.35 }}>
10841
  {t("i18n.conversationCompacted")}
10842
- @@ -1806,7 +1671,7 @@ function CustomMessageView({ message, cwd, onOpenFile }: { message: CustomMessag
10843
  <div
10844
  style={{
10845
  border: "1px solid var(--border)",
@@ -10848,7 +11423,7 @@ index f2ff1de..d98d368 100644
10848
  overflow: "hidden",
10849
  background: "var(--bg)",
10850
  }}
10851
- @@ -1852,9 +1717,7 @@ function CustomMessageView({ message, cwd, onOpenFile }: { message: CustomMessag
10852
  </span>
10853
  )}
10854
  {time && <span style={{ marginLeft: "auto", color: "var(--text-dim)", fontSize: 10, flexShrink: 0 }}>{time}</span>}
@@ -10859,7 +11434,7 @@ index f2ff1de..d98d368 100644
10859
  </button>
10860
  </div>
10861
 
10862
- @@ -1872,7 +1735,7 @@ function CustomMessageView({ message, cwd, onOpenFile }: { message: CustomMessag
10863
  <img
10864
  src={src}
10865
  alt=""
@@ -10868,7 +11443,7 @@ index f2ff1de..d98d368 100644
10868
  />
10869
  </ImagePreview>
10870
  );
10871
- @@ -2021,13 +1884,16 @@ function getToolPreview(block: ToolCallContent): string {
10872
  return String(first).slice(0, 120);
10873
  }
10874
 
@@ -14196,6 +14771,371 @@ index cb888c4..a0c5783 100644
14196
  const width = Number(value);
14197
  if (!Number.isFinite(width)) return CHAT_CONTENT_WIDTH_DEFAULT;
14198
  return Math.max(CHAT_CONTENT_WIDTH_MIN, Math.min(CHAT_CONTENT_WIDTH_MAX, Math.round(width)));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14199
  diff --git a/lib/focus.test.mjs b/lib/focus.test.mjs
14200
  new file mode 100644
14201
  index 0000000..3208319
@@ -14291,6 +15231,64 @@ index 0000000..b77a5ee
14291
  + (event.shiftKey ? last : first).focus();
14292
  + }
14293
  +}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14294
  diff --git a/lib/i18n/messages/en.ts b/lib/i18n/messages/en.ts
14295
  index cd39a31..d2a4229 100644
14296
  --- a/lib/i18n/messages/en.ts
@@ -14627,6 +15625,611 @@ index 0000000..b0253eb
14627
  + }
14628
  + return order.map((kind) => ({ kind, count: counts.get(kind) ?? 0 })).filter((entry) => entry.count > 0);
14629
  +}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14630
  diff --git a/public/icons/apple-touch-icon.png b/public/icons/apple-touch-icon.png
14631
  index 5f7f2b155e7b5c4517b8556909f9dcbe6d9d6f40..17beb7135ed0a030d2d6e6b0342749914855c071 100644
14632
  GIT binary patch
 
94
  @media (max-width: 720px) {
95
  body { padding: 0; background: #fff; }
96
  main { min-height: 100vh; padding: 28px 22px; box-shadow: none; }
97
+ diff --git a/app/api/git/diff/route.ts b/app/api/git/diff/route.ts
98
+ index 9dc27bb..0362104 100644
99
+ --- a/app/api/git/diff/route.ts
100
+ +++ b/app/api/git/diff/route.ts
101
+ @@ -45,7 +45,7 @@ export async function GET(request: NextRequest) {
102
+ return NextResponse.json({ error: "Access denied" }, { status: 403 });
103
+ }
104
+
105
+ - return NextResponse.json(await getGitFileDiff(cwd, filePath));
106
+ + return NextResponse.json(await getGitFileDiff(cwd, filePath, { full: request.nextUrl.searchParams.get("full") === "1" }));
107
+ } catch (error) {
108
+ return NextResponse.json({ error: error instanceof Error ? error.message : String(error) }, { status: 500 });
109
+ }
110
  diff --git a/app/favicon.ico b/app/favicon.ico
111
  index 2da6b7dc00c64c59ef23cff153a6051478ad9315..b407f41443e3e94f4204a1862227e0d457f7d823 100644
112
  GIT binary patch
 
3434
  +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
3435
  +OTHER DEALINGS IN THE FONT SOFTWARE.
3436
  diff --git a/app/globals.css b/app/globals.css
3437
+ index d6b5535..e0f4e31 100644
3438
  --- a/app/globals.css
3439
  +++ b/app/globals.css
3440
  @@ -24,46 +24,109 @@
 
4185
  background: var(--bg-panel);
4186
  }
4187
  .markdown-frontmatter-title {
4188
+ @@ -2474,3 +2555,429 @@ span.token.table {
4189
  display: none !important;
4190
  }
4191
  }
 
4482
  +
4483
  +/* A diff in a tool call (MessageView UnifiedFilesView): line number, mark, code;
4484
  + added and removed lines tinted, no rules between them. */
4485
+ +/* The diff viewer (components/CodeDiff.tsx, @pierre/diffs): its shadow root reads these. The
4486
+ + design system's code type (text-code: 12px on 18px, ligatures off), Pi Web's canvas, the state
4487
+ + colours for additions and deletions, and a neutral "modified" (selection), never the library's blue. */
4488
+ +.code-diff {
4489
+ + --diffs-font-family: var(--font-mono);
4490
+ + --diffs-header-font-family: var(--font-ui);
4491
+ + --diffs-font-size: calc(12px + var(--chat-font-size-offset, 0px));
4492
+ + --diffs-line-height: 18px;
4493
+ + --diffs-font-features: "liga" 0, "calt" 0;
4494
+ + --diffs-light-bg: var(--bg);
4495
+ + --diffs-dark-bg: var(--bg);
4496
+ + --diffs-addition-color-override: var(--success);
4497
+ + --diffs-deletion-color-override: var(--danger);
4498
+ + --diffs-modified-color-override: var(--text-muted);
4499
+ + --diffs-fg-number-override: var(--text-dim);
4500
+ + --diffs-bg-separator-override: color-mix(in srgb, var(--text) 5%, var(--bg));
4501
+ + --diffs-bg-addition-override: color-mix(in srgb, var(--success) 12%, var(--bg));
4502
+ + --diffs-bg-deletion-override: color-mix(in srgb, var(--danger) 12%, var(--bg));
4503
+ + --diffs-bg-addition-emphasis-override: color-mix(in srgb, var(--success) 26%, transparent);
4504
+ + --diffs-bg-deletion-emphasis-override: color-mix(in srgb, var(--danger) 26%, transparent);
4505
+ + min-width: 0;
4506
+ + padding-block: 6px;
4507
  + overflow: auto;
4508
+ + overscroll-behavior: contain;
 
4509
  + font-weight: var(--font-mono-weight);
 
 
4510
  +}
4511
+ +.code-diff-file + .code-diff-file { margin-top: 8px; }
4512
+ +.code-diff-path {
4513
+ + padding: 6px 12px 4px;
4514
  + overflow: hidden;
4515
  + color: var(--text-muted);
4516
+ + font-family: var(--font-mono);
4517
+ + font-size: 12px;
4518
  + text-overflow: ellipsis;
4519
  + white-space: nowrap;
4520
  +}
4521
+ +/* A long diff renders the rows in view only: the virtualizer is its scroll box. */
4522
+ +.code-diff.is-virtual { overflow: visible; }
4523
+ +.code-diff.is-fill { height: 100%; padding-block: 0; }
4524
+ +.code-diff-scroll { overflow: auto; overscroll-behavior: contain; }
4525
+ +/* While the viewer's script loads: a line's height, so the step does not jump. */
4526
+ +.code-diff.is-loading { min-height: 30px; }
4527
+ +/* In the file viewer the panel scrolls, and code keeps its 12px whatever the chat's size. */
4528
+ +.code-diff.file-diff-view {
4529
+ + --diffs-font-size: 12px;
4530
+ + overflow: visible;
 
 
 
 
 
 
 
 
 
 
 
 
4531
  +}
4532
  +
4533
  +/* An error or a cut-off reply under the agent's text: a tinted note, no outline. */
 
8893
  border: "1px solid var(--border)",
8894
  background: "var(--bg-panel)",
8895
  color: "var(--text-muted)",
8896
+ diff --git a/components/CodeDiff.tsx b/components/CodeDiff.tsx
8897
+ new file mode 100644
8898
+ index 0000000..0c690de
8899
+ --- /dev/null
8900
+ +++ b/components/CodeDiff.tsx
8901
+ @@ -0,0 +1,215 @@
8902
+ +"use client";
8903
+ +
8904
+ +import { useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type ReactNode } from "react";
8905
+ +import { parsePatchFiles, registerCustomTheme, type FileDiffLoadedFiles, type ThemeRegistration } from "@pierre/diffs";
8906
+ +import { FileDiff, Virtualizer, WorkerPoolContext, type FileDiffMetadata, type FileDiffOptions, type VirtualFileMetrics } from "@pierre/diffs/react";
8907
+ +import { getOrCreateWorkerPoolSingleton, type WorkerPoolManager } from "@pierre/diffs/worker";
8908
+ +import { useTheme } from "@/hooks/useTheme";
8909
+ +import { DIFF_THEMES, neutralShikiTheme, type ShikiTheme } from "@/lib/diffs-theme";
8910
+ +import { splitFilesToPatch } from "@/lib/diff-patch";
8911
+ +import type { SplitDiffFile } from "@/lib/patch";
8912
+ +
8913
+ +/**
8914
+ + * Pi Web's diff viewer: @pierre/diffs (diffs.com), highlighted by Shiki with its JavaScript regex
8915
+ + * engine in a pool of web workers, in the design system's neutral themes (lib/diffs-theme.ts).
8916
+ + * Unified, one column of line numbers and +/- marks, as Claude Desktop shows edits; split once the
8917
+ + * viewer is 960px or wider. Inline changes are marked by word. Used for the agent's edits in the
8918
+ + * transcript and for a file's changes against HEAD in the file viewer.
8919
+ + */
8920
+ +
8921
+ +/** Side by side only where both halves have room for code. */
8922
+ +export const SPLIT_DIFF_MIN_WIDTH = 960;
8923
+ +
8924
+ +// A diff longer than this renders only the rows in view (and a margin), so a big change does not
8925
+ +// build tens of thousands of nodes at once; the estimates are the design system's metrics (an
8926
+ +// 18px line, a 24px separator row, no file header).
8927
+ +const VIRTUALIZE_AFTER_ROWS = 400;
8928
+ +const VIRTUAL_METRICS: VirtualFileMetrics = { hunkLineCount: 50, lineHeight: 18, diffHeaderHeight: 0, hunkSeparatorHeight: 24, spacing: 8 };
8929
+ +
8930
+ +// Settings the worker pool renders with; the components get the same ones, so a pool render and a
8931
+ +// main-thread render (before the pool is up, or without workers) look alike.
8932
+ +const RENDER = {
8933
+ + theme: DIFF_THEMES,
8934
+ + preferredHighlighter: "shiki-js",
8935
+ + lineDiffType: "word-alt",
8936
+ + maxLineDiffLength: 1000,
8937
+ + // Minified and generated lines are left plain rather than tokenized.
8938
+ + tokenizeMaxLineLength: 1000,
8939
+ +} as const;
8940
+ +
8941
+ +let themesRegistered = false;
8942
+ +function registerThemes() {
8943
+ + if (themesRegistered) return;
8944
+ + themesRegistered = true;
8945
+ + const load = (mode: "dark" | "light", source: () => Promise<{ default: unknown }>) => async () =>
8946
+ + neutralShikiTheme((await source()).default as ShikiTheme, mode, DIFF_THEMES[mode]) as unknown as ThemeRegistration;
8947
+ + registerCustomTheme(DIFF_THEMES.dark, load("dark", () => import("@shikijs/themes/dark-plus")));
8948
+ + registerCustomTheme(DIFF_THEMES.light, load("light", () => import("@shikijs/themes/light-plus")));
8949
+ +}
8950
+ +
8951
+ +// One pool for the page, created by the first diff shown and kept: workers start only when a diff
8952
+ +// is opened, and stay warm (grammars loaded) for the next one.
8953
+ +let pool: WorkerPoolManager | null | undefined;
8954
+ +function diffsPool(): WorkerPoolManager | undefined {
8955
+ + if (pool !== undefined) return pool ?? undefined;
8956
+ + registerThemes();
8957
+ + if (typeof window === "undefined" || typeof Worker === "undefined") return undefined;
8958
+ + try {
8959
+ + pool = getOrCreateWorkerPoolSingleton({
8960
+ + poolOptions: {
8961
+ + workerFactory: () => new Worker(new URL("@pierre/diffs/worker/worker.js", import.meta.url), { type: "module" }),
8962
+ + poolSize: Math.max(1, Math.min(2, (navigator.hardwareConcurrency || 2) - 1)),
8963
+ + },
8964
+ + highlighterOptions: { ...RENDER, langs: [] },
8965
+ + });
8966
+ + } catch {
8967
+ + pool = null;
8968
+ + }
8969
+ + return pool ?? undefined;
8970
+ +}
8971
+ +
8972
+ +// Inside the viewer's shadow root. The library sets a token's weight and style through
8973
+ +// light-dark(), which only takes colours, so a bold or italic token would stay regular: both
8974
+ +// themes mark the same tokens, so the token's own declaration is enough. Keywords are 600, as in
8975
+ +// Pi Web's other code. Separators ("13 unmodified lines") are a quiet 24px row in small type.
8976
+ +const UNSAFE_CSS = `
8977
+ +[data-line] span[style*="font-weight:bold"] { font-weight: 600; }
8978
+ +[data-line] span[style*="font-style:italic"] { font-style: italic; }
8979
+ +[data-separator=line-info-basic] { height: 24px; }
8980
+ +[data-separator-content] { font-size: 12px; }
8981
+ +[data-expand-index] [data-separator-wrapper] { grid-template-columns: 28px auto; }
8982
+ +[data-expand-button]:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }
8983
+ +`;
8984
+ +
8985
+ +// The library's expand controls are role=button divs out of the tab order: give them a place in
8986
+ +// it, a name and the keys a button has.
8987
+ +const EXPAND_LABELS: Array<[string, string]> = [
8988
+ + ["data-expand-up", "Show the lines above"],
8989
+ + ["data-expand-down", "Show the lines below"],
8990
+ + ["data-expand-both", "Show the unmodified lines"],
8991
+ +];
8992
+ +function keyboardExpanders(host: HTMLElement) {
8993
+ + for (const button of host.shadowRoot?.querySelectorAll<HTMLElement>("[data-expand-button]") ?? []) {
8994
+ + if (button.dataset.keyboard !== undefined) continue;
8995
+ + button.dataset.keyboard = "";
8996
+ + button.tabIndex = 0;
8997
+ + const label = EXPAND_LABELS.find(([attribute]) => button.hasAttribute(attribute))?.[1] ?? EXPAND_LABELS[2][1];
8998
+ + button.setAttribute("aria-label", label);
8999
+ + button.addEventListener("keydown", (event) => {
9000
+ + if (event.key !== "Enter" && event.key !== " ") return;
9001
+ + event.preventDefault();
9002
+ + button.click();
9003
+ + });
9004
+ + }
9005
+ +}
9006
+ +
9007
+ +/** A unified patch, or Pi Web's split diff rows. */
9008
+ +export type CodeDiffSource = { patch: string } | { files: SplitDiffFile[] };
9009
+ +
9010
+ +/** The whole file before and after, for expanding the unchanged lines between hunks. */
9011
+ +export type FullFilesLoader = () => Promise<{ oldContents: string; newContents: string } | null>;
9012
+ +
9013
+ +export function CodeDiff({
9014
+ + source,
9015
+ + overflow = "wrap",
9016
+ + maxHeight,
9017
+ + fallback = null,
9018
+ + loadFullFiles,
9019
+ + fill = false,
9020
+ + className,
9021
+ + style,
9022
+ +}: {
9023
+ + source: CodeDiffSource;
9024
+ + /** Long lines wrap (the transcript) or scroll sideways (the file viewer's no-wrap mode). */
9025
+ + overflow?: "wrap" | "scroll";
9026
+ + maxHeight?: number;
9027
+ + /** Shown when the source holds no diff (a tool's result that is not a patch after all). */
9028
+ + fallback?: ReactNode;
9029
+ + /** Given, the unchanged lines between hunks can be expanded; called on the first expansion. */
9030
+ + loadFullFiles?: FullFilesLoader;
9031
+ + /** Fill the parent's height and scroll inside it (the file viewer's panel). */
9032
+ + fill?: boolean;
9033
+ + className?: string;
9034
+ + style?: CSSProperties;
9035
+ +}) {
9036
+ + const { isDark } = useTheme();
9037
+ + const ref = useRef<HTMLDivElement | null>(null);
9038
+ + const [wide, setWide] = useState(false);
9039
+ + useLayoutEffect(() => {
9040
+ + const el = ref.current;
9041
+ + if (!el || typeof ResizeObserver === "undefined") return;
9042
+ + const update = () => setWide(el.clientWidth >= SPLIT_DIFF_MIN_WIDTH);
9043
+ + update();
9044
+ + const observer = new ResizeObserver(update);
9045
+ + observer.observe(el);
9046
+ + return () => observer.disconnect();
9047
+ + }, []);
9048
+ +
9049
+ + const { files, lineNumbers } = useMemo(() => parseSource(source), [source]);
9050
+ + const workers = useMemo(() => diffsPool(), []);
9051
+ + const options = useMemo<FileDiffOptions<undefined, undefined>>(() => ({
9052
+ + ...RENDER,
9053
+ + themeType: isDark ? "dark" : "light",
9054
+ + diffStyle: wide ? "split" : "unified",
9055
+ + diffIndicators: "classic",
9056
+ + hunkSeparators: "line-info-basic",
9057
+ + overflow,
9058
+ + disableFileHeader: true,
9059
+ + disableLineNumbers: !lineNumbers,
9060
+ + unsafeCSS: UNSAFE_CSS,
9061
+ + onPostRender: (host, _instance, phase) => {
9062
+ + if (phase !== "unmount") keyboardExpanders(host);
9063
+ + },
9064
+ + loadDiffFiles: loadFullFiles ? async (fileDiff): Promise<FileDiffLoadedFiles> => {
9065
+ + const full = await loadFullFiles();
9066
+ + if (!full) throw new Error("the whole file is not available");
9067
+ + return {
9068
+ + oldFile: { name: fileDiff.prevName ?? fileDiff.name, contents: full.oldContents },
9069
+ + newFile: { name: fileDiff.name, contents: full.newContents },
9070
+ + };
9071
+ + } : undefined,
9072
+ + }), [isDark, wide, overflow, lineNumbers, loadFullFiles]);
9073
+ +
9074
+ + if (!files) return <>{fallback}</>;
9075
+ + const rows = files.reduce((total, file) => total + (wide ? file.splitLineCount : file.unifiedLineCount), 0);
9076
+ + const virtual = rows > VIRTUALIZE_AFTER_ROWS;
9077
+ + const body = files.map((file, index) => (
9078
+ + <div key={`${index}:${file.name}`} className="code-diff-file">
9079
+ + {files.length > 1 && <div className="code-diff-path" title={file.name}>{file.name}</div>}
9080
+ + <FileDiff fileDiff={file} options={options} metrics={virtual ? VIRTUAL_METRICS : undefined} />
9081
+ + </div>
9082
+ + ));
9083
+ + const classes = `code-diff${fill ? " is-fill" : ""}${virtual ? " is-virtual" : ""}${className ? ` ${className}` : ""}`;
9084
+ + return (
9085
+ + <WorkerPoolContext.Provider value={workers}>
9086
+ + <div ref={ref} className={classes} style={virtual ? style : { maxHeight, ...style }}>
9087
+ + {virtual ? (
9088
+ + <Virtualizer className="code-diff-scroll" style={fill ? { height: "100%" } : { maxHeight }}>{body}</Virtualizer>
9089
+ + ) : body}
9090
+ + </div>
9091
+ + </WorkerPoolContext.Provider>
9092
+ + );
9093
+ +}
9094
+ +
9095
+ +/** The files a source holds, or null when it parses to none (show the raw text instead). */
9096
+ +export function parseSource(source: CodeDiffSource): { files: FileDiffMetadata[] | null; lineNumbers: boolean } {
9097
+ + const { patch, lineNumbers } = "patch" in source ? { patch: source.patch, lineNumbers: true } : splitFilesToPatch(source.files);
9098
+ + // Keyed by content, so the workers' result cache serves a diff shown again (a reopened step).
9099
+ + const key = `pi-${hashText(patch)}`;
9100
+ + try {
9101
+ + const files = parsePatchFiles(patch, key, true).flatMap((parsed) => parsed.files).filter((file) => file.hunks.length > 0);
9102
+ + return { files: files.length > 0 ? files : null, lineNumbers };
9103
+ + } catch {
9104
+ + return { files: null, lineNumbers };
9105
+ + }
9106
+ +}
9107
+ +
9108
+ +/** FNV-1a, 32 bits, hex: a cache key, not a checksum. */
9109
+ +function hashText(text: string): string {
9110
+ + let h = 0x811c9dc5;
9111
+ + for (let i = 0; i < text.length; i++) {
9112
+ + h ^= text.charCodeAt(i);
9113
+ + h = Math.imul(h, 0x01000193);
9114
+ + }
9115
+ + return (h >>> 0).toString(16) + text.length.toString(16);
9116
+ +}
9117
+ diff --git a/components/CodeDiffLazy.tsx b/components/CodeDiffLazy.tsx
9118
+ new file mode 100644
9119
+ index 0000000..ca27152
9120
+ --- /dev/null
9121
+ +++ b/components/CodeDiffLazy.tsx
9122
+ @@ -0,0 +1,20 @@
9123
+ +"use client";
9124
+ +
9125
+ +import dynamic from "next/dynamic";
9126
+ +
9127
+ +/**
9128
+ + * The diff viewer (CodeDiff: @pierre/diffs and Shiki's engine, about 1 MB of script) loaded on
9129
+ + * demand, so a page load without a diff does not pay for it. It is fetched once the page is idle,
9130
+ + * so the first diff opened does not wait for it either.
9131
+ + */
9132
+ +const load = () => import("./CodeDiff").then((module) => module.CodeDiff);
9133
+ +
9134
+ +export const CodeDiff = dynamic(load, {
9135
+ + ssr: false,
9136
+ + loading: () => <div className="code-diff is-loading" aria-busy="true" />,
9137
+ +});
9138
+ +
9139
+ +if (typeof window !== "undefined") {
9140
+ + const whenIdle = window.requestIdleCallback ?? ((callback: () => void) => window.setTimeout(callback, 2000));
9141
+ + whenIdle(() => void load());
9142
+ +}
9143
  diff --git a/components/DirectoryPicker.tsx b/components/DirectoryPicker.tsx
9144
  index 433cd89..344b0c2 100644
9145
  --- a/components/DirectoryPicker.tsx
 
9654
 
9655
  export function FolderIcon({ size = 14, open = false }: IconProps & { open?: boolean }) {
9656
  diff --git a/components/FileViewer.tsx b/components/FileViewer.tsx
9657
+ index 9426211..42f0dac 100644
9658
  --- a/components/FileViewer.tsx
9659
  +++ b/components/FileViewer.tsx
9660
+ @@ -6,6 +6,8 @@ import SyntaxHighlighter from "react-syntax-highlighter/dist/esm/prism-light";
9661
  import renderSyntaxNode from "react-syntax-highlighter/dist/esm/create-element";
9662
  import { vs } from "react-syntax-highlighter/dist/cjs/styles/prism";
9663
  import { vscDarkPlus } from "react-syntax-highlighter/dist/cjs/styles/prism";
9664
  +import { neutralCodeTheme } from "@/lib/neutral-code-theme";
9665
+ +import { CodeDiff } from "./CodeDiffLazy";
9666
  import ReactMarkdown from "react-markdown";
9667
  import { useTheme } from "@/hooks/useTheme";
9668
  import { usePrismLanguages } from "@/hooks/usePrismLanguages";
9669
+ @@ -26,7 +28,6 @@ import { CodeBlock, MermaidBlock } from "./MermaidBlock";
9670
+ import { DelimitedTable } from "./DelimitedTable";
9671
+ import { isDelimitedTablePath } from "@/lib/delimited-table";
9672
+ import { FrontmatterCard } from "./FrontmatterCard";
9673
+ -import { parseUnifiedPatch } from "@/lib/patch";
9674
+ import type { GitFileDiffResponse } from "@/lib/git-types";
9675
+ import { useI18n } from "@/hooks/useI18n";
9676
+ import {
9677
  @@ -34,6 +35,8 @@ import {
9678
  type FileViewerDisplayMode as DisplayMode,
9679
  type FileViewerState,
 
9740
  );
9741
  }
9742
 
9743
+ @@ -252,196 +259,46 @@ function DownloadLink({ filePath, sourceSessionId }: { filePath: string; sourceS
9744
  aria-label={t("i18n.downloadFile")}
9745
  className="file-viewer-icon-button"
9746
  >
 
9753
  </a>
9754
  );
9755
  }
9756
+
9757
+ -type DiffLine = {
9758
+ - type: "unchanged" | "removed" | "added";
9759
+ - text: string;
9760
+ - oldLineNo: number | null;
9761
+ - newLineNo: number | null;
9762
+ -};
9763
+ -
9764
+ function formatSize(bytes: number): string {
9765
+ if (bytes < 1024) return `${bytes} B`;
9766
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
9767
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
9768
+ }
9769
+
9770
+ -function diffLines(patch: string): DiffLine[] {
9771
+ - const files = parseUnifiedPatch(patch);
9772
+ - if (!files) return [];
9773
+ -
9774
+ - return files.flatMap((file) => file.rows.flatMap((row): DiffLine[] => {
9775
+ - if (row.type === "hunk") return [];
9776
+ - if (row.left.type === "context" && row.right.type === "context") {
9777
+ - return [{
9778
+ - type: "unchanged",
9779
+ - text: row.right.text,
9780
+ - oldLineNo: row.left.lineNo,
9781
+ - newLineNo: row.right.lineNo,
9782
+ - }];
9783
+ - }
9784
+ -
9785
+ - const lines: DiffLine[] = [];
9786
+ - if (row.left.type === "removed") {
9787
+ - lines.push({
9788
+ - type: "removed",
9789
+ - text: row.left.text,
9790
+ - oldLineNo: row.left.lineNo,
9791
+ - newLineNo: null,
9792
+ - });
9793
+ - }
9794
+ - if (row.right.type === "added") {
9795
+ - lines.push({
9796
+ - type: "added",
9797
+ - text: row.right.text,
9798
+ - oldLineNo: null,
9799
+ - newLineNo: row.right.lineNo,
9800
+ - });
9801
+ - }
9802
+ - return lines;
9803
+ - }));
9804
+ -}
9805
+ -
9806
+ -function DiffView({ patch }: { patch: string }) {
9807
+ +/**
9808
+ + * A file's changes against HEAD in the diff viewer (CodeDiff). Unchanged lines between hunks
9809
+ + * expand on demand: the first expansion fetches both whole versions of the file.
9810
+ + */
9811
+ +function FileChangesView({ patch, cwd, filePath, wrapLines }: { patch: string; cwd?: string; filePath: string; wrapLines: boolean }) {
9812
+ const { t } = useI18n();
9813
+ - const diff = diffLines(patch);
9814
+ -
9815
+ - const hasChanges = diff.some((l) => l.type !== "unchanged");
9816
+ - if (!hasChanges) {
9817
+ - return (
9818
+ - <div style={{ padding: "12px 16px", fontSize: 12, color: "var(--text-dim)", fontFamily: "var(--font-mono)" }}>
9819
+ - {t("i18n.noChanges")}
9820
+ - </div>
9821
+ - );
9822
+ - }
9823
+ -
9824
+ - // Render with context: show 3 lines around each change, collapse the rest
9825
+ - const CONTEXT = 3;
9826
+ - const changed = new Set(diff.flatMap((l, i) => (l.type !== "unchanged" ? [i] : [])));
9827
+ - const visible = new Set<number>();
9828
+ - for (const ci of changed) {
9829
+ - for (let j = Math.max(0, ci - CONTEXT); j <= Math.min(diff.length - 1, ci + CONTEXT); j++) {
9830
+ - visible.add(j);
9831
+ - }
9832
+ - }
9833
+ -
9834
+ - const segments: Array<{ hidden: true; count: number } | { hidden: false; lines: DiffLine[] }> = [];
9835
+ - let i = 0;
9836
+ - while (i < diff.length) {
9837
+ - if (visible.has(i)) {
9838
+ - const block: DiffLine[] = [];
9839
+ - while (i < diff.length && visible.has(i)) {
9840
+ - block.push(diff[i]);
9841
+ - i++;
9842
+ - }
9843
+ - segments.push({ hidden: false, lines: block });
9844
+ - } else {
9845
+ - let count = 0;
9846
+ - while (i < diff.length && !visible.has(i)) {
9847
+ - count++;
9848
+ - i++;
9849
+ - }
9850
+ - segments.push({ hidden: true, count });
9851
+ - }
9852
+ - }
9853
+ -
9854
+ + const source = useMemo(() => ({ patch }), [patch]);
9855
+ + const loadFullFiles = useCallback(async () => {
9856
+ + if (!cwd) return null;
9857
+ + const params = new URLSearchParams({ cwd, path: filePath, full: "1" });
9858
+ + const response = await fetch(`/api/git/diff?${params.toString()}`);
9859
+ + const next = await response.json() as GitFileDiffResponse;
9860
+ + return response.ok && typeof next.oldContent === "string" && typeof next.newContent === "string"
9861
+ + ? { oldContents: next.oldContent, newContents: next.newContent }
9862
+ + : null;
9863
+ + }, [cwd, filePath]);
9864
+ return (
9865
+ - <div
9866
+ + <CodeDiff
9867
+ + source={source}
9868
+ className="file-diff-view"
9869
+ - style={{
9870
+ - width: "max-content",
9871
+ - minWidth: "100%",
9872
+ - ...FILE_CODE_STYLE,
9873
+ - }}
9874
+ - >
9875
+ - {segments.map((seg, si) => {
9876
+ - if (seg.hidden) {
9877
+ - const result = (
9878
+ - <div
9879
+ - key={si}
9880
+ - style={{
9881
+ - padding: "2px 16px",
9882
+ - color: "var(--text-dim)",
9883
+ - background: "var(--bg-panel)",
9884
+ - fontSize: 11,
9885
+ - borderTop: "1px solid var(--border)",
9886
+ - borderBottom: "1px solid var(--border)",
9887
+ - }}
9888
+ - >
9889
+ - ... {seg.count} unchanged lines ...
9890
+ - </div>
9891
+ - );
9892
+ - return result;
9893
+ - }
9894
+ - const lines = seg.lines.map((line, li) => {
9895
+ - const bg =
9896
+ - line.type === "added"
9897
+ - ? "rgba(0,200,80,0.12)"
9898
+ - : line.type === "removed"
9899
+ - ? "rgba(240,60,60,0.14)"
9900
+ - : "transparent";
9901
+ - const prefix =
9902
+ - line.type === "added" ? "+" : line.type === "removed" ? "-" : " ";
9903
+ - const prefixColor =
9904
+ - line.type === "added" ? "#4ade80" : line.type === "removed" ? "#f87171" : "var(--text-dim)";
9905
+ -
9906
+ - return (
9907
+ - <div
9908
+ - key={li}
9909
+ - className="file-diff-line"
9910
+ - style={{
9911
+ - display: "flex",
9912
+ - minWidth: "100%",
9913
+ - background: bg,
9914
+ - borderLeft: line.type === "added"
9915
+ - ? "3px solid #4ade80"
9916
+ - : line.type === "removed"
9917
+ - ? "3px solid #f87171"
9918
+ - : "3px solid transparent",
9919
+ - }}
9920
+ - >
9921
+ - <span
9922
+ - style={FILE_LINE_NUMBER_STYLE}
9923
+ - >
9924
+ - {line.type === "removed" ? line.oldLineNo : line.newLineNo}
9925
+ - </span>
9926
+ - <span
9927
+ - style={{
9928
+ - minWidth: 16,
9929
+ - padding: "0 6px",
9930
+ - color: prefixColor,
9931
+ - userSelect: "none",
9932
+ - flexShrink: 0,
9933
+ - fontWeight: 600,
9934
+ - }}
9935
+ - >
9936
+ - {prefix}
9937
+ - </span>
9938
+ - <span
9939
+ - className="file-diff-line-content"
9940
+ - style={{
9941
+ - flexShrink: 0,
9942
+ - padding: "0 8px 0 0",
9943
+ - whiteSpace: "pre",
9944
+ - color: "var(--text)",
9945
+ - }}
9946
+ - >
9947
+ - {line.text || "\u00a0"}
9948
+ - </span>
9949
+ - </div>
9950
+ - );
9951
+ - });
9952
+ - return <div key={si}>{lines}</div>;
9953
+ - })}
9954
+ - </div>
9955
+ + fill
9956
+ + overflow={wrapLines ? "wrap" : "scroll"}
9957
+ + loadFullFiles={loadFullFiles}
9958
+ + fallback={(
9959
+ + <div style={{ padding: "12px 16px", fontSize: 12, color: "var(--text-dim)", fontFamily: "var(--font-mono)" }}>
9960
+ + {t("i18n.noChanges")}
9961
+ + </div>
9962
+ + )}
9963
+ + />
9964
+ );
9965
+ }
9966
+
9967
+ @@ -1442,7 +1299,7 @@ function TextFileViewer({
9968
  <SyntaxHighlighter
9969
  className={wrapLines ? "file-source-view is-wrapped" : "file-source-view"}
9970
  language={language === "text" || !prismReady ? "plaintext" : language}
 
9973
  showLineNumbers
9974
  lineNumberStyle={{
9975
  ...FILE_LINE_NUMBER_STYLE,
9976
+ @@ -1708,12 +1565,7 @@ function TextFileViewer({
9977
  color: wrapLines ? "var(--text)" : "var(--text-muted)",
9978
  }}
9979
  >
 
9987
  </button>
9988
  </>
9989
  )}
9990
+ @@ -1733,7 +1585,7 @@ function TextFileViewer({
9991
  gap: 10,
9992
  padding: "5px 8px",
9993
  border: "1px solid var(--border)",
 
9996
  color: "var(--text-dim)",
9997
  fontSize: 11,
9998
  }}
9999
+ @@ -1764,7 +1616,7 @@ function TextFileViewer({
10000
+ style={{ flex: 1, overflow: "auto", background: "var(--bg)", paddingBottom: showLoadMore ? 48 : undefined }}
10001
+ >
10002
+ {effectiveDisplayMode === "diff" && hasGitDiff ? (
10003
+ - <DiffView patch={gitDiff.patch!} />
10004
+ + <FileChangesView patch={gitDiff.patch!} cwd={cwd} filePath={filePath} wrapLines={wrapLines} />
10005
+ ) : isHtml && effectiveDisplayMode === "preview" && data?.truncated && !htmlFull?.text ? (
10006
+ <div style={{ padding: 24, color: "var(--text-dim)", fontSize: 12 }}>
10007
+ {htmlFull?.error ?? t("i18n.loading")}
10008
  diff --git a/components/FontSettings.tsx b/components/FontSettings.tsx
10009
  index 7e4c208..960fc5e 100644
10010
  --- a/components/FontSettings.tsx
 
10181
 
10182
  test("collapses a displayed custom message from its header alone", () => {
10183
  diff --git a/components/MessageView.tsx b/components/MessageView.tsx
10184
+ index f2ff1de..82a4551 100644
10185
  --- a/components/MessageView.tsx
10186
  +++ b/components/MessageView.tsx
10187
+ @@ -5,11 +5,13 @@ import ReactMarkdown from "react-markdown";
 
 
 
 
 
10188
  import { MarkdownBody } from "./MarkdownBody";
10189
  import { ImagePreview } from "./ImagePreview";
10190
  import { ThinkingIcon } from "./ThinkingIcon";
 
10192
  import { copyText } from "@/lib/clipboard";
10193
  import { useI18n } from "@/hooks/useI18n";
10194
  import { parseCompactionSummary } from "@/lib/compaction-summary";
10195
+ import { getAssistantErrorMessage, getThinkingPreview, hasAssistantAnswer, isAssistantTruncated, isEmptyThinkingBlock } from "@/lib/message-display";
10196
+ -import { parseUnifiedPatch, type SplitDiffCell, type SplitDiffFile } from "@/lib/patch";
10197
+ +import type { SplitDiffFile } from "@/lib/patch";
10198
+ +import { CodeDiff } from "./CodeDiffLazy";
10199
+ import { applyPatchPreviewToFiles, applyPatchResultHasFailures, extractApplyPatchPaths, getApplyPatchInputText, parseApplyPatchInput } from "@/lib/apply-patch";
10200
+ import { isApplyPatchToolName, isEditToolName, isWriteToolName } from "@/lib/tool-names";
10201
+ import { isToolCallExpanded, setToolCallExpanded } from "@/lib/tool-call-expansion";
10202
+ @@ -35,6 +37,8 @@ import type {
10203
  ToolCallContent,
10204
  ThinkingContent,
10205
  } from "@/lib/types";
 
10208
 
10209
  // CJK chars ~1 token each (GLM/DeepSeek/GPT-o200k); other chars ~4 chars/token.
10210
  const CJK_PATTERN = /[\u3000-\u30ff\u3400-\u9fff\uf900-\ufaff\u{20000}-\u{2fa1f}\uac00-\ud7af]/u;
10211
+ @@ -122,7 +126,7 @@ function SafeMarkdownBody({ children, className, ...props }: React.ComponentProp
10212
  margin: "4px 0",
10213
  padding: "7px 10px",
10214
  border: "1px solid var(--border)",
 
10217
  background: "var(--bg-panel)",
10218
  color: "var(--text-muted)",
10219
  cursor: "pointer",
10220
+ @@ -213,6 +217,19 @@ interface Props {
10221
  onCompact?: () => void;
10222
  isCompacting?: boolean;
10223
  compactError?: string | null;
 
10237
  }
10238
 
10239
  export function getModelDisplayName(
10240
+ @@ -280,12 +297,12 @@ function haveSameRelevantToolResults(
10241
  return true;
10242
  }
10243
 
 
10252
  }
10253
  if (message.role === "toolResult") {
10254
  // Rendered inline under its toolCall — skip standalone rendering if paired
10255
+ @@ -322,9 +339,18 @@ export const MessageView = memo(function MessageView({ message, isStreaming, too
10256
  && prev.sessionId === next.sessionId
10257
  && prev.onCompact === next.onCompact
10258
  && prev.isCompacting === next.isCompacting
 
10272
  function UserMessageView({ message, cwd, onOpenFile, entryId, onFork, forking, onEditContent, onCancelEdit, isEditing }: {
10273
  message: UserMessage;
10274
  cwd?: string;
10275
+ @@ -337,7 +363,6 @@ function UserMessageView({ message, cwd, onOpenFile, entryId, onFork, forking, o
10276
  isEditing?: boolean;
10277
  }) {
10278
  const { t } = useI18n();
 
10280
  const [copied, setCopied] = useState(false);
10281
  const [expanded, setExpanded] = useState(false);
10282
 
10283
+ @@ -391,7 +416,7 @@ function UserMessageView({ message, cwd, onOpenFile, entryId, onFork, forking, o
10284
  <img
10285
  src={src}
10286
  alt=""
 
10289
  />
10290
  </ImagePreview>
10291
  );
10292
+ @@ -409,228 +434,120 @@ function UserMessageView({ message, cwd, onOpenFile, entryId, onFork, forking, o
10293
  };
10294
 
10295
  return (
 
10621
  </div>
10622
  );
10623
  }
10624
+ @@ -652,6 +569,8 @@ function AssistantMessageView({
10625
  onCompact,
10626
  isCompacting,
10627
  compactError,
 
10630
  }: {
10631
  message: AssistantMessage;
10632
  isStreaming?: boolean;
10633
+ @@ -669,6 +588,8 @@ function AssistantMessageView({
10634
  onCompact?: () => void;
10635
  isCompacting?: boolean;
10636
  compactError?: string | null;
 
10639
  }) {
10640
  const { t } = useI18n();
10641
  const time = showTimestamp ? formatTime(message.timestamp) : null;
10642
+ @@ -679,7 +600,6 @@ function AssistantMessageView({
10643
  const providerError = getAssistantErrorMessage(message, { isStreaming });
10644
  const truncated = isAssistantTruncated(message, { isStreaming });
10645
  const unansweredTruncation = truncated && !hasAssistantAnswer(message);
 
10647
  const [copied, setCopied] = useState(false);
10648
  const streamStartRef = useRef<StreamRateStart | null>(null);
10649
  const rateKey = streamRateKey(message);
10650
+ @@ -803,123 +723,59 @@ function AssistantMessageView({
10651
 
10652
  if (blocks.length === 0 && !isStreaming && !providerError && !truncated) return null;
10653
 
 
10796
  )}
10797
  </div>
10798
  )}
10799
+ @@ -928,51 +784,28 @@ function AssistantMessageView({
10800
  <TurnWrittenFiles files={writtenFiles} onOpenFile={onOpenFile} />
10801
  )}
10802
 
 
10866
  </div>
10867
  );
10868
  }
10869
+ @@ -1052,62 +885,34 @@ export function ThinkingBlock({ block, duration, sessionId, entryId, blockIndex
10870
  }, [expanded, block.deferred, content, sessionId, entryId, blockIndex]);
10871
 
10872
  return (
 
10953
  </div>
10954
  );
10955
  }
10956
+ @@ -1176,136 +981,131 @@ function ToolCallBlock({ block, result, duration, onOpenSubagent }: { block: Too
10957
  const subagent = isSubagentToolDetails(result?.details) ? result.details : null;
10958
  const codemodeCallCount = codemode ? codemode.calls.length + codemode.omitted : 0;
10959
 
 
11131
  + {/* ── Applied-patch split diff ── */}
11132
  + {patchFiles && (
11133
  + <div style={{ background: "var(--bg)" }}>
11134
+ + <PatchFilesView files={patchFiles} />
11135
  + </div>
11136
  + )}
11137
  +
 
11179
  interface ResultDiff {
11180
  text: string;
11181
  }
11182
+ @@ -1316,7 +1116,6 @@ function PairedDiffResult({ diff }: {
11183
  return (
11184
  <div
11185
  style={{
 
11187
  background: "var(--bg)",
11188
  }}
11189
  >
11190
+ @@ -1325,148 +1124,16 @@ function PairedDiffResult({ diff }: {
11191
+ );
11192
  }
11193
 
11194
+ +/** A tool's patch in the diff viewer; text that is not a patch, as it is. */
11195
+ function SplitPatchView({ text }: { text: string }) {
11196
+ - const files = useMemo(() => parseUnifiedPatch(text), [text]);
11197
+ - if (!files) return <PatchTextView text={text} />;
11198
+ - return <SplitFilesView files={files} />;
11199
+ -}
11200
+ -
11201
+ -function SplitFilesView({ files }: { files: SplitDiffFile[] }) {
11202
+ - const { t } = useI18n();
11203
+ - const showFileHeaders = files.length > 1;
11204
+ -
11205
+ - return (
11206
+ - <div style={{ maxHeight: 560, overflowY: "auto", overflowX: "hidden", background: "var(--bg)" }}>
11207
+ - {files.map((file, fileIndex) => (
11208
+ - <div
11209
+ - key={fileIndex}
11210
+ - style={{
11211
+ - minWidth: 0,
11212
+ - borderTop: fileIndex === 0 ? "none" : "1px solid var(--border)",
11213
+ - fontFamily: "var(--font-mono)",
11214
+ - fontWeight: "var(--font-mono-weight)",
11215
+ - fontSize: "calc(12px + var(--chat-font-size-offset, 0px))",
11216
+ - lineHeight: 1.55,
11217
+ - }}
11218
+ - >
11219
+ - {showFileHeaders && (
11220
+ - <div
11221
+ - style={{
11222
+ - display: "grid",
11223
+ - gridTemplateColumns: "minmax(0, 1fr) minmax(0, 1fr)",
11224
+ - position: "sticky",
11225
+ - top: 0,
11226
+ - zIndex: 1,
11227
+ - background: "var(--bg-panel)",
11228
+ - borderBottom: "1px solid var(--border)",
11229
+ - }}
11230
+ - >
11231
+ - <SplitDiffHeader title={file.oldPath || t("i18n.before")} side="left" />
11232
+ - <SplitDiffHeader title={file.newPath || t("i18n.after")} side="right" />
11233
+ - </div>
11234
+ - )}
11235
+ -
11236
+ - <div style={{ display: "grid", gridTemplateColumns: "minmax(0, 1fr) minmax(0, 1fr)" }}>
11237
+ - {file.rows.map((row, rowIndex) => {
11238
+ - if (row.type === "hunk") {
11239
+ - return null;
11240
+ - }
11241
+ -
11242
+ - return (
11243
+ - <div key={rowIndex} style={{ display: "contents" }}>
11244
+ - <SplitDiffCellView cell={row.left} side="left" />
11245
+ - <SplitDiffCellView cell={row.right} side="right" />
11246
+ - </div>
11247
+ - );
11248
+ - })}
11249
+ - </div>
11250
+ - </div>
11251
+ - ))}
11252
+ - </div>
11253
+ - );
11254
+ + const source = useMemo(() => ({ patch: text }), [text]);
11255
+ + return <CodeDiff source={source} maxHeight={560} fallback={<PatchTextView text={text} />} />;
11256
+ }
11257
+
11258
+ -function SplitDiffHeader({ title, side }: { title: string; side: "left" | "right" }) {
11259
+ - return (
11260
+ - <div
11261
+ - title={title}
11262
+ - style={{
11263
+ - padding: "5px 10px",
11264
+ - color: "var(--text-dim)",
11265
+ - borderRight: side === "left" ? "1px solid var(--border)" : "none",
11266
+ - overflow: "hidden",
11267
+ - textOverflow: "ellipsis",
11268
+ - whiteSpace: "nowrap",
11269
+ - }}
11270
+ - >
11271
+ - {title}
11272
+ - </div>
11273
+ - );
11274
+ -}
11275
+ -
11276
+ -function SplitDiffCellView({ cell, side }: { cell: SplitDiffCell; side: "left" | "right" }) {
11277
+ - const bg =
11278
+ - cell.type === "added"
11279
+ - ? "rgba(34,197,94,0.12)"
11280
+ - : cell.type === "removed"
11281
+ - ? "rgba(248,113,113,0.13)"
11282
+ - : cell.type === "empty"
11283
+ - ? "var(--bg-subtle)"
11284
+ - : "transparent";
11285
+ - const marker =
11286
+ - cell.type === "added" ? "+" : cell.type === "removed" ? "-" : " ";
11287
+ - const markerColor =
11288
+ - cell.type === "added" ? "#22c55e" : cell.type === "removed" ? "#f87171" : "var(--text-dim)";
11289
+ -
11290
+ - return (
11291
+ - <div
11292
+ - style={{
11293
+ - display: "flex",
11294
+ - minWidth: 0,
11295
+ - background: bg,
11296
+ - borderRight: side === "left" ? "1px solid var(--border)" : "none",
11297
+ - }}
11298
+ - >
11299
+ - <span
11300
+ - style={{
11301
+ - width: 42,
11302
+ - padding: "0 6px",
11303
+ - textAlign: "right",
11304
+ - color: "var(--text-dim)",
11305
+ - userSelect: "none",
11306
+ - background: "var(--bg-panel)",
11307
+ - borderRight: "1px solid var(--border)",
11308
+ - flexShrink: 0,
11309
+ - }}
11310
+ - >
11311
+ - {cell.lineNo ?? ""}
11312
+ - </span>
11313
+ - <span
11314
+ - style={{
11315
+ - width: 18,
11316
+ - padding: "0 5px",
11317
+ - color: markerColor,
11318
+ - userSelect: "none",
11319
+ - fontWeight: cell.type === "context" || cell.type === "empty" ? 400 : 700,
11320
+ - flexShrink: 0,
11321
+ - }}
11322
+ - >
11323
+ - {marker}
11324
+ - </span>
11325
+ - <span
11326
+ - style={{
11327
+ - flex: 1,
11328
+ - minWidth: 0,
11329
+ - padding: "0 10px 0 0",
11330
+ - color: cell.type === "empty" ? "var(--text-dim)" : "var(--text)",
11331
+ - whiteSpace: "pre-wrap",
11332
+ - overflowWrap: "anywhere",
11333
+ - }}
11334
+ - >
11335
+ - {cell.text || "\u00a0"}
11336
+ - </span>
11337
+ - </div>
11338
+ - );
11339
+ +/** An apply_patch call's files in the diff viewer. */
11340
+ +function PatchFilesView({ files }: { files: SplitDiffFile[] }) {
11341
+ + const source = useMemo(() => ({ files }), [files]);
11342
+ + return <CodeDiff source={source} maxHeight={560} />;
11343
+ }
11344
 
11345
+ function PatchTextView({ text }: { text: string }) {
11346
+ @@ -1483,12 +1150,12 @@ function PatchTextView({ text }: { text: string }) {
11347
  const bg =
11348
  kind === "added" ? "rgba(34,197,94,0.12)" :
11349
  kind === "removed" ? "rgba(248,113,113,0.13)" :
 
11358
  "var(--text)";
11359
 
11360
  return (
11361
+ @@ -1502,7 +1169,7 @@ function PatchTextView({ text }: { text: string }) {
11362
  : kind === "removed"
11363
  ? "3px solid #f87171"
11364
  : kind === "hunk"
 
11367
  : "3px solid transparent",
11368
  }}
11369
  >
11370
+ @@ -1587,7 +1254,6 @@ function ResultImages({ images, isError }: { images: ImageContent[]; isError: bo
11371
  flexWrap: "wrap",
11372
  padding: "10px",
11373
  background: "var(--bg)",
 
11375
  }}
11376
  >
11377
  {images.map((image, index) => {
11378
+ @@ -1608,7 +1274,7 @@ function ResultImages({ images, isError }: { images: ImageContent[]; isError: bo
11379
  display: "block",
11380
  maxWidth: "min(100%, 720px)",
11381
  maxHeight: 520,
 
11384
  objectFit: "contain",
11385
  border: "1px solid var(--border)",
11386
  }}
11387
+ @@ -1629,8 +1295,7 @@ function PairedResult({ text, isEmpty, isError }: {
11388
  return (
11389
  <div
11390
  style={{
 
11394
  }}
11395
  >
11396
  <pre
11397
+ @@ -1668,7 +1333,7 @@ function CompactionMessageView({ message }: { message: CustomMessage }) {
11398
  <div
11399
  style={{
11400
  border: "1px solid var(--border)",
 
11403
  overflow: "hidden",
11404
  background: "var(--bg)",
11405
  }}
11406
+ @@ -1710,9 +1375,7 @@ function CompactionMessageView({ message }: { message: CustomMessage }) {
11407
  textAlign: "left",
11408
  }}
11409
  >
 
11414
  <span style={{ minWidth: 0 }}>
11415
  <span style={{ display: "block", fontSize: "calc(15px + var(--chat-font-size-offset, 0px))", fontWeight: 700, lineHeight: 1.35 }}>
11416
  {t("i18n.conversationCompacted")}
11417
+ @@ -1806,7 +1469,7 @@ function CustomMessageView({ message, cwd, onOpenFile }: { message: CustomMessag
11418
  <div
11419
  style={{
11420
  border: "1px solid var(--border)",
 
11423
  overflow: "hidden",
11424
  background: "var(--bg)",
11425
  }}
11426
+ @@ -1852,9 +1515,7 @@ function CustomMessageView({ message, cwd, onOpenFile }: { message: CustomMessag
11427
  </span>
11428
  )}
11429
  {time && <span style={{ marginLeft: "auto", color: "var(--text-dim)", fontSize: 10, flexShrink: 0 }}>{time}</span>}
 
11434
  </button>
11435
  </div>
11436
 
11437
+ @@ -1872,7 +1533,7 @@ function CustomMessageView({ message, cwd, onOpenFile }: { message: CustomMessag
11438
  <img
11439
  src={src}
11440
  alt=""
 
11443
  />
11444
  </ImagePreview>
11445
  );
11446
+ @@ -2021,13 +1682,16 @@ function getToolPreview(block: ToolCallContent): string {
11447
  return String(first).slice(0, 120);
11448
  }
11449
 
 
14771
  const width = Number(value);
14772
  if (!Number.isFinite(width)) return CHAT_CONTENT_WIDTH_DEFAULT;
14773
  return Math.max(CHAT_CONTENT_WIDTH_MIN, Math.min(CHAT_CONTENT_WIDTH_MAX, Math.round(width)));
14774
+ diff --git a/lib/diff-patch.test.mjs b/lib/diff-patch.test.mjs
14775
+ new file mode 100644
14776
+ index 0000000..a8e2fb3
14777
+ --- /dev/null
14778
+ +++ b/lib/diff-patch.test.mjs
14779
+ @@ -0,0 +1,97 @@
14780
+ +import assert from "node:assert/strict";
14781
+ +import test from "node:test";
14782
+ +import { createJiti } from "jiti";
14783
+ +
14784
+ +const jiti = createJiti(import.meta.url);
14785
+ +const { splitFilesToPatch } = await jiti.import("./diff-patch.ts");
14786
+ +const { parseUnifiedPatch } = await jiti.import("./patch.ts");
14787
+ +const { parseApplyPatchInput } = await jiti.import("./apply-patch.ts");
14788
+ +
14789
+ +// Context lines are a space and their text, so the blank ones are a lone space.
14790
+ +const EDIT_PATCH = [
14791
+ + "--- /workspace/gradio-chat/app.py",
14792
+ + "+++ /workspace/gradio-chat/app.py",
14793
+ + "@@ -5,9 +5,14 @@",
14794
+ + " ",
14795
+ + " ",
14796
+ + " def respond(message, history):",
14797
+ + ' messages = history + [{"role": "user", "content": message}]',
14798
+ + '- out = client.chat_completion(messages, model="zai-org/GLM-5.3-Flash", max_tokens=512)',
14799
+ + "- return out.choices[0].message.content",
14800
+ + "+ stream = client.chat_completion(",
14801
+ + '+ messages, model="zai-org/GLM-5.3-Flash", max_tokens=512, stream=True',
14802
+ + "+ )",
14803
+ + "+ for chunk in stream:",
14804
+ + "+ delta = chunk.choices[0].delta.content",
14805
+ + "+ if delta:",
14806
+ + "+ yield delta",
14807
+ + " ",
14808
+ + " ",
14809
+ + ' gr.ChatInterface(respond, type="messages", title="Chat").launch()',
14810
+ + "",
14811
+ +].join("\n");
14812
+ +
14813
+ +test("a unified patch survives the trip through split rows, hunks and line numbers included", () => {
14814
+ + const files = parseUnifiedPatch(EDIT_PATCH);
14815
+ + const { patch, lineNumbers } = splitFilesToPatch(files);
14816
+ + assert.equal(lineNumbers, true);
14817
+ + assert.equal(patch, EDIT_PATCH);
14818
+ + assert.deepEqual(parseUnifiedPatch(patch), files);
14819
+ +});
14820
+ +
14821
+ +test("several hunks keep their own starts and section names", () => {
14822
+ + const source = `--- a/x.ts
14823
+ ++++ b/x.ts
14824
+ +@@ -2,3 +2,3 @@ function a() {
14825
+ + one
14826
+ +-two
14827
+ ++TWO
14828
+ + three
14829
+ +@@ -40,2 +40,3 @@ function b() {
14830
+ + forty
14831
+ ++forty-one
14832
+ + forty-two
14833
+ +`;
14834
+ + const { patch } = splitFilesToPatch(parseUnifiedPatch(source));
14835
+ + assert.equal(patch, source);
14836
+ +});
14837
+ +
14838
+ +test("an apply_patch document has no line numbers: hunks count from 1 and numbers are hidden", () => {
14839
+ + const files = parseApplyPatchInput(`*** Begin Patch
14840
+ +*** Update File: src/a.py
14841
+ +@@ def f():
14842
+ +- return 1
14843
+ ++ return 2
14844
+ + # done
14845
+ +*** Add File: src/b.py
14846
+ ++print("hi")
14847
+ ++print("there")
14848
+ +*** End Patch`);
14849
+ + const { patch, lineNumbers } = splitFilesToPatch(files);
14850
+ + assert.equal(lineNumbers, false);
14851
+ + assert.equal(patch, `--- src/a.py
14852
+ ++++ src/a.py
14853
+ +@@ -1,2 +1,2 @@
14854
+ +- return 1
14855
+ ++ return 2
14856
+ + # done
14857
+ +--- /dev/null
14858
+ ++++ src/b.py
14859
+ +@@ -0,0 +1,2 @@
14860
+ ++print("hi")
14861
+ ++print("there")
14862
+ +`);
14863
+ +});
14864
+ +
14865
+ +test("a missing newline at the end stays attached to its line", () => {
14866
+ + const source = `--- a/x.txt
14867
+ ++++ b/x.txt
14868
+ +@@ -1,1 +1,1 @@
14869
+ +-old
14870
+ +\
14871
+ ++new
14872
+ +\
14873
+ +`;
14874
+ + const { patch } = splitFilesToPatch(parseUnifiedPatch(source));
14875
+ + assert.equal(patch, source);
14876
+ +});
14877
+ diff --git a/lib/diff-patch.ts b/lib/diff-patch.ts
14878
+ new file mode 100644
14879
+ index 0000000..1150f7a
14880
+ --- /dev/null
14881
+ +++ b/lib/diff-patch.ts
14882
+ @@ -0,0 +1,87 @@
14883
+ +import type { SplitDiffCell, SplitDiffFile } from "./patch";
14884
+ +
14885
+ +/**
14886
+ + * Pi Web's split diff rows (lib/patch.ts, lib/apply-patch.ts) as one unified patch, the input
14887
+ + * the diff viewer (components/CodeDiff.tsx, @pierre/diffs) parses: a `---`/`+++` header per file
14888
+ + * and a `@@` hunk per run of rows between hunk markers. Hunks start at their first known line
14889
+ + * number; rows without any (an apply_patch document) are numbered from 1, and `lineNumbers` is
14890
+ + * false so the viewer hides numbers it would otherwise invent. Pure.
14891
+ + */
14892
+ +export function splitFilesToPatch(files: SplitDiffFile[]): { patch: string; lineNumbers: boolean } {
14893
+ + let lineNumbers = false;
14894
+ + const out: string[] = [];
14895
+ + for (const file of files) {
14896
+ + const oldPath = file.oldPath ?? file.newPath ?? "file";
14897
+ + const newPath = file.newPath ?? file.oldPath ?? "file";
14898
+ + out.push(`--- ${file.oldPath ? oldPath : "/dev/null"}`, `+++ ${file.newPath ? newPath : "/dev/null"}`);
14899
+ +
14900
+ + let hunk: { header: string; lines: string[]; oldStart: number | null; newStart: number | null; oldCount: number; newCount: number } | null = null;
14901
+ + let nextOld = 1;
14902
+ + let nextNew = 1;
14903
+ + const flush = () => {
14904
+ + if (!hunk || hunk.lines.length === 0) return;
14905
+ + const oldStart = hunk.oldStart ?? nextOld;
14906
+ + const newStart = hunk.newStart ?? nextNew;
14907
+ + // An empty side starts one line before its position, as diff writes it ("-0,0").
14908
+ + const oldAt = hunk.oldCount === 0 ? Math.max(0, oldStart - 1) : oldStart;
14909
+ + const newAt = hunk.newCount === 0 ? Math.max(0, newStart - 1) : newStart;
14910
+ + out.push(`@@ -${oldAt},${hunk.oldCount} +${newAt},${hunk.newCount} @@${hunk.header}`, ...hunk.lines);
14911
+ + nextOld = oldStart + hunk.oldCount;
14912
+ + nextNew = newStart + hunk.newCount;
14913
+ + };
14914
+ + const start = (header = "") => {
14915
+ + flush();
14916
+ + hunk = { header, lines: [], oldStart: null, newStart: null, oldCount: 0, newCount: 0 };
14917
+ + };
14918
+ + const seen = (cell: SplitDiffCell, side: "old" | "new") => {
14919
+ + if (cell.lineNo === null || !hunk) return;
14920
+ + lineNumbers = true;
14921
+ + const key = side === "old" ? "oldStart" : "newStart";
14922
+ + const count = side === "old" ? hunk.oldCount : hunk.newCount;
14923
+ + if (hunk[key] === null) hunk[key] = cell.lineNo - count;
14924
+ + };
14925
+ +
14926
+ + let added: SplitDiffCell[] = [];
14927
+ + const flushAdded = () => {
14928
+ + for (const cell of added) {
14929
+ + seen(cell, "new");
14930
+ + hunk!.lines.push(`+${cell.text}`);
14931
+ + hunk!.newCount++;
14932
+ + }
14933
+ + added = [];
14934
+ + };
14935
+ +
14936
+ + start();
14937
+ + for (const row of file.rows) {
14938
+ + if (row.type === "hunk") {
14939
+ + flushAdded();
14940
+ + if (row.text.startsWith("\\ ")) {
14941
+ + hunk!.lines.push(row.text);
14942
+ + continue;
14943
+ + }
14944
+ + // "@@ -1,5 +1,6 @@ def foo" keeps its section name.
14945
+ + const section = row.text.match(/^@@ [^@]* @@(.*)$/)?.[1] ?? "";
14946
+ + start(section);
14947
+ + continue;
14948
+ + }
14949
+ + if (row.left.type === "context") {
14950
+ + flushAdded();
14951
+ + seen(row.left, "old");
14952
+ + seen(row.right, "new");
14953
+ + hunk!.lines.push(` ${row.left.text}`);
14954
+ + hunk!.oldCount++;
14955
+ + hunk!.newCount++;
14956
+ + continue;
14957
+ + }
14958
+ + if (row.left.type === "removed") {
14959
+ + seen(row.left, "old");
14960
+ + hunk!.lines.push(`-${row.left.text}`);
14961
+ + hunk!.oldCount++;
14962
+ + }
14963
+ + if (row.right.type === "added") added.push(row.right);
14964
+ + }
14965
+ + flushAdded();
14966
+ + flush();
14967
+ + }
14968
+ + return { patch: out.join("\n") + "\n", lineNumbers };
14969
+ +}
14970
+ diff --git a/lib/diffs-theme.test.mjs b/lib/diffs-theme.test.mjs
14971
+ new file mode 100644
14972
+ index 0000000..d3e9819
14973
+ --- /dev/null
14974
+ +++ b/lib/diffs-theme.test.mjs
14975
+ @@ -0,0 +1,47 @@
14976
+ +import assert from "node:assert/strict";
14977
+ +import test from "node:test";
14978
+ +import { createJiti } from "jiti";
14979
+ +import darkPlus from "@shikijs/themes/dark-plus";
14980
+ +import lightPlus from "@shikijs/themes/light-plus";
14981
+ +
14982
+ +const jiti = createJiti(import.meta.url);
14983
+ +const { neutralShikiTheme, isBlue, DIFF_THEMES } = await jiti.import("./diffs-theme.ts");
14984
+ +
14985
+ +const sources = {
14986
+ + dark: darkPlus,
14987
+ + light: lightPlus,
14988
+ +};
14989
+ +
14990
+ +function allColors(theme) {
14991
+ + const out = [theme.fg, theme.bg, ...Object.values(theme.colors ?? {})];
14992
+ + for (const entry of theme.tokenColors ?? []) {
14993
+ + if (entry.settings?.foreground) out.push(entry.settings.foreground);
14994
+ + if (entry.settings?.background) out.push(entry.settings.background);
14995
+ + }
14996
+ + return out.filter((c) => typeof c === "string");
14997
+ +}
14998
+ +
14999
+ +for (const mode of ["dark", "light"]) {
15000
+ + test(`the ${mode} diff theme has no blue left, the source theme had some`, () => {
15001
+ + assert.ok(allColors(sources[mode]).some(isBlue), "dark+/light+ changed: nothing to neutralise");
15002
+ + const theme = neutralShikiTheme(sources[mode], mode, DIFF_THEMES[mode]);
15003
+ + assert.deepEqual(allColors(theme).filter(isBlue), []);
15004
+ + assert.equal(theme.name, DIFF_THEMES[mode]);
15005
+ + assert.equal(theme.type, mode);
15006
+ + assert.equal(theme.semanticTokenColors, undefined);
15007
+ + });
15008
+ +
15009
+ + test(`the ${mode} theme keeps its other colours and marks keywords by weight`, () => {
15010
+ + const theme = neutralShikiTheme(sources[mode], mode, DIFF_THEMES[mode]);
15011
+ + const byScope = (scope) => theme.tokenColors.find((e) => [].concat(e.scope ?? []).includes(scope))?.settings;
15012
+ + assert.equal(byScope("string").foreground, sources[mode].tokenColors.find((e) => [].concat(e.scope ?? []).includes("string")).settings.foreground);
15013
+ + assert.match(byScope("storage").fontStyle ?? "", /bold/);
15014
+ + assert.equal(theme.colors["gitDecoration.modifiedResourceForeground"], mode === "dark" ? "#a3a3a3" : "#525252");
15015
+ + assert.equal(theme.colors["gitDecoration.addedResourceForeground"], mode === "dark" ? "#05df72" : "#008236");
15016
+ + });
15017
+ +}
15018
+ +
15019
+ +test("blue is hue 180-275 and saturated; grays, teal and purple are not", () => {
15020
+ + for (const blue of ["#569cd6", "#0000ff", "#001080", "#267f99", "#3b82f6"]) assert.equal(isBlue(blue), true, blue);
15021
+ + for (const other of ["#d4d4d4", "#4ec9b0", "#c586c0", "#ce9178", "#808080", "#000000ff", "inherit"]) assert.equal(isBlue(other), false, other);
15022
+ +});
15023
+ diff --git a/lib/diffs-theme.ts b/lib/diffs-theme.ts
15024
+ new file mode 100644
15025
+ index 0000000..7134615
15026
+ --- /dev/null
15027
+ +++ b/lib/diffs-theme.ts
15028
+ @@ -0,0 +1,110 @@
15029
+ +/**
15030
+ + * The Shiki themes the diff viewer (components/CodeDiff.tsx, @pierre/diffs) highlights with:
15031
+ + * VS Code's dark+ and light+, the palette Pi Web's Prism code blocks use (lib/neutral-code-theme.ts),
15032
+ + * with their blue tokens turned into the design system's neutral grays. Keywords stand out by
15033
+ + * weight instead of hue; strings, numbers, functions and comments keep their colours. The diff's
15034
+ + * own colours come from the design system too: additions `success`, deletions `danger`, and the
15035
+ + * "modified" accent (selection, changed files) a neutral gray, never the terminal blue Shiki
15036
+ + * themes fall back to. Pure, client-safe.
15037
+ + */
15038
+ +
15039
+ +export const DIFF_THEMES = { dark: "pi-web-dark", light: "pi-web-light" } as const;
15040
+ +
15041
+ +type Mode = "dark" | "light";
15042
+ +interface TokenColor {
15043
+ + scope?: string | string[];
15044
+ + settings?: { foreground?: string; background?: string; fontStyle?: string };
15045
+ +}
15046
+ +export interface ShikiTheme {
15047
+ + name?: string;
15048
+ + type?: string;
15049
+ + colors?: Record<string, string>;
15050
+ + tokenColors?: TokenColor[];
15051
+ + semanticTokenColors?: Record<string, unknown>;
15052
+ + [key: string]: unknown;
15053
+ +}
15054
+ +
15055
+ +// The blues of dark+ and light+, by role, as Pi Web's Prism themes already map them.
15056
+ +const NEUTRAL: Record<Mode, Record<string, { foreground: string; bold?: boolean }>> = {
15057
+ + dark: {
15058
+ + "#569cd6": { foreground: "#e5e5e5", bold: true }, // keywords, storage, tags, true/false
15059
+ + "#9cdcfe": { foreground: "#e5e5e5" }, // variables, properties, attribute names
15060
+ + "#4fc1ff": { foreground: "#e5e5e5" }, // constants, enum members
15061
+ + "#000080": { foreground: "#a3a3a3" }, // diff and markup headers
15062
+ + "#646695": { foreground: "#a3a3a3" }, // regular expression constants
15063
+ + "#6796e6": { foreground: "#a3a3a3" }, // list markers
15064
+ + },
15065
+ + light: {
15066
+ + "#0000ff": { foreground: "#0a0a0a", bold: true }, // keywords, storage, constants
15067
+ + "#000080": { foreground: "#525252" },
15068
+ + "#0451a5": { foreground: "#404040" }, // JSON keys, list markers, changed markup
15069
+ + "#267f99": { foreground: "#404040" }, // classes and types
15070
+ + "#001080": { foreground: "#2e2e2e" }, // variables, object keys
15071
+ + "#0070c1": { foreground: "#404040" }, // constants, enum members
15072
+ + },
15073
+ +};
15074
+ +// Whatever blue is left (a theme update, a grammar's own scopes) goes to the body gray.
15075
+ +const FALLBACK: Record<Mode, string> = { dark: "#d4d4d4", light: "#404040" };
15076
+ +
15077
+ +const UI: Record<Mode, Record<string, string>> = {
15078
+ + dark: {
15079
+ + "editor.background": "#0a0a0a",
15080
+ + "editor.foreground": "#d4d4d4",
15081
+ + "gitDecoration.addedResourceForeground": "#05df72",
15082
+ + "gitDecoration.deletedResourceForeground": "#ff6467",
15083
+ + "gitDecoration.modifiedResourceForeground": "#a3a3a3",
15084
+ + },
15085
+ + light: {
15086
+ + "editor.background": "#ffffff",
15087
+ + "editor.foreground": "#2e2e2e",
15088
+ + "gitDecoration.addedResourceForeground": "#008236",
15089
+ + "gitDecoration.deletedResourceForeground": "#c10007",
15090
+ + "gitDecoration.modifiedResourceForeground": "#525252",
15091
+ + },
15092
+ +};
15093
+ +
15094
+ +/** Hue (0-360) and saturation (0-1) of a #rgb, #rrggbb or #rrggbbaa colour; null for anything else. */
15095
+ +export function hueOf(color: string): { hue: number; saturation: number } | null {
15096
+ + let hex = color.trim().toLowerCase();
15097
+ + if (!/^#[0-9a-f]{3,8}$/.test(hex)) return null;
15098
+ + if (hex.length === 4) hex = `#${hex[1]}${hex[1]}${hex[2]}${hex[2]}${hex[3]}${hex[3]}`;
15099
+ + const n = parseInt(hex.slice(1, 7), 16);
15100
+ + const r = ((n >> 16) & 255) / 255, g = ((n >> 8) & 255) / 255, b = (n & 255) / 255;
15101
+ + const max = Math.max(r, g, b), min = Math.min(r, g, b), d = max - min;
15102
+ + if (d === 0) return { hue: 0, saturation: 0 };
15103
+ + let hue = max === r ? ((g - b) / d) % 6 : max === g ? (b - r) / d + 2 : (r - g) / d + 4;
15104
+ + hue = (hue * 60 + 360) % 360;
15105
+ + const lightness = (max + min) / 2;
15106
+ + return { hue, saturation: d / (1 - Math.abs(2 * lightness - 1)) };
15107
+ +}
15108
+ +
15109
+ +/** Blue as the design system's no-blue rule means it: hue 180-275°, not near gray. */
15110
+ +export function isBlue(color: string): boolean {
15111
+ + const c = hueOf(color);
15112
+ + return c !== null && c.hue >= 180 && c.hue <= 275 && c.saturation > 0.15;
15113
+ +}
15114
+ +
15115
+ +function neutralize(color: string, mode: Mode): { foreground: string; bold?: boolean } | null {
15116
+ + const key = color.toLowerCase().slice(0, 7);
15117
+ + return NEUTRAL[mode][key] ?? (isBlue(color) ? { foreground: FALLBACK[mode] } : null);
15118
+ +}
15119
+ +
15120
+ +/** dark+ or light+ as a Pi Web theme: same token roles, no blue, the design system's diff colours. */
15121
+ +export function neutralShikiTheme(theme: ShikiTheme, mode: Mode, name: string): ShikiTheme {
15122
+ + const tokenColors = (theme.tokenColors ?? []).map((entry) => {
15123
+ + const fg = entry.settings?.foreground;
15124
+ + const swap = fg ? neutralize(fg, mode) : null;
15125
+ + if (!swap) return entry;
15126
+ + const styles = new Set((entry.settings?.fontStyle ?? "").split(/\s+/).filter(Boolean));
15127
+ + if (swap.bold) styles.add("bold");
15128
+ + return { ...entry, settings: { ...entry.settings, foreground: swap.foreground, fontStyle: [...styles].join(" ") || undefined } };
15129
+ + });
15130
+ + const colors: Record<string, string> = {};
15131
+ + for (const [key, value] of Object.entries(theme.colors ?? {})) {
15132
+ + colors[key] = isBlue(value) ? (mode === "dark" ? "#a3a3a3" : "#525252") : value;
15133
+ + }
15134
+ + // Shiki does not apply semantic token colours; dropping them keeps blue out of the theme object.
15135
+ + const rest = { ...theme };
15136
+ + delete rest.semanticTokenColors;
15137
+ + return { ...rest, name, type: mode, fg: UI[mode]["editor.foreground"], bg: UI[mode]["editor.background"], colors: { ...colors, ...UI[mode] }, tokenColors };
15138
+ +}
15139
  diff --git a/lib/focus.test.mjs b/lib/focus.test.mjs
15140
  new file mode 100644
15141
  index 0000000..3208319
 
15231
  + (event.shiftKey ? last : first).focus();
15232
  + }
15233
  +}
15234
+ diff --git a/lib/git-changes.ts b/lib/git-changes.ts
15235
+ index c8abaf3..14d6906 100644
15236
+ --- a/lib/git-changes.ts
15237
+ +++ b/lib/git-changes.ts
15238
+ @@ -185,7 +185,12 @@ async function createTrackedFilePatch(
15239
+ }
15240
+ }
15241
+
15242
+ -export async function getGitFileDiff(cwd: string, filePath: string): Promise<GitFileDiffResponse> {
15243
+ +/**
15244
+ + * A changed file's patch against HEAD. With `full`, also both whole versions (HEAD's and the
15245
+ + * working tree's), which the diff viewer asks for only when the reader expands the unchanged
15246
+ + * lines between hunks.
15247
+ + */
15248
+ +export async function getGitFileDiff(cwd: string, filePath: string, { full = false }: { full?: boolean } = {}): Promise<GitFileDiffResponse> {
15249
+ const repositoryRoot = await findRepositoryRoot(cwd);
15250
+ if (!repositoryRoot || !isWithinPath(repositoryRoot, filePath)) return { supported: false };
15251
+
15252
+ @@ -199,7 +204,7 @@ export async function getGitFileDiff(cwd: string, filePath: string): Promise<Git
15253
+ if (status === "deleted") {
15254
+ const patch = await createTrackedFilePatch(repositoryRoot, relativePath, entry.originalPath);
15255
+ if (!patch?.includes("\n@@ ")) return { supported: false };
15256
+ - return { supported: true, status, patch };
15257
+ + return { supported: true, status, patch, ...(full ? { oldContent: await readHeadVersion(repositoryRoot, entry.originalPath ?? relativePath), newContent: "" } : {}) };
15258
+ }
15259
+
15260
+ let stat: fs.Stats;
15261
+ @@ -228,5 +233,17 @@ export async function getGitFileDiff(cwd: string, filePath: string): Promise<Git
15262
+ }
15263
+
15264
+ if (!patch.includes("\n@@ ")) return { supported: false };
15265
+ - return { supported: true, status, patch };
15266
+ + if (!full) return { supported: true, status, patch };
15267
+ + const oldContent = status === "untracked" ? "" : await readHeadVersion(repositoryRoot, entry.originalPath ?? relativePath) ?? (status === "added" ? "" : undefined);
15268
+ + return { supported: true, status, patch, ...(oldContent !== undefined ? { oldContent, newContent } : {}) };
15269
+ +}
15270
+ +
15271
+ +/** A file as HEAD has it, if it is there, text, and within the preview limit. */
15272
+ +async function readHeadVersion(repositoryRoot: string, relativePath: string): Promise<string | undefined> {
15273
+ + try {
15274
+ + const text = await git(repositoryRoot, ["show", `HEAD:${relativePath}`], TEXT_PREVIEW_MAX_BYTES + 1);
15275
+ + return text.length > TEXT_PREVIEW_MAX_BYTES || text.includes("\0") ? undefined : text;
15276
+ + } catch {
15277
+ + return undefined;
15278
+ + }
15279
+ }
15280
+ diff --git a/lib/git-types.ts b/lib/git-types.ts
15281
+ index 2e833b0..e09dd9c 100644
15282
+ --- a/lib/git-types.ts
15283
+ +++ b/lib/git-types.ts
15284
+ @@ -26,4 +26,7 @@ export interface GitFileDiffResponse {
15285
+ supported: boolean;
15286
+ status?: GitFileStatusKind;
15287
+ patch?: string;
15288
+ + /** With `full=1`: the whole file at HEAD ("" when it is new) and in the working tree ("" when deleted). */
15289
+ + oldContent?: string;
15290
+ + newContent?: string;
15291
+ }
15292
  diff --git a/lib/i18n/messages/en.ts b/lib/i18n/messages/en.ts
15293
  index cd39a31..d2a4229 100644
15294
  --- a/lib/i18n/messages/en.ts
 
15625
  + }
15626
  + return order.map((kind) => ({ kind, count: counts.get(kind) ?? 0 })).filter((entry) => entry.count > 0);
15627
  +}
15628
+ diff --git a/package-lock.json b/package-lock.json
15629
+ index 9cd6e2c..53ea09a 100644
15630
+ --- a/package-lock.json
15631
+ +++ b/package-lock.json
15632
+ @@ -17,6 +17,8 @@
15633
+ "@earendil-works/pi-mcp": "1.2.0",
15634
+ "@earendil-works/pi-telemetry": "1.2.0",
15635
+ "@earendil-works/pi-tui": "1.2.0",
15636
+ + "@pierre/diffs": "1.5.2",
15637
+ + "@shikijs/themes": "4.5.0",
15638
+ "@xterm/addon-fit": "0.11.0",
15639
+ "@xterm/xterm": "6.0.0",
15640
+ "js-yaml": "^5.2.3",
15641
+ @@ -2235,6 +2237,72 @@
15642
+ "node": ">=12.4.0"
15643
+ }
15644
+ },
15645
+ + "node_modules/@pierre/diffs": {
15646
+ + "version": "1.5.2",
15647
+ + "resolved": "https://registry.npmjs.org/@pierre/diffs/-/diffs-1.5.2.tgz",
15648
+ + "integrity": "sha512-QVxIWQEnNoko22k63maERzozd29+FtaUNpRrZiw603WMe5R1mFSED+jMtPkcVP3SDYS1DWg5K7sa7sJbr3xkNQ==",
15649
+ + "license": "apache-2.0",
15650
+ + "dependencies": {
15651
+ + "@pierre/theme": "2.0.0",
15652
+ + "@pierre/theming": "1.0.1",
15653
+ + "@shikijs/transformers": "^3.0.0 || ^4.0.0",
15654
+ + "diff": "9.0.0",
15655
+ + "hast-util-to-html": "9.0.5",
15656
+ + "lru_map": "0.4.1",
15657
+ + "shiki": "^3.0.0 || ^4.0.0"
15658
+ + },
15659
+ + "peerDependencies": {
15660
+ + "react": "^18.3.1 || ^19.0.0",
15661
+ + "react-dom": "^18.3.1 || ^19.0.0"
15662
+ + },
15663
+ + "peerDependenciesMeta": {
15664
+ + "react": {
15665
+ + "optional": true
15666
+ + },
15667
+ + "react-dom": {
15668
+ + "optional": true
15669
+ + }
15670
+ + }
15671
+ + },
15672
+ + "node_modules/@pierre/theme": {
15673
+ + "version": "2.0.0",
15674
+ + "resolved": "https://registry.npmjs.org/@pierre/theme/-/theme-2.0.0.tgz",
15675
+ + "integrity": "sha512-yNDd9GYLQl1mEUJR8AneJ5e4ohLIHQd/wZLWr4fagt78vS2RwwZNW530vVgHqXFAyFVcFlRmGUD5ramXH46OXw==",
15676
+ + "license": "apache-2.0",
15677
+ + "engines": {
15678
+ + "vscode": "^1.0.0"
15679
+ + }
15680
+ + },
15681
+ + "node_modules/@pierre/theming": {
15682
+ + "version": "1.0.1",
15683
+ + "resolved": "https://registry.npmjs.org/@pierre/theming/-/theming-1.0.1.tgz",
15684
+ + "integrity": "sha512-WCI5Qd7iprDpISL9fBYOLe8RV53+b7mFNA3bPzl60/2CKCSrsKN8zEcep6Y3BAzvARlmca50zGjDodqPGiTUKA==",
15685
+ + "license": "apache-2.0",
15686
+ + "peerDependencies": {
15687
+ + "@pierre/theme": "^1.1.0 || ^2.0.0",
15688
+ + "@shikijs/themes": "^3.0.0 || ^4.0.0",
15689
+ + "react": "^18.3.1 || ^19.0.0",
15690
+ + "react-dom": "^18.3.1 || ^19.0.0",
15691
+ + "shiki": "^3.0.0 || ^4.0.0"
15692
+ + },
15693
+ + "peerDependenciesMeta": {
15694
+ + "@pierre/theme": {
15695
+ + "optional": true
15696
+ + },
15697
+ + "@shikijs/themes": {
15698
+ + "optional": true
15699
+ + },
15700
+ + "react": {
15701
+ + "optional": true
15702
+ + },
15703
+ + "react-dom": {
15704
+ + "optional": true
15705
+ + },
15706
+ + "shiki": {
15707
+ + "optional": true
15708
+ + }
15709
+ + }
15710
+ + },
15711
+ "node_modules/@protobufjs/aspromise": {
15712
+ "version": "1.1.2",
15713
+ "resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz",
15714
+ @@ -2299,6 +2367,119 @@
15715
+ "dev": true,
15716
+ "license": "MIT"
15717
+ },
15718
+ + "node_modules/@shikijs/core": {
15719
+ + "version": "4.5.0",
15720
+ + "resolved": "https://registry.npmjs.org/@shikijs/core/-/core-4.5.0.tgz",
15721
+ + "integrity": "sha512-6CIgwq+bt2JZ3OSjb/nBkkwEf/CfpHcbam+Mg5Pllco7HAGRQ2/EFhZrrJtbyNTgKwknfVS+llsXGygiDGwJWw==",
15722
+ + "license": "MIT",
15723
+ + "dependencies": {
15724
+ + "@shikijs/primitive": "4.5.0",
15725
+ + "@shikijs/types": "4.5.0",
15726
+ + "@shikijs/vscode-textmate": "^10.0.2",
15727
+ + "@types/hast": "^3.0.5",
15728
+ + "hast-util-to-html": "^9.0.5"
15729
+ + },
15730
+ + "engines": {
15731
+ + "node": ">=20"
15732
+ + }
15733
+ + },
15734
+ + "node_modules/@shikijs/engine-javascript": {
15735
+ + "version": "4.5.0",
15736
+ + "resolved": "https://registry.npmjs.org/@shikijs/engine-javascript/-/engine-javascript-4.5.0.tgz",
15737
+ + "integrity": "sha512-Ed6UdEj84LyYkwnxM5CvSMWAD+id9ExTYri0/+x41U9zrgNifPSS9lZm0JqBP0VfYI8yr8tY5nbNq9+p9R0kFA==",
15738
+ + "license": "MIT",
15739
+ + "dependencies": {
15740
+ + "@shikijs/types": "4.5.0",
15741
+ + "@shikijs/vscode-textmate": "^10.0.2",
15742
+ + "oniguruma-to-es": "^4.3.6"
15743
+ + },
15744
+ + "engines": {
15745
+ + "node": ">=20"
15746
+ + }
15747
+ + },
15748
+ + "node_modules/@shikijs/engine-oniguruma": {
15749
+ + "version": "4.5.0",
15750
+ + "resolved": "https://registry.npmjs.org/@shikijs/engine-oniguruma/-/engine-oniguruma-4.5.0.tgz",
15751
+ + "integrity": "sha512-dKVmbJecVdB9recl8a/CU4jdpNXyjJQrIcesIkpS70s5HS02ohpnCSpMUbotPnEUzbAcLQ+S4hwZYbkBBiTcJw==",
15752
+ + "license": "MIT",
15753
+ + "dependencies": {
15754
+ + "@shikijs/types": "4.5.0",
15755
+ + "@shikijs/vscode-textmate": "^10.0.2"
15756
+ + },
15757
+ + "engines": {
15758
+ + "node": ">=20"
15759
+ + }
15760
+ + },
15761
+ + "node_modules/@shikijs/langs": {
15762
+ + "version": "4.5.0",
15763
+ + "resolved": "https://registry.npmjs.org/@shikijs/langs/-/langs-4.5.0.tgz",
15764
+ + "integrity": "sha512-wwBTqwduXSz0X4v9Qa2EWeFaYJEw1clCncWjoRNQRbVDu3SPRTRWucnouYapKj3b8Q+sk/41Vbc4B5c8nuYzLA==",
15765
+ + "license": "MIT",
15766
+ + "dependencies": {
15767
+ + "@shikijs/types": "4.5.0"
15768
+ + },
15769
+ + "engines": {
15770
+ + "node": ">=20"
15771
+ + }
15772
+ + },
15773
+ + "node_modules/@shikijs/primitive": {
15774
+ + "version": "4.5.0",
15775
+ + "resolved": "https://registry.npmjs.org/@shikijs/primitive/-/primitive-4.5.0.tgz",
15776
+ + "integrity": "sha512-UM7ShlA8oz0OWxLLO8BmO9Ip6fVqdkt8yF0EH7nOCqHfrx1eEAzF0ZUVK7L+I8NEgeu1PEWSRlxaiPPeCb4iDg==",
15777
+ + "license": "MIT",
15778
+ + "dependencies": {
15779
+ + "@shikijs/types": "4.5.0",
15780
+ + "@shikijs/vscode-textmate": "^10.0.2",
15781
+ + "@types/hast": "^3.0.5"
15782
+ + },
15783
+ + "engines": {
15784
+ + "node": ">=20"
15785
+ + }
15786
+ + },
15787
+ + "node_modules/@shikijs/themes": {
15788
+ + "version": "4.5.0",
15789
+ + "resolved": "https://registry.npmjs.org/@shikijs/themes/-/themes-4.5.0.tgz",
15790
+ + "integrity": "sha512-zGb87H3UBbpuI4yoh5UguB1XbU+2BDU3kflM7UfZ+Cy2hWo9lBtqjSVK20gmLY6ukYl040hAypGXMgud9vul8Q==",
15791
+ + "license": "MIT",
15792
+ + "dependencies": {
15793
+ + "@shikijs/types": "4.5.0"
15794
+ + },
15795
+ + "engines": {
15796
+ + "node": ">=20"
15797
+ + }
15798
+ + },
15799
+ + "node_modules/@shikijs/transformers": {
15800
+ + "version": "4.5.0",
15801
+ + "resolved": "https://registry.npmjs.org/@shikijs/transformers/-/transformers-4.5.0.tgz",
15802
+ + "integrity": "sha512-LM7twi043qCC3gRyGQfjoC2/sowzbEltWuruyRtT3RlBlk1hKzWk9ETnU7RcDBoVWQBmC8Mebnr7p28W7kPoaA==",
15803
+ + "license": "MIT",
15804
+ + "dependencies": {
15805
+ + "@shikijs/core": "4.5.0",
15806
+ + "@shikijs/types": "4.5.0"
15807
+ + },
15808
+ + "engines": {
15809
+ + "node": ">=20"
15810
+ + }
15811
+ + },
15812
+ + "node_modules/@shikijs/types": {
15813
+ + "version": "4.5.0",
15814
+ + "resolved": "https://registry.npmjs.org/@shikijs/types/-/types-4.5.0.tgz",
15815
+ + "integrity": "sha512-drtPrtD8N0DENyD2cyt6Ajy+IWsiCLgMxODwLTpvH1UsN6a9jf90tNTPjqwHvA+0Lzu9e0txk8DjfqH1p9UJRw==",
15816
+ + "license": "MIT",
15817
+ + "dependencies": {
15818
+ + "@shikijs/vscode-textmate": "^10.0.2",
15819
+ + "@types/hast": "^3.0.5"
15820
+ + },
15821
+ + "engines": {
15822
+ + "node": ">=20"
15823
+ + }
15824
+ + },
15825
+ + "node_modules/@shikijs/vscode-textmate": {
15826
+ + "version": "10.0.2",
15827
+ + "resolved": "https://registry.npmjs.org/@shikijs/vscode-textmate/-/vscode-textmate-10.0.2.tgz",
15828
+ + "integrity": "sha512-83yeghZ2xxin3Nj8z1NMd/NCuca+gsYXswywDy5bHvwlWL8tpTQmzGeUuHd9FC3E/SBEMvzJRwWEOz5gGes9Qg==",
15829
+ + "license": "MIT"
15830
+ + },
15831
+ "node_modules/@smithy/core": {
15832
+ "version": "3.35.1",
15833
+ "resolved": "https://registry.npmjs.org/@smithy/core/-/core-3.35.1.tgz",
15834
+ @@ -3060,10 +3241,9 @@
15835
+ "license": "MIT"
15836
+ },
15837
+ "node_modules/@types/hast": {
15838
+ - "version": "3.0.4",
15839
+ - "resolved": "https://registry.npmjs.org/@types/hast/-/hast-3.0.4.tgz",
15840
+ - "integrity": "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ==",
15841
+ - "dev": true,
15842
+ + "version": "3.0.5",
15843
+ + "resolved": "https://registry.npmjs.org/@types/hast/-/hast-3.0.5.tgz",
15844
+ + "integrity": "sha512-rp/ezSWaD1m44dPKICGhiskI13nVr7qTloFwDa/IYkhhf5nzwP+zIQcIJh3WIFSBOy/H1PzB40jPjMDksN4F+g==",
15845
+ "license": "MIT",
15846
+ "dependencies": {
15847
+ "@types/unist": "*"
15848
+ @@ -3101,7 +3281,6 @@
15849
+ "version": "4.0.4",
15850
+ "resolved": "https://registry.npmjs.org/@types/mdast/-/mdast-4.0.4.tgz",
15851
+ "integrity": "sha512-kGaNbPh1k7AFzgpud/gMdvIm5xuECykRR+JnWKQno9TAXVa6WIVCGTPvYGekIDL4uwCZQSYbUxNBSb1aUo79oA==",
15852
+ - "dev": true,
15853
+ "license": "MIT",
15854
+ "dependencies": {
15855
+ "@types/unist": "*"
15856
+ @@ -3195,7 +3374,6 @@
15857
+ "version": "3.0.3",
15858
+ "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.3.tgz",
15859
+ "integrity": "sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==",
15860
+ - "dev": true,
15861
+ "license": "MIT"
15862
+ },
15863
+ "node_modules/@types/web-push": {
15864
+ @@ -3442,7 +3620,6 @@
15865
+ "version": "1.3.0",
15866
+ "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.3.0.tgz",
15867
+ "integrity": "sha512-WmoN8qaIAo7WTYWbAZuG8PYEhn5fkz7dZrqTBZ7dtt//lL2Gwms1IcnQ5yHqjDfX8Ft5j4YzDM23f87zBfDe9g==",
15868
+ - "dev": true,
15869
+ "license": "ISC"
15870
+ },
15871
+ "node_modules/@unrs/resolver-binding-android-arm-eabi": {
15872
+ @@ -4267,7 +4444,6 @@
15873
+ "version": "2.0.1",
15874
+ "resolved": "https://registry.npmjs.org/ccount/-/ccount-2.0.1.tgz",
15875
+ "integrity": "sha512-eyrF0jiFpY+3drT6383f1qhkbGsLSifNAjA61IUjZjmLCWjItY6LB9ft9YhoDgwfmclB2zhu51Lc7+95b8NRAg==",
15876
+ - "dev": true,
15877
+ "license": "MIT",
15878
+ "funding": {
15879
+ "type": "github",
15880
+ @@ -4306,7 +4482,6 @@
15881
+ "version": "2.1.0",
15882
+ "resolved": "https://registry.npmjs.org/character-entities-html4/-/character-entities-html4-2.1.0.tgz",
15883
+ "integrity": "sha512-1v7fgQRj6hnSwFpq1Eu0ynr/CDEw0rXo2B61qXrLNdHZmPKgb7fqS1a2JwF0rISo9q77jDI8VMEHoApn8qDoZA==",
15884
+ - "dev": true,
15885
+ "license": "MIT",
15886
+ "funding": {
15887
+ "type": "github",
15888
+ @@ -4317,7 +4492,6 @@
15889
+ "version": "3.0.0",
15890
+ "resolved": "https://registry.npmjs.org/character-entities-legacy/-/character-entities-legacy-3.0.0.tgz",
15891
+ "integrity": "sha512-RpPp0asT/6ufRm//AJVwpViZbGM/MkjQFxJccQRHmISF/22NBtsHqAWmL+/pmkPWoIUJdWyeVleTl1wydHATVQ==",
15892
+ - "dev": true,
15893
+ "license": "MIT",
15894
+ "funding": {
15895
+ "type": "github",
15896
+ @@ -4365,7 +4539,6 @@
15897
+ "version": "2.0.3",
15898
+ "resolved": "https://registry.npmjs.org/comma-separated-tokens/-/comma-separated-tokens-2.0.3.tgz",
15899
+ "integrity": "sha512-Fu4hJdvzeylCfQPp9SGWidpzrMs7tTrlu6Vb8XGaRGck8QSNZJJp538Wrb60Lax4fPwR64ViY468OIUTbRlGZg==",
15900
+ - "dev": true,
15901
+ "license": "MIT",
15902
+ "funding": {
15903
+ "type": "github",
15904
+ @@ -5157,7 +5330,6 @@
15905
+ "version": "2.0.3",
15906
+ "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz",
15907
+ "integrity": "sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==",
15908
+ - "dev": true,
15909
+ "license": "MIT",
15910
+ "engines": {
15911
+ "node": ">=6"
15912
+ @@ -5177,7 +5349,6 @@
15913
+ "version": "1.1.0",
15914
+ "resolved": "https://registry.npmjs.org/devlop/-/devlop-1.1.0.tgz",
15915
+ "integrity": "sha512-RWmIqhcFf1lRYBvNmr7qTNuyCt/7/ns2jbpp1+PalgE/rDQcBT0fioSMUpJ93irlUhC5hrg4cYqe6U+0ImW0rA==",
15916
+ - "dev": true,
15917
+ "license": "MIT",
15918
+ "dependencies": {
15919
+ "dequal": "^2.0.0"
15920
+ @@ -5187,6 +5358,15 @@
15921
+ "url": "https://github.com/sponsors/wooorm"
15922
+ }
15923
+ },
15924
+ + "node_modules/diff": {
15925
+ + "version": "9.0.0",
15926
+ + "resolved": "https://registry.npmjs.org/diff/-/diff-9.0.0.tgz",
15927
+ + "integrity": "sha512-svtcdpS8CgJyqAjEQIXdb3OjhFVVYjzGAPO8WGCmRbrml64SPw/jJD4GoE98aR7r25A0XcgrK3F02yw9R/vhQw==",
15928
+ + "license": "BSD-3-Clause",
15929
+ + "engines": {
15930
+ + "node": ">=0.3.1"
15931
+ + }
15932
+ + },
15933
+ "node_modules/dingbat-to-unicode": {
15934
+ "version": "1.0.1",
15935
+ "resolved": "https://registry.npmjs.org/dingbat-to-unicode/-/dingbat-to-unicode-1.0.1.tgz",
15936
+ @@ -6804,6 +6984,29 @@
15937
+ "url": "https://opencollective.com/unified"
15938
+ }
15939
+ },
15940
+ + "node_modules/hast-util-to-html": {
15941
+ + "version": "9.0.5",
15942
+ + "resolved": "https://registry.npmjs.org/hast-util-to-html/-/hast-util-to-html-9.0.5.tgz",
15943
+ + "integrity": "sha512-OguPdidb+fbHQSU4Q4ZiLKnzWo8Wwsf5bZfbvu7//a9oTYoqD/fWpe96NuHkoS9h0ccGOTe0C4NGXdtS0iObOw==",
15944
+ + "license": "MIT",
15945
+ + "dependencies": {
15946
+ + "@types/hast": "^3.0.0",
15947
+ + "@types/unist": "^3.0.0",
15948
+ + "ccount": "^2.0.0",
15949
+ + "comma-separated-tokens": "^2.0.0",
15950
+ + "hast-util-whitespace": "^3.0.0",
15951
+ + "html-void-elements": "^3.0.0",
15952
+ + "mdast-util-to-hast": "^13.0.0",
15953
+ + "property-information": "^7.0.0",
15954
+ + "space-separated-tokens": "^2.0.0",
15955
+ + "stringify-entities": "^4.0.0",
15956
+ + "zwitch": "^2.0.4"
15957
+ + },
15958
+ + "funding": {
15959
+ + "type": "opencollective",
15960
+ + "url": "https://opencollective.com/unified"
15961
+ + }
15962
+ + },
15963
+ "node_modules/hast-util-to-jsx-runtime": {
15964
+ "version": "2.3.6",
15965
+ "resolved": "https://registry.npmjs.org/hast-util-to-jsx-runtime/-/hast-util-to-jsx-runtime-2.3.6.tgz",
15966
+ @@ -6873,7 +7076,6 @@
15967
+ "version": "3.0.0",
15968
+ "resolved": "https://registry.npmjs.org/hast-util-whitespace/-/hast-util-whitespace-3.0.0.tgz",
15969
+ "integrity": "sha512-88JUN06ipLwsnv+dVn+OIYOvAuvBMy/Qoi6O7mQHxdPXpjy+Cd6xRkWwux7DKO+4sYILtLBRIKgsdpS2gQc7qw==",
15970
+ - "dev": true,
15971
+ "license": "MIT",
15972
+ "dependencies": {
15973
+ "@types/hast": "^3.0.0"
15974
+ @@ -6949,7 +7151,6 @@
15975
+ "version": "3.0.0",
15976
+ "resolved": "https://registry.npmjs.org/html-void-elements/-/html-void-elements-3.0.0.tgz",
15977
+ "integrity": "sha512-bEqo66MRXsUGxWHV5IP0PUiAWwoEjba4VCzg0LjFJBpchPaTfyfCKTG6bc5F8ucKec3q5y6qOdGyYTSBEvhCrg==",
15978
+ - "dev": true,
15979
+ "license": "MIT",
15980
+ "funding": {
15981
+ "type": "github",
15982
+ @@ -8172,6 +8373,12 @@
15983
+ "url": "https://github.com/sponsors/wooorm"
15984
+ }
15985
+ },
15986
+ + "node_modules/lru_map": {
15987
+ + "version": "0.4.1",
15988
+ + "resolved": "https://registry.npmjs.org/lru_map/-/lru_map-0.4.1.tgz",
15989
+ + "integrity": "sha512-I+lBvqMMFfqaV8CJCISjI3wbjmwVu/VyOoU7+qtu9d7ioW5klMgsTTiUOUp+DJvfTTzKXoPbyC6YfgkNcyPSOg==",
15990
+ + "license": "MIT"
15991
+ + },
15992
+ "node_modules/lru-cache": {
15993
+ "version": "5.1.1",
15994
+ "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz",
15995
+ @@ -8554,7 +8761,6 @@
15996
+ "version": "13.2.1",
15997
+ "resolved": "https://registry.npmjs.org/mdast-util-to-hast/-/mdast-util-to-hast-13.2.1.tgz",
15998
+ "integrity": "sha512-cctsq2wp5vTsLIcaymblUriiTcZd0CwWtCbLvrOzYCDZoWyMNV8sZ7krj09FSnsiJi3WVsHLM4k6Dq/yaPyCXA==",
15999
+ - "dev": true,
16000
+ "license": "MIT",
16001
+ "dependencies": {
16002
+ "@types/hast": "^3.0.0",
16003
+ @@ -9111,7 +9317,6 @@
16004
+ "version": "2.1.1",
16005
+ "resolved": "https://registry.npmjs.org/micromark-util-character/-/micromark-util-character-2.1.1.tgz",
16006
+ "integrity": "sha512-wv8tdUTJ3thSFFFJKtpYKOYiGP2+v96Hvk4Tu8KpCAsTMs6yi+nVmGh1syvSCsaxz45J6Jbw+9DD6g97+NV67Q==",
16007
+ - "dev": true,
16008
+ "funding": [
16009
+ {
16010
+ "type": "GitHub Sponsors",
16011
+ @@ -9238,7 +9443,6 @@
16012
+ "version": "2.0.1",
16013
+ "resolved": "https://registry.npmjs.org/micromark-util-encode/-/micromark-util-encode-2.0.1.tgz",
16014
+ "integrity": "sha512-c3cVx2y4KqUnwopcO9b/SCdo2O67LwJJ/UyqGfbigahfegL9myoEFoDYZgkT7f36T0bLrM9hZTAaAyH+PCAXjw==",
16015
+ - "dev": true,
16016
+ "funding": [
16017
+ {
16018
+ "type": "GitHub Sponsors",
16019
+ @@ -9312,7 +9516,6 @@
16020
+ "version": "2.0.1",
16021
+ "resolved": "https://registry.npmjs.org/micromark-util-sanitize-uri/-/micromark-util-sanitize-uri-2.0.1.tgz",
16022
+ "integrity": "sha512-9N9IomZ/YuGGZZmQec1MbgxtlgougxTodVwDzzEouPKo3qFWvymFHWcnDi2vzV1ff6kas9ucW+o3yzJK9YB1AQ==",
16023
+ - "dev": true,
16024
+ "funding": [
16025
+ {
16026
+ "type": "GitHub Sponsors",
16027
+ @@ -9357,7 +9560,6 @@
16028
+ "version": "2.0.1",
16029
+ "resolved": "https://registry.npmjs.org/micromark-util-symbol/-/micromark-util-symbol-2.0.1.tgz",
16030
+ "integrity": "sha512-vs5t8Apaud9N28kgCrRUdEed4UJ+wWNvicHLPxCa9ENlYuAY31M0ETy5y1vA33YoNPDFTghEbnh6efaE8h4x0Q==",
16031
+ - "dev": true,
16032
+ "funding": [
16033
+ {
16034
+ "type": "GitHub Sponsors",
16035
+ @@ -9374,7 +9576,6 @@
16036
+ "version": "2.0.2",
16037
+ "resolved": "https://registry.npmjs.org/micromark-util-types/-/micromark-util-types-2.0.2.tgz",
16038
+ "integrity": "sha512-Yw0ECSpJoViF1qTU4DC6NwtC4aWGt1EkzaQB8KPPyCRR8z9TWeV0HbEFGTO+ZY1wB22zmxnJqhPyTpOVCpeHTA==",
16039
+ - "dev": true,
16040
+ "funding": [
16041
+ {
16042
+ "type": "GitHub Sponsors",
16043
+ @@ -9789,6 +9990,23 @@
16044
+ "url": "https://github.com/sponsors/ljharb"
16045
+ }
16046
+ },
16047
+ + "node_modules/oniguruma-parser": {
16048
+ + "version": "0.12.2",
16049
+ + "resolved": "https://registry.npmjs.org/oniguruma-parser/-/oniguruma-parser-0.12.2.tgz",
16050
+ + "integrity": "sha512-6HVa5oIrgMC6aA6WF6XyyqbhRPJrKR02L20+2+zpDtO5QAzGHAUGw5TKQvwi5vctNnRHkJYmjAhRVQF2EKdTQw==",
16051
+ + "license": "MIT"
16052
+ + },
16053
+ + "node_modules/oniguruma-to-es": {
16054
+ + "version": "4.3.6",
16055
+ + "resolved": "https://registry.npmjs.org/oniguruma-to-es/-/oniguruma-to-es-4.3.6.tgz",
16056
+ + "integrity": "sha512-csuQ9x3Yr0cEIs/Zgx/OEt9iBw9vqIunAPQkx19R/fiMq2oGVTgcMqO/V3Ybqefr1TBvosI6jU539ksaBULJyA==",
16057
+ + "license": "MIT",
16058
+ + "dependencies": {
16059
+ + "oniguruma-parser": "^0.12.2",
16060
+ + "regex": "^6.1.0",
16061
+ + "regex-recursion": "^6.0.2"
16062
+ + }
16063
+ + },
16064
+ "node_modules/openai": {
16065
+ "version": "7.19.0",
16066
+ "resolved": "https://registry.npmjs.org/openai/-/openai-7.19.0.tgz",
16067
+ @@ -10194,7 +10412,6 @@
16068
+ "version": "7.1.0",
16069
+ "resolved": "https://registry.npmjs.org/property-information/-/property-information-7.1.0.tgz",
16070
+ "integrity": "sha512-TwEZ+X+yCJmYfL7TPUOcvBZ4QfoT5YenQiJuX//0th53DE6w0xxLEtfK3iyryQFddXuvkIk51EEgrJQ0WJkOmQ==",
16071
+ - "dev": true,
16072
+ "license": "MIT",
16073
+ "funding": {
16074
+ "type": "github",
16075
+ @@ -10425,6 +10642,30 @@
16076
+ "url": "https://github.com/sponsors/wooorm"
16077
+ }
16078
+ },
16079
+ + "node_modules/regex": {
16080
+ + "version": "6.1.0",
16081
+ + "resolved": "https://registry.npmjs.org/regex/-/regex-6.1.0.tgz",
16082
+ + "integrity": "sha512-6VwtthbV4o/7+OaAF9I5L5V3llLEsoPyq9P1JVXkedTP33c7MfCG0/5NOPcSJn0TzXcG9YUrR0gQSWioew3LDg==",
16083
+ + "license": "MIT",
16084
+ + "dependencies": {
16085
+ + "regex-utilities": "^2.3.0"
16086
+ + }
16087
+ + },
16088
+ + "node_modules/regex-recursion": {
16089
+ + "version": "6.0.2",
16090
+ + "resolved": "https://registry.npmjs.org/regex-recursion/-/regex-recursion-6.0.2.tgz",
16091
+ + "integrity": "sha512-0YCaSCq2VRIebiaUviZNs0cBz1kg5kVS2UKUfNIx8YVs1cN3AV7NTctO5FOKBA+UT2BPJIWZauYHPqJODG50cg==",
16092
+ + "license": "MIT",
16093
+ + "dependencies": {
16094
+ + "regex-utilities": "^2.3.0"
16095
+ + }
16096
+ + },
16097
+ + "node_modules/regex-utilities": {
16098
+ + "version": "2.3.0",
16099
+ + "resolved": "https://registry.npmjs.org/regex-utilities/-/regex-utilities-2.3.0.tgz",
16100
+ + "integrity": "sha512-8VhliFJAWRaUiVvREIiW2NXXTmHs4vMNnSzuJVhscgmGav3g9VDxLrQndI3dZZVVdp0ZO/5v0xmX516/7M9cng==",
16101
+ + "license": "MIT"
16102
+ + },
16103
+ "node_modules/regexp.prototype.flags": {
16104
+ "version": "1.5.4",
16105
+ "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.4.tgz",
16106
+ @@ -10962,6 +11203,25 @@
16107
+ "node": ">=8"
16108
+ }
16109
+ },
16110
+ + "node_modules/shiki": {
16111
+ + "version": "4.5.0",
16112
+ + "resolved": "https://registry.npmjs.org/shiki/-/shiki-4.5.0.tgz",
16113
+ + "integrity": "sha512-OcRW72ngQvc+MSVWBRIovC/BTW589iUE/Vxav7VeM4RcY9MUjqB+IR6ILG1k9nuW6LiG/nct9uma4/MBtnZbmQ==",
16114
+ + "license": "MIT",
16115
+ + "dependencies": {
16116
+ + "@shikijs/core": "4.5.0",
16117
+ + "@shikijs/engine-javascript": "4.5.0",
16118
+ + "@shikijs/engine-oniguruma": "4.5.0",
16119
+ + "@shikijs/langs": "4.5.0",
16120
+ + "@shikijs/themes": "4.5.0",
16121
+ + "@shikijs/types": "4.5.0",
16122
+ + "@shikijs/vscode-textmate": "^10.0.2",
16123
+ + "@types/hast": "^3.0.5"
16124
+ + },
16125
+ + "engines": {
16126
+ + "node": ">=20"
16127
+ + }
16128
+ + },
16129
+ "node_modules/side-channel": {
16130
+ "version": "1.1.0",
16131
+ "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz",
16132
+ @@ -11057,7 +11317,6 @@
16133
+ "version": "2.0.2",
16134
+ "resolved": "https://registry.npmjs.org/space-separated-tokens/-/space-separated-tokens-2.0.2.tgz",
16135
+ "integrity": "sha512-PEGlAwrG8yXGXRjW32fGbg66JAlOAwbObuqVoJpv/mRgoWDQfgH1wDPvtzWyUSNAXBGSk8h755YDbbcEy3SH2Q==",
16136
+ - "dev": true,
16137
+ "license": "MIT",
16138
+ "funding": {
16139
+ "type": "github",
16140
+ @@ -11243,7 +11502,6 @@
16141
+ "version": "4.0.4",
16142
+ "resolved": "https://registry.npmjs.org/stringify-entities/-/stringify-entities-4.0.4.tgz",
16143
+ "integrity": "sha512-IwfBptatlO+QCJUo19AqvrPNqlVMpW9YEL2LIVY+Rpv2qsjCGxaDLNRgeGsQWJhfItebuJhsGSLjaBbNSQ+ieg==",
16144
+ - "dev": true,
16145
+ "license": "MIT",
16146
+ "dependencies": {
16147
+ "character-entities-html4": "^2.0.0",
16148
+ @@ -11449,7 +11707,6 @@
16149
+ "version": "3.0.1",
16150
+ "resolved": "https://registry.npmjs.org/trim-lines/-/trim-lines-3.0.1.tgz",
16151
+ "integrity": "sha512-kRj8B+YHZCc9kQYdWfJB2/oUl9rA99qbowYYBtr4ui4mZyAQ2JpvVBd/6U2YloATfqBhBTSMhTpgBHtU0Mf3Rg==",
16152
+ - "dev": true,
16153
+ "license": "MIT",
16154
+ "funding": {
16155
+ "type": "github",
16156
+ @@ -11737,7 +11994,6 @@
16157
+ "version": "6.0.1",
16158
+ "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.1.tgz",
16159
+ "integrity": "sha512-LsiILbtBETkDz8I9p1dQ0uyRUWuaQzd/cuEeS1hoRSyW5E5XGmTzlwY1OrNzzakGowI9Dr/I8HVaw4hTtnxy8g==",
16160
+ - "dev": true,
16161
+ "license": "MIT",
16162
+ "dependencies": {
16163
+ "@types/unist": "^3.0.0"
16164
+ @@ -11751,7 +12007,6 @@
16165
+ "version": "5.0.0",
16166
+ "resolved": "https://registry.npmjs.org/unist-util-position/-/unist-util-position-5.0.0.tgz",
16167
+ "integrity": "sha512-fucsC7HjXvkB5R3kTCO7kUjRdrS0BJt3M/FPxmHMBOm8JQi2BsHAHFsy27E0EolP8rp0NzXsJ+jNPyDWvOJZPA==",
16168
+ - "dev": true,
16169
+ "license": "MIT",
16170
+ "dependencies": {
16171
+ "@types/unist": "^3.0.0"
16172
+ @@ -11780,7 +12035,6 @@
16173
+ "version": "4.0.0",
16174
+ "resolved": "https://registry.npmjs.org/unist-util-stringify-position/-/unist-util-stringify-position-4.0.0.tgz",
16175
+ "integrity": "sha512-0ASV06AAoKCDkS2+xw5RXJywruurpbC4JZSm7nr7MOt1ojAzvyyaO+UxZf18j8FCF6kmzCZKcAgN/yu2gm2XgQ==",
16176
+ - "dev": true,
16177
+ "license": "MIT",
16178
+ "dependencies": {
16179
+ "@types/unist": "^3.0.0"
16180
+ @@ -11794,7 +12048,6 @@
16181
+ "version": "5.1.0",
16182
+ "resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-5.1.0.tgz",
16183
+ "integrity": "sha512-m+vIdyeCOpdr/QeQCu2EzxX/ohgS8KbnPDgFni4dQsfSCtpz8UqDyY5GjRru8PDKuYn7Fq19j1CQ+nJSsGKOzg==",
16184
+ - "dev": true,
16185
+ "license": "MIT",
16186
+ "dependencies": {
16187
+ "@types/unist": "^3.0.0",
16188
+ @@ -11810,7 +12063,6 @@
16189
+ "version": "6.0.2",
16190
+ "resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-6.0.2.tgz",
16191
+ "integrity": "sha512-goh1s1TBrqSqukSc8wrjwWhL0hiJxgA8m4kFxGlQ+8FYQ3C/m11FcTs4YYem7V664AhHVvgoQLk890Ssdsr2IQ==",
16192
+ - "dev": true,
16193
+ "license": "MIT",
16194
+ "dependencies": {
16195
+ "@types/unist": "^3.0.0",
16196
+ @@ -11908,7 +12160,6 @@
16197
+ "version": "6.0.3",
16198
+ "resolved": "https://registry.npmjs.org/vfile/-/vfile-6.0.3.tgz",
16199
+ "integrity": "sha512-KzIbH/9tXat2u30jf+smMwFCsno4wHVdNmzFyL+T/L3UGqqk6JKfVqOFOZEpZSHADH1k40ab6NUIXZq422ov3Q==",
16200
+ - "dev": true,
16201
+ "license": "MIT",
16202
+ "dependencies": {
16203
+ "@types/unist": "^3.0.0",
16204
+ @@ -11938,7 +12189,6 @@
16205
+ "version": "4.0.3",
16206
+ "resolved": "https://registry.npmjs.org/vfile-message/-/vfile-message-4.0.3.tgz",
16207
+ "integrity": "sha512-QTHzsGd1EhbZs4AsQ20JX1rC3cOlt/IWJruk893DfLRr57lcnOeMaWG4K0JrRta4mIJZKth2Au3mM3u03/JWKw==",
16208
+ - "dev": true,
16209
+ "license": "MIT",
16210
+ "dependencies": {
16211
+ "@types/unist": "^3.0.0",
16212
+ @@ -12180,7 +12430,6 @@
16213
+ "version": "2.0.4",
16214
+ "resolved": "https://registry.npmjs.org/zwitch/-/zwitch-2.0.4.tgz",
16215
+ "integrity": "sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==",
16216
+ - "dev": true,
16217
+ "license": "MIT",
16218
+ "funding": {
16219
+ "type": "github",
16220
+ diff --git a/package.json b/package.json
16221
+ index 14d9cb5..b9b2b64 100644
16222
+ --- a/package.json
16223
+ +++ b/package.json
16224
+ @@ -55,6 +55,8 @@
16225
+ "@earendil-works/pi-mcp": "1.2.0",
16226
+ "@earendil-works/pi-telemetry": "1.2.0",
16227
+ "@earendil-works/pi-tui": "1.2.0",
16228
+ + "@pierre/diffs": "1.5.2",
16229
+ + "@shikijs/themes": "4.5.0",
16230
+ "@xterm/addon-fit": "0.11.0",
16231
+ "@xterm/xterm": "6.0.0",
16232
+ "js-yaml": "^5.2.3",
16233
  diff --git a/public/icons/apple-touch-icon.png b/public/icons/apple-touch-icon.png
16234
  index 5f7f2b155e7b5c4517b8556909f9dcbe6d9d6f40..17beb7135ed0a030d2d6e6b0342749914855c071 100644
16235
  GIT binary patch