1565 lines
88 KiB
HTML
1565 lines
88 KiB
HTML
<!doctype html>
|
||
<html class="dv-fill"><head><meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||
<!-- conversation.tab "changes": the conversation's commits and uncommitted work, reviewable.
|
||
Generated by build.sh from ui/src/ — edit those, not this. -->
|
||
<style>
|
||
/* The diff-viewer frames' own look (the renderer's is AiaDiff.css). Theme
|
||
tokens come from the host on :root; the `dark` class from common.js. */
|
||
:root { color-scheme: light dark; }
|
||
* { box-sizing: border-box; }
|
||
html, body { margin: 0; padding: 0; background: transparent; }
|
||
body { font: 13px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: hsl(var(--foreground)); }
|
||
.dv-i { width: 14px; height: 14px; flex: none; display: block; }
|
||
.dv-i16 { width: 16px; height: 16px; }
|
||
.dv-i24 { width: 24px; height: 24px; }
|
||
.dv-grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||
.dv-trunc { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||
.dv-b { font-weight: 600; }
|
||
.dv-fg { color: hsl(var(--foreground)); }
|
||
.dv-12 { font-size: 12px; }
|
||
.dv-xs { flex: none; font-size: 10px; color: hsl(var(--muted-foreground)); }
|
||
.dv-mutc { color: hsl(var(--muted-foreground)); }
|
||
.dv-pri { color: hsl(var(--primary)); }
|
||
.dv-amb { color: #d97706; }
|
||
.dark .dv-amb { color: #fbbf24; }
|
||
.dv-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
|
||
.dv-sha { flex: none; font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; color: hsl(var(--primary)); }
|
||
.dv-sha.dv-12 { font-size: 12px; }
|
||
.dv-err { color: #ef4444; }
|
||
.dv-center { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 64px 12px; font-size: 13px; color: hsl(var(--muted-foreground)); text-align: center; }
|
||
.dv-scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
|
||
.dv-inner { max-width: 1024px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
|
||
.dv-inner > div:empty { display: none; }
|
||
|
||
/* ── the Changes tab ─────────────────────────────────────────────────────── */
|
||
html.dv-fill, html.dv-fill body { height: 100%; overflow: hidden; }
|
||
.dv-tab { display: flex; height: 100%; min-height: 0; }
|
||
.dv-tab.dv-isempty > :not(.dv-empty) { display: none; }
|
||
.dv-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 32px; text-align: center; font-size: 13px; color: hsl(var(--muted-foreground)); }
|
||
.dv-empty[hidden] { display: none; }
|
||
.dv-rail { width: 288px; flex: none; display: flex; flex-direction: column; overflow-y: auto; padding: 8px; border-right: 1px solid hsl(var(--border)); }
|
||
.dv-label { padding: 0 8px 4px; font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: hsl(var(--muted-foreground)); }
|
||
.dv-sel { display: flex; width: 100%; min-width: 0; align-items: center; gap: 6px; margin: 0; padding: 6px 8px; border: 0; border-radius: 6px; background: none; color: inherit; font: 12px/1.35 inherit; font-family: inherit; text-align: left; cursor: pointer; transition: background-color .15s; }
|
||
.dv-sel:hover { background: hsl(var(--muted) / .6); }
|
||
.dv-sel.dv-on { background: hsl(var(--primary) / .1); color: hsl(var(--foreground)); }
|
||
.dv-sel.dv-mut:not(.dv-on) { color: hsl(var(--muted-foreground)); }
|
||
.dv-sel.dv-amber { margin-top: 2px; border: 1px dashed rgba(245,158,11,.5); color: #d97706; }
|
||
.dark .dv-sel.dv-amber { color: #fbbf24; }
|
||
.dv-sel .dv-i { width: 14px; height: 14px; }
|
||
.dv-hint { margin: 0; padding: 4px 8px 0; font-size: 10px; line-height: 1.35; color: hsl(var(--muted-foreground)); }
|
||
.dv-fhead { display: flex; align-items: center; gap: 8px; margin-top: 12px; padding: 0 8px 4px; }
|
||
.dv-fhead .dv-label { padding: 0; }
|
||
.dv-prog { height: 4px; margin: 0 8px; overflow: hidden; border-radius: 999px; background: hsl(var(--muted)); }
|
||
.dv-prog > div { height: 100%; border-radius: 999px; background: hsl(var(--primary)); transition: width .2s; }
|
||
#flist { margin-top: 4px; }
|
||
.dv-chips { display: none; flex: none; gap: 6px; overflow-x: auto; padding: 8px 12px; border-bottom: 1px solid hsl(var(--border)); }
|
||
.dv-chip { display: inline-flex; flex: none; align-items: center; gap: 4px; white-space: nowrap; padding: 4px 8px; border: 1px solid hsl(var(--border)); border-radius: 8px; background: hsl(var(--muted) / .4); color: inherit; font: 11px/1.3 inherit; font-family: inherit; cursor: pointer; }
|
||
.dv-chip.dv-on { border-color: hsl(var(--primary)); background: hsl(var(--primary) / .1); }
|
||
.dv-chip .dv-sha { font-size: 11px; }
|
||
.dv-main { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
|
||
.dv-mprog { display: none; align-items: center; gap: 8px; }
|
||
.dv-mprog .dv-prog { flex: 1; margin: 0; }
|
||
.dv-headrow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 12px; color: hsl(var(--muted-foreground)); }
|
||
.dv-ch { display: flex; min-width: 0; align-items: center; gap: 8px; }
|
||
.dv-subj { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 600; }
|
||
.dv-pills { display: flex; min-width: 0; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 4px; padding-left: 24px; font-size: 10px; }
|
||
.dv-pill { display: inline-flex; max-width: 16rem; align-items: center; gap: 3px; padding: 1px 6px; border: 1px solid hsl(var(--border)); border-radius: 999px; color: hsl(var(--muted-foreground)); }
|
||
.dv-pill .dv-i, .dv-warn .dv-i { width: 10px; height: 10px; }
|
||
.dv-pill.dv-ok { border-color: transparent; background: rgba(16,185,129,.1); color: #059669; }
|
||
.dark .dv-pill.dv-ok { color: #34d399; }
|
||
.dv-warn { display: inline-flex; align-items: center; gap: 3px; color: #d97706; }
|
||
.dark .dv-warn { color: #fbbf24; }
|
||
.dv-unav { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px dashed rgba(245,158,11,.5); border-radius: 8px; font-size: 12px; color: hsl(var(--muted-foreground)); }
|
||
.dv-unav .dv-i { width: 16px; height: 16px; color: #f59e0b; }
|
||
.dv-retry { flex: none; padding: 2px 8px; border: 1px solid hsl(var(--border)); border-radius: 6px; background: none; color: inherit; font: 11px/1.4 inherit; font-family: inherit; cursor: pointer; }
|
||
.dv-retry:hover { background: hsl(var(--muted)); }
|
||
.dv-bar { flex: none; padding: 8px 12px; border-top: 1px solid hsl(var(--border)); background: hsl(var(--card)); }
|
||
.dv-barin { max-width: 1024px; margin: 0 auto; display: flex; align-items: center; gap: 8px; }
|
||
.dv-narrow { display: none; }
|
||
@media (max-width: 767px) {
|
||
.dv-rail { display: none; }
|
||
.dv-tab { flex-direction: column; }
|
||
.dv-chips { display: flex; }
|
||
.dv-mprog { display: flex; }
|
||
.dv-inner { padding: 12px; }
|
||
}
|
||
@media (max-width: 639px) { .dv-wide { display: none; } .dv-narrow { display: inline; } }
|
||
|
||
/* ── the Details row ─────────────────────────────────────────────────────── */
|
||
.dv-slot { padding: 0; }
|
||
.dv-unc { display: flex; width: 100%; align-items: center; gap: 6px; margin: 0; padding: 6px 8px; border: 1px dashed rgba(245,158,11,.5); border-radius: 6px; background: rgba(245,158,11,.07); color: inherit; font: 12px/1.35 inherit; font-family: inherit; text-align: left; cursor: pointer; transition: background-color .15s; }
|
||
.dv-unc:hover { background: rgba(245,158,11,.14); }
|
||
.dv-br { font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; color: #b45309; }
|
||
.dark .dv-br { color: #fcd34d; }
|
||
.dv-cnt { margin-left: 6px; font-size: 10px; color: hsl(var(--muted-foreground)); }
|
||
|
||
/* ── the page ────────────────────────────────────────────────────────────── */
|
||
.dv-pagebox { display: flex; height: 100%; min-height: 0; }
|
||
.dv-tree { width: 256px; flex: none; overflow-y: auto; border-right: 1px solid hsl(var(--border)); }
|
||
.dv-tree:empty { display: none; }
|
||
.dv-sub { font-size: 12px; color: hsl(var(--muted-foreground)); }
|
||
.dv-metarow { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font-size: 11px; }
|
||
.dv-num { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-variant-numeric: tabular-nums; }
|
||
.dv-addc { color: #059669; } .dv-delc { color: #dc2626; }
|
||
.dark .dv-addc { color: #34d399; } .dark .dv-delc { color: #f87171; }
|
||
.dv-wt { display: inline-flex; align-items: center; gap: 4px; padding: 2px 6px; border-radius: 4px; background: rgba(245,158,11,.15); font: 10px ui-monospace, SFMono-Regular, Menlo, monospace; color: #b45309; }
|
||
.dark .dv-wt { color: #fcd34d; }
|
||
.dv-wt .dv-i { width: 12px; height: 12px; }
|
||
.dv-agg { padding: 2px 6px; border-radius: 4px; background: hsl(var(--muted)); font-size: 10px; color: hsl(var(--muted-foreground)); }
|
||
.dv-cchips { display: flex; flex-wrap: wrap; gap: 6px; }
|
||
.dv-cchip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border: 1px solid hsl(var(--border)); border-radius: 999px; background: hsl(var(--muted) / .4); color: inherit; font: 11px/1.4 inherit; font-family: inherit; cursor: pointer; }
|
||
.dv-cchip:hover { background: hsl(var(--muted)); }
|
||
.dv-cchip .dv-i { width: 12px; height: 12px; }
|
||
.dv-csub { max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: hsl(var(--muted-foreground)); }
|
||
@media (max-width: 899px) { .dv-tree { display: none; } }
|
||
</style>
|
||
</head><body>
|
||
<div id="app" class="dv-tab"></div>
|
||
<script>
|
||
/*
|
||
* diff-render.js — the diff-viewer plugin's shared renderer: one global,
|
||
* window.AiaDiff, no dependencies, ES5. The `commits` plugin inlines this file
|
||
* into its feed card (its build.sh reads ../diff-viewer/ui/src/diff-render.js),
|
||
* so the API below is a contract (CONTRACT.md → "diff-viewer — what C relies
|
||
* on"): add to it, never change what is there.
|
||
*
|
||
* AiaDiff.css every style the renderer needs (theme tokens)
|
||
* AiaDiff.injectStyles(doc) adds css once
|
||
* AiaDiff.fileList(el, files, opts) compact file rows, click → opts.onOpen(path, file)
|
||
* AiaDiff.renderFiles(el, files, opts) full hunks, one card per file
|
||
* AiaDiff.stat(add, del) "+12 −3" (an HTMLElement)
|
||
* AiaDiff.esc(s) HTML-escape
|
||
*
|
||
* opts: {lang: "en"|"fr", collapsed?: bool | (f) => bool, maxLines?: number,
|
||
* viewed?: {[path or repo|path]: true}, onToggleViewed?(path, on, file),
|
||
* comments?: [{path, line?, side?: "old"|"new", text, file?, id?}],
|
||
* onComment?(c), onDeleteComment?(c),
|
||
* imageUrl?(file, side) => Promise<string|null>, wrap?: bool}
|
||
*
|
||
* Additions (optional, B only so far): opts.onEditComment?(c, text),
|
||
* opts.onOpenImage?(urls, index, file), opts.commentLabel?(c), opts.highlight
|
||
* (default true), opts.active (fileList: the path drawn as current);
|
||
* AiaDiff.fileTree(el, files, opts) (the page's changed-files tree),
|
||
* AiaDiff.fileKey(f), AiaDiff.signature(f), AiaDiff.anchor(f),
|
||
* AiaDiff.scrollToFile(doc, f | path), AiaDiff.isImage(path),
|
||
* AiaDiff.statusLetter(status), AiaDiff.highlight(text, path), AiaDiff.t(lang, s, vars).
|
||
* renderFiles returns {open(path), scrollTo(path)}.
|
||
*/
|
||
(function (root) {
|
||
"use strict";
|
||
|
||
var FR = {
|
||
"could not load image": "impossible de charger l'image",
|
||
"Open in viewer": "Ouvrir dans la visionneuse",
|
||
"Image — preview unavailable.": "Image — aperçu indisponible.",
|
||
"before": "avant",
|
||
"after": "après",
|
||
"{n} unchanged line": "{n} ligne inchangée",
|
||
"{n} unchanged lines": "{n} lignes inchangées",
|
||
"unchanged lines": "lignes inchangées",
|
||
"Comment on this line": "Commenter cette ligne",
|
||
"… diff truncated (very large file).": "… diff tronqué (fichier très volumineux).",
|
||
"No file changes.": "Aucune modification de fichier.",
|
||
"Binary file — no text diff.": "Fichier binaire — pas de diff texte.",
|
||
"No hunks kept (a lockfile, or too large).": "Aucune modification conservée (un lockfile, ou trop gros).",
|
||
"No content change.": "Aucun changement de contenu.",
|
||
"No content changes (renamed only).": "Aucun changement de contenu (simple renommage).",
|
||
"Comment on the whole file": "Commenter le fichier entier",
|
||
"Viewed": "Vu",
|
||
"About the whole file…": "À propos du fichier entier…",
|
||
"You · {where} · draft": "Toi · {where} · brouillon",
|
||
"old line {n}": "ancienne ligne {n}",
|
||
"line {n}": "ligne {n}",
|
||
"whole file": "fichier entier",
|
||
"Edit": "Modifier",
|
||
"Delete": "Supprimer",
|
||
"Leave a comment for Claude…": "Laisse un commentaire pour Claude…",
|
||
"Cancel": "Annuler",
|
||
"Add comment": "Ajouter le commentaire",
|
||
"Save": "Enregistrer",
|
||
"… {n} more lines": "… {n} lignes de plus",
|
||
"… {n} more line": "… {n} ligne de plus",
|
||
"added": "ajouté",
|
||
"deleted": "supprimé",
|
||
"modified": "modifié",
|
||
"renamed": "renommé"
|
||
};
|
||
|
||
function t(lang, s, vars) {
|
||
var out = lang === "fr" && FR[s] ? FR[s] : s;
|
||
return out.replace(/\{(\w+)\}/g, function (m, k) {
|
||
return vars && vars[k] != null ? String(vars[k]) : m;
|
||
});
|
||
}
|
||
function tn(lang, n, one, many) { return t(lang, n === 1 ? one : many, { n: n }); }
|
||
|
||
function esc(s) {
|
||
return String(s == null ? "" : s).replace(/[&<>"']/g, function (c) {
|
||
return { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c];
|
||
});
|
||
}
|
||
|
||
// ── glyphs (lucide 0.469, currentColor) ────────────────────────────────────
|
||
function svg(body, cls) {
|
||
return '<svg class="aiad-i' + (cls ? " " + cls : "") + '" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' + body + "</svg>";
|
||
}
|
||
var I = {
|
||
chevronRight: '<path d="m9 18 6-6-6-6"/>',
|
||
chevronDown: '<path d="m6 9 6 6 6-6"/>',
|
||
msgPlus: '<path d="M7.9 20A9 9 0 1 0 4 16.1L2 22Z"/><path d="M8 12h8"/><path d="M12 8v8"/>',
|
||
msg: '<path d="M7.9 20A9 9 0 1 0 4 16.1L2 22Z"/>',
|
||
check: '<path d="M20 6 9 17l-5-5"/>',
|
||
trash: '<path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/>',
|
||
imageOff: '<line x1="2" x2="22" y1="2" y2="22"/><path d="M10.41 10.41a2 2 0 1 1-2.83-2.83"/><line x1="13.5" x2="6" y1="13.5" y2="21"/><line x1="18" x2="21" y1="12" y2="15"/><path d="M3.59 3.59A1.99 1.99 0 0 0 3 5v14a2 2 0 0 0 2 2h14c.55 0 1.052-.22 1.41-.59"/><path d="M21 15V5a2 2 0 0 0-2-2H9"/>',
|
||
maximize: '<path d="M15 3h6v6"/><path d="M9 21H3v-6"/><path d="M21 3l-7 7"/><path d="M3 21l7-7"/>',
|
||
folder: '<path d="M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"/>',
|
||
folderOpen: '<path d="m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2"/>',
|
||
filePlus: '<path d="M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/><path d="M3 15h6"/><path d="M6 12v6"/>',
|
||
fileMinus: '<path d="M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/><path d="M3 15h6"/>',
|
||
filePen: '<path d="M12.5 22H18a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v9.5"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/><path d="M13.378 15.626a1 1 0 1 0-3.004-3.004l-5.01 5.012a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506z"/>',
|
||
fileText: '<path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/><path d="M10 9H8"/><path d="M16 13H8"/><path d="M16 17H8"/>'
|
||
};
|
||
|
||
// ── styles ─────────────────────────────────────────────────────────────────
|
||
var css = [
|
||
".aiad-i{width:14px;height:14px;flex:none;display:block}",
|
||
".aiad-add{color:#10b981}.aiad-del{color:#ef4444}",
|
||
".aiad-stat{flex:none;font:10px/1 ui-monospace,SFMono-Regular,Menlo,monospace;font-variant-numeric:tabular-nums;white-space:nowrap}",
|
||
".aiad-stat .aiad-del{margin-left:2px}",
|
||
".aiad-sl{flex:none;margin-right:2px;border-radius:3px;padding:0 4px;font:700 9px/16px ui-sans-serif,system-ui,sans-serif}",
|
||
".aiad-sl-A{background:rgba(16,185,129,.15);color:#059669}.aiad-sl-D{background:rgba(239,68,68,.15);color:#dc2626}",
|
||
".aiad-sl-R{background:rgba(14,165,233,.15);color:#0284c7}.aiad-sl-M{background:hsl(var(--primary)/.15);color:hsl(var(--primary))}",
|
||
".dark .aiad-sl-A{color:#34d399}.dark .aiad-sl-D{color:#f87171}.dark .aiad-sl-R{color:#38bdf8}",
|
||
".aiad-files{display:flex;flex-direction:column;gap:12px}",
|
||
".aiad-file{overflow:hidden;border:1px solid hsl(var(--border));border-radius:12px;background:hsl(var(--card));scroll-margin-top:16px}",
|
||
".aiad-fh{display:flex;align-items:center;gap:8px;padding:6px 10px;background:hsl(var(--muted)/.3)}",
|
||
".aiad-file.aiad-open .aiad-fh{border-bottom:1px solid hsl(var(--border))}",
|
||
".aiad-fh-main{display:flex;flex:1;min-width:0;align-items:center;gap:6px;padding:0;border:0;background:none;color:inherit;font:inherit;text-align:left;cursor:pointer}",
|
||
".aiad-chev{color:hsl(var(--muted-foreground));transition:transform .15s}",
|
||
".aiad-open .aiad-chev{transform:rotate(90deg)}",
|
||
".aiad-path{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font:12px/1.4 ui-monospace,SFMono-Regular,Menlo,monospace}",
|
||
".aiad-path.aiad-dim{color:hsl(var(--muted-foreground))}",
|
||
".aiad-old{color:hsl(var(--muted-foreground))}",
|
||
".aiad-dir{margin-left:6px;font-size:10px;color:hsl(var(--muted-foreground))}",
|
||
".aiad-short{display:none}",
|
||
".aiad-sha{flex:none;font:10px ui-monospace,SFMono-Regular,Menlo,monospace;color:hsl(var(--muted-foreground))}",
|
||
".aiad-ib{display:flex;flex:none;width:24px;height:24px;align-items:center;justify-content:center;border:0;border-radius:6px;background:none;color:hsl(var(--muted-foreground));cursor:pointer}",
|
||
".aiad-ib:hover{background:hsl(var(--muted));color:hsl(var(--foreground))}",
|
||
".aiad-viewed{display:flex;flex:none;align-items:center;gap:4px;padding:2px 6px;border:1px solid hsl(var(--border));border-radius:6px;font-size:11px;color:hsl(var(--muted-foreground));cursor:pointer;user-select:none;-webkit-user-select:none}",
|
||
".aiad-viewed input{position:absolute;width:1px;height:1px;opacity:0;pointer-events:none}",
|
||
".aiad-box{display:flex;width:12px;height:12px;align-items:center;justify-content:center;border:1px solid hsl(var(--muted-foreground)/.6);border-radius:2px}",
|
||
".aiad-box .aiad-i{width:10px;height:10px}",
|
||
".aiad-viewed.aiad-on{border-color:rgba(16,185,129,.4);background:rgba(16,185,129,.1);color:#059669}",
|
||
".dark .aiad-viewed.aiad-on{color:#34d399}",
|
||
".aiad-viewed.aiad-on .aiad-box{border-color:#10b981;background:#10b981;color:#fff}",
|
||
".aiad-note{padding:12px;font-size:12px;color:hsl(var(--muted-foreground))}",
|
||
".aiad-code{margin:0;overflow-x:auto;font:12px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;color:var(--code-foreground,hsl(var(--foreground)))}",
|
||
".aiad-rows{display:inline-block;min-width:100%}",
|
||
".aiad-ln{display:flex}",
|
||
".aiad-ln.aiad-a{background:rgba(16,185,129,.1)}.aiad-ln.aiad-d{background:rgba(239,68,68,.1)}",
|
||
".aiad-ln.aiad-marked{box-shadow:inset 3px 0 0 hsl(var(--primary))}",
|
||
".aiad-g{position:relative;display:flex;flex:none;padding:0;border:0;background:none;color:inherit;font:inherit}",
|
||
"button.aiad-g{cursor:pointer}button.aiad-g:hover{background:hsl(var(--primary)/.15)}",
|
||
".aiad-no{width:40px;flex:none;padding:0 4px;border-right:1px solid hsl(var(--border)/.4);text-align:right;font-size:10px;font-variant-numeric:tabular-nums;color:hsl(var(--muted-foreground)/.6);user-select:none;-webkit-user-select:none}",
|
||
".aiad-g .aiad-plus{position:absolute;left:2px;top:50%;width:12px;height:12px;transform:translateY(-50%);color:hsl(var(--primary));opacity:0;pointer-events:none}",
|
||
".aiad-ln:hover .aiad-plus{opacity:1}",
|
||
".aiad-mk{width:16px;flex:none;text-align:center;color:hsl(var(--muted-foreground)/.5);user-select:none;-webkit-user-select:none}",
|
||
".aiad-a .aiad-mk{color:#059669}.aiad-d .aiad-mk{color:#dc2626}",
|
||
".dark .aiad-a .aiad-mk{color:#34d399}.dark .aiad-d .aiad-mk{color:#f87171}",
|
||
".aiad-tx{padding:0 4px;white-space:pre-wrap;word-break:break-word;overflow-wrap:anywhere}",
|
||
".aiad-nowrap .aiad-tx{white-space:pre;word-break:normal;overflow-wrap:normal}",
|
||
".aiad-gap{display:flex;align-items:center;gap:8px;padding:2px 12px;border-top:1px solid hsl(var(--border)/.6);border-bottom:1px solid hsl(var(--border)/.6);background:hsl(var(--muted)/.4);font:11px/1.6 ui-sans-serif,system-ui,sans-serif;color:hsl(var(--muted-foreground));user-select:none;-webkit-user-select:none}",
|
||
".aiad-gap .aiad-i{width:12px;height:12px}",
|
||
".aiad-trunc{padding:2px 12px;border-top:1px solid hsl(var(--border)/.6);background:hsl(var(--muted)/.4);font:11px/1.6 ui-sans-serif,system-ui,sans-serif;color:hsl(var(--muted-foreground))}",
|
||
".aiad-after{display:flex;flex-direction:column;gap:6px;padding:8px 12px;border-top:1px solid hsl(var(--border)/.6);border-bottom:1px solid hsl(var(--border)/.6);background:hsl(var(--background));font-family:ui-sans-serif,system-ui,sans-serif;white-space:normal}",
|
||
".aiad-fcs{display:flex;flex-direction:column;gap:6px;padding:8px 12px;border-bottom:1px solid hsl(var(--border)/.6)}",
|
||
".aiad-bub{border:1px solid hsl(var(--primary)/.4);border-radius:8px;background:hsl(var(--card));padding:6px 10px}",
|
||
".aiad-bub-h{display:flex;align-items:center;gap:6px;font-size:10px;color:hsl(var(--muted-foreground))}",
|
||
".aiad-bub-h .aiad-i{width:12px;height:12px}",
|
||
".aiad-bub-h .aiad-msg{color:hsl(var(--primary))}",
|
||
".aiad-bub-h span{flex:1}",
|
||
".aiad-bub-h button{padding:1px 4px;border:0;border-radius:4px;background:none;color:inherit;font:inherit;cursor:pointer}",
|
||
".aiad-bub-h button:hover{background:hsl(var(--muted))}",
|
||
".aiad-bub-h button.aiad-rm:hover{color:#ef4444}",
|
||
".aiad-bub-b{white-space:pre-wrap;font-size:12.5px;line-height:1.45}",
|
||
".aiad-box-c{border:1px dashed hsl(var(--border));border-radius:8px;background:hsl(var(--card));padding:8px}",
|
||
".aiad-box-c textarea{box-sizing:border-box;display:block;width:100%;min-height:52px;resize:vertical;border:1px solid hsl(var(--border));border-radius:6px;background:hsl(var(--background));color:inherit;padding:6px 8px;font:12.5px/1.4 ui-sans-serif,system-ui,sans-serif;outline:none}",
|
||
".aiad-box-c textarea:focus{border-color:hsl(var(--primary))}",
|
||
".aiad-box-a{display:flex;justify-content:flex-end;gap:6px;margin-top:6px}",
|
||
".aiad-btn{padding:4px 10px;border:1px solid hsl(var(--border));border-radius:6px;background:none;color:inherit;font:11px/1.3 ui-sans-serif,system-ui,sans-serif;cursor:pointer}",
|
||
".aiad-btn:hover{background:hsl(var(--muted))}",
|
||
".aiad-btn-p{border-color:transparent;background:hsl(var(--primary));color:hsl(var(--primary-foreground));font-weight:600}",
|
||
".aiad-btn-p:hover{background:hsl(var(--primary)/.88)}",
|
||
".aiad-btn:disabled{opacity:.5;cursor:default}",
|
||
".aiad-imgs{display:flex;flex-wrap:wrap;gap:12px;padding:12px}",
|
||
".aiad-tile{flex:1;min-width:0}",
|
||
".aiad-tag{display:inline-flex;margin-bottom:4px;border-radius:4px;padding:2px 6px;font:600 10px/1.2 ui-sans-serif,system-ui,sans-serif;text-transform:uppercase;letter-spacing:.04em}",
|
||
".aiad-tag-del{background:rgba(239,68,68,.15);color:#b91c1c}.aiad-tag-add{background:rgba(16,185,129,.15);color:#047857}",
|
||
".dark .aiad-tag-del{color:#fca5a5}.dark .aiad-tag-add{color:#6ee7b7}",
|
||
".aiad-pic{position:relative;display:block;width:100%;overflow:hidden;border:1px solid hsl(var(--border));border-radius:8px;background:hsl(var(--muted)/.1);padding:8px;cursor:zoom-in}",
|
||
".aiad-pic img{display:block;margin:0 auto;max-width:100%;max-height:28rem;width:auto;object-fit:contain}",
|
||
".aiad-pic .aiad-max{position:absolute;right:8px;top:8px;padding:4px;border-radius:4px;background:rgba(0,0,0,.5);color:#fff;opacity:0;transition:opacity .15s}",
|
||
".aiad-pic:hover .aiad-max{opacity:1}",
|
||
".aiad-pic .aiad-max .aiad-i{width:12px;height:12px}",
|
||
".aiad-nopic{display:flex;align-items:center;gap:8px;border:1px solid hsl(var(--border));border-radius:8px;background:hsl(var(--muted)/.1);padding:24px 12px;font-size:12px;color:hsl(var(--muted-foreground))}",
|
||
".aiad-list{display:flex;flex-direction:column;gap:1px}",
|
||
".aiad-row{display:flex;width:100%;min-width:0;align-items:center;gap:6px;padding:4px 8px;border:0;border-radius:6px;background:none;color:inherit;text-align:left;font:11px/1.4 ui-monospace,SFMono-Regular,Menlo,monospace;cursor:pointer}",
|
||
".aiad-row:hover{background:hsl(var(--muted)/.6)}",
|
||
".aiad-row.aiad-cur{background:hsl(var(--accent))}",
|
||
".aiad-row .aiad-nm{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
||
".aiad-row .aiad-dir{color:hsl(var(--muted-foreground)/.7)}",
|
||
".aiad-row.aiad-seen .aiad-base{color:hsl(var(--muted-foreground));text-decoration:line-through}",
|
||
".aiad-dot{width:12px;height:12px;flex:none;border:1px solid hsl(var(--muted-foreground)/.5);border-radius:999px;box-sizing:border-box}",
|
||
".aiad-tick{width:12px;height:12px;color:#10b981}",
|
||
".aiad-cc{display:inline-flex;flex:none;align-items:center;gap:2px;color:hsl(var(--primary))}",
|
||
".aiad-cc .aiad-i{width:10px;height:10px}",
|
||
".aiad-tree{padding:4px 0}",
|
||
".aiad-tr{display:flex;width:100%;align-items:center;gap:6px;padding:6px 8px 6px 0;border:0;background:none;color:inherit;text-align:left;font:13px/1.3 ui-sans-serif,system-ui,sans-serif;cursor:pointer}",
|
||
".aiad-tr:hover{background:hsl(var(--accent)/.6)}",
|
||
".aiad-tr.aiad-cur{background:hsl(var(--accent));color:hsl(var(--accent-foreground))}",
|
||
".aiad-tr .aiad-i{width:16px;height:16px}",
|
||
".aiad-tr .aiad-chv{width:14px;height:14px;color:hsl(var(--muted-foreground))}",
|
||
".aiad-tr .aiad-nm{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
||
".aiad-tr.aiad-dirrow .aiad-nm{font-weight:500}",
|
||
".aiad-tr .aiad-stat{margin-left:auto}",
|
||
".aiad-sp{width:14px;flex:none}",
|
||
".aiad-fg{color:hsl(var(--muted-foreground))}",
|
||
".aiad-ic-add{color:#10b981}.aiad-ic-del{color:#ef4444}.aiad-ic-ren{color:#3b82f6}",
|
||
// syntax colours: the app's --code-* tokens (hex values)
|
||
".aiad-k{color:var(--code-keyword,#7c3aed)}.aiad-s{color:var(--code-string,#059669)}",
|
||
".aiad-c{color:var(--code-comment,#6b7280);font-style:italic}.aiad-n{color:var(--code-number,#d97706)}",
|
||
".aiad-f{color:var(--code-function,#2563eb)}.aiad-t{color:var(--code-tag,#dc2626)}",
|
||
"@media (max-width:767px){.aiad-long{display:none}.aiad-short{display:inline}}"
|
||
].join("\n");
|
||
|
||
function injectStyles(doc) {
|
||
doc = doc || root.document;
|
||
if (!doc || doc.getElementById("aiad-css")) return;
|
||
var st = doc.createElement("style");
|
||
st.id = "aiad-css";
|
||
st.textContent = css;
|
||
(doc.head || doc.documentElement).appendChild(st);
|
||
}
|
||
|
||
// ── small pieces ───────────────────────────────────────────────────────────
|
||
function statHtml(add, del) {
|
||
add = +add || 0; del = +del || 0;
|
||
if (!add && !del) return "";
|
||
return '<span class="aiad-stat">' + (add > 0 ? '<span class="aiad-add">+' + add + "</span>" : "") +
|
||
(del > 0 ? '<span class="aiad-del">−' + del + "</span>" : "") + "</span>";
|
||
}
|
||
function stat(add, del) {
|
||
var doc = root.document;
|
||
var s = doc.createElement("span");
|
||
s.className = "aiad-stat";
|
||
s.innerHTML = statHtml(add, del).replace(/^<span class="aiad-stat">|<\/span>$/g, "");
|
||
return s;
|
||
}
|
||
var LETTER = { added: "A", deleted: "D", renamed: "R", modified: "M" };
|
||
function statusLetter(status) {
|
||
var l = LETTER[status] || "M";
|
||
return '<span class="aiad-sl aiad-sl-' + l + '">' + l + "</span>";
|
||
}
|
||
function fileKey(f) { return (f && f.repo ? f.repo : "") + "|" + (f ? f.path : ""); }
|
||
function anchor(f) {
|
||
var k = typeof f === "string" ? "|" + f : fileKey(f);
|
||
return "aiad-f-" + k.replace(/[^a-zA-Z0-9]+/g, "-");
|
||
}
|
||
/** What the reader saw of a file (its counts and hunk headers) — the app's
|
||
* reviewStore.fileSignature: another commit touching the file changes it,
|
||
* so a Viewed tick keyed on it drops. */
|
||
function signature(f) {
|
||
var h = 0, hunks = f.hunks || [];
|
||
for (var i = 0; i < hunks.length; i++) {
|
||
var hd = String(hunks[i].header || "");
|
||
for (var j = 0; j < hd.length; j++) h = (h * 31 + hd.charCodeAt(j)) | 0;
|
||
}
|
||
return (f.additions || 0) + "/" + (f.deletions || 0) + "/" + hunks.length + "/" + (h >>> 0).toString(36);
|
||
}
|
||
var IMG_RE = /\.(png|jpe?g|gif|webp|bmp|avif|svg|ico)$/i;
|
||
function isImage(path) { return IMG_RE.test(String(path || "")); }
|
||
function isImageDiff(f) { return isImage(f.path) || (!!f.oldPath && isImage(f.oldPath)); }
|
||
|
||
// ── a light syntax colouring, one line at a time ───────────────────────────
|
||
var KW = {
|
||
js: "abstract as async await break case catch class const continue debugger default delete do else enum export extends false finally for from function get if implements import in instanceof interface let new null of package private protected public readonly return set static super switch this throw true try type typeof undefined var void while with yield",
|
||
py: "and as assert async await break class continue def del elif else except False finally for from global if import in is lambda None nonlocal not or pass raise return self True try while with yield match case",
|
||
sh: "if then else elif fi for while until do done case esac function in return local export readonly set unset exit echo source",
|
||
go: "break case chan const continue default defer else fallthrough for func go goto if import interface map package range return select struct switch type var nil true false",
|
||
rs: "as async await break const continue crate else enum extern false fn for if impl in let loop match mod move mut pub ref return self Self static struct super trait true type unsafe use where while",
|
||
c: "auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while class public private protected virtual namespace new delete template typename this true false nullptr bool",
|
||
sql: "select from where and or not insert into values update set delete create table index view drop alter add join left right inner outer on as group by order having limit offset null is in like between distinct union all primary key references default",
|
||
css: "important media import from to"
|
||
};
|
||
var EXT = {
|
||
js: "js", jsx: "js", mjs: "js", cjs: "js", ts: "js", tsx: "js", vue: "js", svelte: "js", json: "js", java: "c", kt: "c", swift: "c", dart: "js", php: "js", cs: "c",
|
||
py: "py", pyi: "py", rb: "py", sh: "sh", bash: "sh", zsh: "sh", fish: "sh", yml: "sh", yaml: "sh", toml: "sh", ini: "sh", conf: "sh", env: "sh", dockerfile: "sh", makefile: "sh", mk: "sh",
|
||
go: "go", rs: "rs", c: "c", h: "c", cpp: "c", cc: "c", hpp: "c", m: "c", sql: "sql", css: "css", scss: "css", less: "css",
|
||
html: "html", htm: "html", xml: "html", svg: "html"
|
||
};
|
||
var HASH = { py: 1, sh: 1 };
|
||
var reCache = {};
|
||
function langOf(path) {
|
||
var p = String(path || "").toLowerCase();
|
||
var base = p.slice(p.lastIndexOf("/") + 1);
|
||
if (base === "dockerfile" || base === "makefile") return "sh";
|
||
var dot = base.lastIndexOf(".");
|
||
return dot >= 0 ? EXT[base.slice(dot + 1)] || "" : "";
|
||
}
|
||
function langRe(lang) {
|
||
if (reCache[lang]) return reCache[lang];
|
||
var parts = [];
|
||
if (lang === "html") parts.push("<!--.*?(?:-->|$)", "<\\/?[A-Za-z][\\w:-]*", "/?>");
|
||
if (HASH[lang]) parts.push("#.*$");
|
||
else if (lang === "sql") parts.push("--.*$");
|
||
else if (lang && lang !== "html") parts.push("\\/\\/.*$", "\\/\\*.*?(?:\\*\\/|$)");
|
||
parts.push('"(?:[^"\\\\]|\\\\.)*"?', "'(?:[^'\\\\]|\\\\.)*'?");
|
||
if (lang === "js" || lang === "sh" || lang === "go") parts.push("`(?:[^`\\\\]|\\\\.)*`?");
|
||
parts.push("\\b\\d[\\d_]*(?:\\.\\d+)?(?:e[+-]?\\d+)?\\b|\\b0x[\\da-fA-F]+\\b", "[A-Za-z_$][\\w$]*");
|
||
var set = {};
|
||
(KW[lang] || "").split(" ").forEach(function (w) { if (w) set[lang === "sql" ? w.toLowerCase() : w] = 1; });
|
||
reCache[lang] = { re: new RegExp(parts.join("|"), "g"), kw: set };
|
||
return reCache[lang];
|
||
}
|
||
function highlight(text, path) {
|
||
var lang = typeof path === "string" && KW[path] ? path : langOf(path);
|
||
text = String(text == null ? "" : text);
|
||
if (!lang || text.length > 2000) return esc(text);
|
||
var L = langRe(lang), out = "", last = 0, m;
|
||
L.re.lastIndex = 0;
|
||
while ((m = L.re.exec(text))) {
|
||
var tok = m[0], cls = "";
|
||
if (!tok) { L.re.lastIndex++; continue; }
|
||
var c0 = tok.charAt(0);
|
||
if (tok.slice(0, 2) === "//" || tok.slice(0, 2) === "/*" || tok.slice(0, 4) === "<!--" ||
|
||
(c0 === "#" && HASH[lang]) || (tok.slice(0, 2) === "--" && lang === "sql")) cls = "c";
|
||
else if (c0 === '"' || c0 === "'" || c0 === "`") cls = "s";
|
||
else if (/^\d/.test(tok)) cls = "n";
|
||
else if (c0 === "<" || tok === ">" || tok === "/>") cls = lang === "html" ? "t" : "";
|
||
else if (L.kw[lang === "sql" ? tok.toLowerCase() : tok]) cls = "k";
|
||
else if (text.charAt(m.index + tok.length) === "(") cls = "f";
|
||
out += esc(text.slice(last, m.index)) + (cls ? '<span class="aiad-' + cls + '">' + esc(tok) + "</span>" : esc(tok));
|
||
last = m.index + tok.length;
|
||
}
|
||
return out + esc(text.slice(last));
|
||
}
|
||
|
||
// ── fileList: compact rows ─────────────────────────────────────────────────
|
||
function isViewedIn(map, f) {
|
||
if (!map) return false;
|
||
return !!(map[fileKey(f)] || map[f.path]);
|
||
}
|
||
function countComments(comments, f) {
|
||
var n = 0, k = fileKey(f);
|
||
(comments || []).forEach(function (c) { if (c && (c.file ? c.file === k : c.path === f.path)) n++; });
|
||
return n;
|
||
}
|
||
function fileList(container, files, opts) {
|
||
opts = opts || {};
|
||
files = files || [];
|
||
var lang = opts.lang;
|
||
if (!files.length) {
|
||
container.innerHTML = '<div class="aiad-note">' + esc(t(lang, "No file changes.")) + "</div>";
|
||
return;
|
||
}
|
||
var h = '<div class="aiad-list">';
|
||
files.forEach(function (f, i) {
|
||
var slash = f.path.lastIndexOf("/");
|
||
var seen = opts.viewed ? isViewedIn(opts.viewed, f) : false;
|
||
var n = countComments(opts.comments, f);
|
||
h += '<button type="button" class="aiad-row' + (seen ? " aiad-seen" : "") + (opts.active === f.path ? " aiad-cur" : "") +
|
||
'" data-i="' + i + '" title="' + esc(f.path) + '">' +
|
||
(opts.viewed ? (seen ? svg(I.check, "aiad-tick") : '<span class="aiad-dot"></span>') : statusLetter(f.status)) +
|
||
'<span class="aiad-nm"><span class="aiad-base">' + esc(f.path.slice(slash + 1)) + "</span>" +
|
||
(slash > 0 ? '<span class="aiad-dir">' + esc(f.path.slice(0, slash)) + "</span>" : "") + "</span>" +
|
||
(n > 0 ? '<span class="aiad-cc">' + svg(I.msg) + n + "</span>" : "") +
|
||
statHtml(f.additions, f.deletions) + "</button>";
|
||
});
|
||
container.innerHTML = h + "</div>";
|
||
container.__aiadList = { files: files, opts: opts };
|
||
if (!container.__aiadListBound) {
|
||
container.__aiadListBound = true;
|
||
container.addEventListener("click", function (e) {
|
||
var b = e.target.closest && e.target.closest(".aiad-row");
|
||
var st = container.__aiadList;
|
||
if (!b || !st) return;
|
||
var f = st.files[+b.getAttribute("data-i")];
|
||
if (f && st.opts.onOpen) st.opts.onOpen(f.path, f);
|
||
});
|
||
}
|
||
}
|
||
|
||
// ── fileTree: the changed files as folders (the old DiffFileTree) ──────────
|
||
function buildTree(files) {
|
||
var rootN = { name: "", path: "", dir: true, children: [] };
|
||
files.forEach(function (file) {
|
||
var parts = file.path.split("/"), node = rootN, acc = "";
|
||
parts.forEach(function (part, i) {
|
||
acc = acc ? acc + "/" + part : part;
|
||
var leaf = i === parts.length - 1, child = null;
|
||
for (var j = 0; j < node.children.length; j++) if (node.children[j].name === part && node.children[j].dir === !leaf) child = node.children[j];
|
||
if (!child) {
|
||
child = { name: part, path: acc, dir: !leaf, file: leaf ? file : null, children: [] };
|
||
node.children.push(child);
|
||
}
|
||
node = child;
|
||
});
|
||
});
|
||
function collapse(n) {
|
||
n.children.forEach(collapse);
|
||
if (n.dir && n.children.length === 1 && n.children[0].dir) {
|
||
var only = n.children[0];
|
||
n.name = n.name + "/" + only.name;
|
||
n.path = only.path;
|
||
n.children = only.children;
|
||
}
|
||
}
|
||
function sort(n) {
|
||
n.children.sort(function (a, b) {
|
||
if (a.dir !== b.dir) return a.dir ? -1 : 1;
|
||
return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
|
||
});
|
||
n.children.forEach(sort);
|
||
}
|
||
rootN.children.forEach(collapse);
|
||
sort(rootN);
|
||
return rootN;
|
||
}
|
||
function nodeStat(n) {
|
||
if (n.file) return { add: n.file.additions || 0, del: n.file.deletions || 0 };
|
||
return n.children.reduce(function (a, c) { var s = nodeStat(c); return { add: a.add + s.add, del: a.del + s.del }; }, { add: 0, del: 0 });
|
||
}
|
||
function fileTree(container, files, opts) {
|
||
opts = opts || {};
|
||
files = files || [];
|
||
var st = container.__aiadTree || (container.__aiadTree = { closed: {} });
|
||
st.files = files; st.opts = opts; st.leaves = [];
|
||
if (!files.length) {
|
||
container.innerHTML = '<div class="aiad-note" style="text-align:center">' + esc(t(opts.lang, "No file changes.")) + "</div>";
|
||
return;
|
||
}
|
||
function row(n, depth) {
|
||
var pad = ' style="padding-left:' + (depth * 12 + 8) + 'px"';
|
||
if (n.dir) {
|
||
var s = nodeStat(n), open = !st.closed[n.path];
|
||
var h = '<button type="button" class="aiad-tr aiad-dirrow" data-dir="' + esc(n.path) + '"' + pad + ">" +
|
||
svg(open ? I.chevronDown : I.chevronRight, "aiad-chv") + svg(open ? I.folderOpen : I.folder, "aiad-fg") +
|
||
'<span class="aiad-nm">' + esc(n.name) + "</span>" + statHtml(s.add, s.del) + "</button>";
|
||
if (open) n.children.forEach(function (c) { h += row(c, depth + 1); });
|
||
return h;
|
||
}
|
||
var f = n.file, ic = f.status === "added" ? svg(I.filePlus, "aiad-ic-add") : f.status === "deleted" ? svg(I.fileMinus, "aiad-ic-del")
|
||
: f.status === "renamed" ? svg(I.fileText, "aiad-ic-ren") : svg(I.filePen, "aiad-fg");
|
||
st.leaves.push(f);
|
||
return '<button type="button" class="aiad-tr' + (opts.active === f.path ? " aiad-cur" : "") + '" data-leaf="' + (st.leaves.length - 1) + '"' + pad + ' title="' + esc(f.path) + '">' +
|
||
'<span class="aiad-sp"></span>' + ic + '<span class="aiad-nm">' + esc(n.name) + "</span>" + statHtml(f.additions, f.deletions) + "</button>";
|
||
}
|
||
var tree = buildTree(files), h = '<div class="aiad-tree">';
|
||
tree.children.forEach(function (c) { h += row(c, 0); });
|
||
container.innerHTML = h + "</div>";
|
||
if (!st.bound) {
|
||
st.bound = true;
|
||
container.addEventListener("click", function (e) {
|
||
var b = e.target.closest && e.target.closest(".aiad-tr");
|
||
if (!b) return;
|
||
var dir = b.getAttribute("data-dir");
|
||
if (dir != null) {
|
||
st.closed[dir] = !st.closed[dir];
|
||
fileTree(container, st.files, st.opts);
|
||
return;
|
||
}
|
||
var f = st.leaves[+b.getAttribute("data-leaf")];
|
||
if (f) {
|
||
st.opts.active = f.path;
|
||
fileTree(container, st.files, st.opts);
|
||
if (st.opts.onOpen) st.opts.onOpen(f.path, f);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
// ── renderFiles: the full diff, one card per file ──────────────────────────
|
||
function lineSide(ln) { return ln.newNo != null ? "new" : "old"; }
|
||
function lineNo(ln) { return ln.newNo != null ? ln.newNo : ln.oldNo != null ? ln.oldNo : 0; }
|
||
function commentWhere(lang, c) {
|
||
if (c.line == null) return t(lang, "whole file");
|
||
return c.side === "old" ? t(lang, "old line {n}", { n: c.line }) : t(lang, "line {n}", { n: c.line });
|
||
}
|
||
|
||
function renderFiles(container, files, opts) {
|
||
opts = opts || {};
|
||
files = files || [];
|
||
var doc = container.ownerDocument || root.document;
|
||
injectStyles(doc);
|
||
var st = container.__aiad || (container.__aiad = { open: {}, draft: null, edit: null, seq: 0 });
|
||
st.files = files; st.opts = opts; st.seq++;
|
||
var lang = opts.lang;
|
||
var comments = opts.comments || [];
|
||
var canComment = typeof opts.onComment === "function";
|
||
|
||
if (!files.length) {
|
||
container.innerHTML = '<div class="aiad-note" style="text-align:center;padding:48px 12px">' + esc(t(lang, "No file changes.")) + "</div>";
|
||
bind();
|
||
return handle();
|
||
}
|
||
|
||
function isOpen(f) {
|
||
var k = fileKey(f);
|
||
if (st.open[k] != null) return st.open[k];
|
||
var c = opts.collapsed;
|
||
if (typeof c === "function") return !c(f);
|
||
if (c != null) return !c;
|
||
return !(opts.viewed && isViewedIn(opts.viewed, f));
|
||
}
|
||
function mine(f) {
|
||
var k = fileKey(f), out = [];
|
||
comments.forEach(function (c, i) { if (c && (c.file ? c.file === k : c.path === f.path)) out.push([c, i]); });
|
||
return out;
|
||
}
|
||
function bubble(c, i) {
|
||
if (st.edit && st.edit.i === i) return box("edit", st.edit.text, t(lang, "Leave a comment for Claude…"), t(lang, "Save"));
|
||
var label = opts.commentLabel ? opts.commentLabel(c) : t(lang, "You · {where} · draft", { where: commentWhere(lang, c) });
|
||
return '<div class="aiad-bub"><div class="aiad-bub-h">' + svg(I.msg, "aiad-msg") + "<span>" + esc(label) + "</span>" +
|
||
(opts.onEditComment ? '<button type="button" data-act="cedit" data-ci="' + i + '">' + esc(t(lang, "Edit")) + "</button>" : "") +
|
||
(opts.onDeleteComment ? '<button type="button" class="aiad-rm" data-act="cdel" data-ci="' + i + '" title="' + esc(t(lang, "Delete")) + '">' + svg(I.trash) + "</button>" : "") +
|
||
'</div><div class="aiad-bub-b">' + esc(c.text) + "</div></div>";
|
||
}
|
||
function box(kind, text, ph, ok) {
|
||
return '<div class="aiad-box-c" data-box="' + kind + '"><textarea rows="2" placeholder="' + esc(ph) + '">' + esc(text || "") + "</textarea>" +
|
||
'<div class="aiad-box-a"><button type="button" class="aiad-btn" data-act="bcancel">' + esc(t(lang, "Cancel")) + "</button>" +
|
||
'<button type="button" class="aiad-btn aiad-btn-p" data-act="bsave"' + ((text || "").trim() ? "" : " disabled") + ">" + esc(ok) + "</button></div></div>";
|
||
}
|
||
function pathHtml(f, dim) {
|
||
var slash = f.path.lastIndexOf("/");
|
||
var old = f.status === "renamed" && f.oldPath ? '<span class="aiad-old">' + esc(f.oldPath) + " → </span>" : "";
|
||
return '<span class="aiad-path' + (dim ? " aiad-dim" : "") + '" title="' + esc(f.path) + '">' +
|
||
'<span class="aiad-long">' + old + esc(f.path) + "</span>" +
|
||
'<span class="aiad-short">' + esc(f.path.slice(slash + 1)) + (slash > 0 ? '<span class="aiad-dir">' + esc(f.path.slice(0, slash)) + "</span>" : "") + "</span></span>";
|
||
}
|
||
function codeHtml(f, fi, list) {
|
||
var k = fileKey(f), budget = opts.maxLines > 0 ? opts.maxLines : Infinity, shown = 0, total = 0;
|
||
var hl = opts.highlight !== false;
|
||
var out = '<div class="aiad-code' + (opts.wrap === false ? " aiad-nowrap" : "") + '"><div class="aiad-rows">';
|
||
(f.hunks || []).forEach(function (hk, hi) {
|
||
total += (hk.lines || []).length;
|
||
if (shown >= budget) return;
|
||
var prev = hi > 0 ? f.hunks[hi - 1] : null;
|
||
var gap = prev ? hk.oldStart - (prev.oldStart + prev.oldLines) : hk.oldStart - 1;
|
||
if (gap > 0) out += '<div class="aiad-gap">' + svg(I.chevronDown) + "<span>" + esc(tn(lang, gap, "{n} unchanged line", "{n} unchanged lines")) + "</span></div>";
|
||
(hk.lines || []).forEach(function (ln, li) {
|
||
if (shown >= budget) return;
|
||
shown++;
|
||
var side = lineSide(ln), no = lineNo(ln);
|
||
var here = [];
|
||
list.forEach(function (p) { var c = p[0]; if (c.line != null && (c.side || "new") === side && +c.line === no) here.push(p); });
|
||
var editing = st.draft && st.draft.k === k && st.draft.line === no && st.draft.side === side;
|
||
var nos = '<span class="aiad-no">' + (ln.oldNo != null ? ln.oldNo : "") + '</span><span class="aiad-no">' + (ln.newNo != null ? ln.newNo : "") + "</span>";
|
||
var cls = ln.type === "add" ? " aiad-a" : ln.type === "del" ? " aiad-d" : "";
|
||
out += '<div class="aiad-ln' + cls + (here.length ? " aiad-marked" : "") + '">' +
|
||
(canComment ? '<button type="button" class="aiad-g" data-act="cline" data-f="' + fi + '" data-h="' + hi + '" data-l="' + li + '" title="' + esc(t(lang, "Comment on this line")) + '">' + nos + svg(I.msgPlus, "aiad-plus") + "</button>"
|
||
: '<span class="aiad-g">' + nos + "</span>") +
|
||
'<span class="aiad-mk">' + (ln.type === "add" ? "+" : ln.type === "del" ? "−" : " ") + "</span>" +
|
||
'<span class="aiad-tx">' + (ln.text === "" ? " " : hl ? highlight(ln.text, f.path) : esc(ln.text)) + "</span></div>";
|
||
if (here.length || editing) {
|
||
out += '<div class="aiad-after">';
|
||
here.forEach(function (p) { out += bubble(p[0], p[1]); });
|
||
if (editing) out += box("line", st.draft.text, t(lang, "Leave a comment for Claude…"), t(lang, "Add comment"));
|
||
out += "</div>";
|
||
}
|
||
});
|
||
});
|
||
out += "</div></div>";
|
||
if (total > shown) out += '<div class="aiad-trunc">' + esc(tn(lang, total - shown, "… {n} more line", "… {n} more lines")) + "</div>";
|
||
else if (f.truncated) out += '<div class="aiad-trunc">' + esc(t(lang, "… diff truncated (very large file).")) + "</div>";
|
||
return out;
|
||
}
|
||
function imagesHtml(f, fi) {
|
||
var sides = [];
|
||
if (f.status !== "added") sides.push("old");
|
||
if (f.status !== "deleted") sides.push("new");
|
||
if (!opts.imageUrl) return '<div class="aiad-note">' + esc(t(lang, "Image — preview unavailable.")) + "</div>";
|
||
var h = '<div class="aiad-imgs">';
|
||
sides.forEach(function (s) {
|
||
h += '<div class="aiad-tile"><div class="aiad-tag ' + (s === "old" ? "aiad-tag-del" : "aiad-tag-add") + '">' + esc(t(lang, s === "old" ? "before" : "after")) + "</div>" +
|
||
'<div class="aiad-pic" data-act="img" data-f="' + fi + '" data-side="' + s + '" title="' + esc(t(lang, "Open in viewer")) + '" role="button" tabindex="0">' +
|
||
'<img alt="' + esc(t(lang, s === "old" ? "before" : "after")) + '" data-f="' + fi + '" data-side="' + s + '" />' +
|
||
'<span class="aiad-max">' + svg(I.maximize) + "</span></div></div>";
|
||
});
|
||
return h + "</div>";
|
||
}
|
||
function bodyHtml(f, fi, list) {
|
||
if (isImageDiff(f)) return imagesHtml(f, fi);
|
||
if (f.binary) return '<div class="aiad-note">' + esc(t(lang, "Binary file — no text diff.")) + "</div>";
|
||
if (!f.hunks || !f.hunks.length) {
|
||
return '<div class="aiad-note">' + esc(f.truncated ? t(lang, "No hunks kept (a lockfile, or too large).")
|
||
: f.status === "renamed" ? t(lang, "No content changes (renamed only).") : t(lang, "No content change.")) + "</div>";
|
||
}
|
||
return codeHtml(f, fi, list);
|
||
}
|
||
|
||
var h = '<div class="aiad-files">';
|
||
files.forEach(function (f, fi) {
|
||
var k = fileKey(f), open = isOpen(f), list = mine(f);
|
||
var viewed = opts.viewed ? isViewedIn(opts.viewed, f) : false;
|
||
var fileCs = list.filter(function (p) { return p[0].line == null; });
|
||
var fileDraft = st.draft && st.draft.k === k && st.draft.line == null;
|
||
h += '<div class="aiad-file' + (open ? " aiad-open" : "") + '" id="' + anchor(f) + '" data-f="' + fi + '">' +
|
||
'<div class="aiad-fh"><button type="button" class="aiad-fh-main" data-act="toggle" data-f="' + fi + '" aria-expanded="' + open + '">' +
|
||
svg(I.chevronRight, "aiad-chev") + statusLetter(f.status) + pathHtml(f, viewed) +
|
||
(f.commit ? '<span class="aiad-sha">' + esc(String(f.commit).slice(0, 7)) + "</span>" : "") +
|
||
statHtml(f.additions, f.deletions) + "</button>" +
|
||
(canComment ? '<button type="button" class="aiad-ib" data-act="cfile" data-f="' + fi + '" title="' + esc(t(lang, "Comment on the whole file")) + '">' + svg(I.msgPlus) + "</button>" : "") +
|
||
(opts.onToggleViewed ? '<label class="aiad-viewed' + (viewed ? " aiad-on" : "") + '"><input type="checkbox" data-act="viewed" data-f="' + fi + '"' + (viewed ? " checked" : "") + ' />' +
|
||
'<span class="aiad-box">' + (viewed ? svg(I.check) : "") + "</span>" + esc(t(lang, "Viewed")) + "</label>" : "") +
|
||
"</div>";
|
||
if (open) {
|
||
if (fileCs.length || fileDraft) {
|
||
h += '<div class="aiad-fcs">';
|
||
fileCs.forEach(function (p) { h += bubble(p[0], p[1]); });
|
||
if (fileDraft) h += box("file", st.draft.text, t(lang, "About the whole file…"), t(lang, "Add comment"));
|
||
h += "</div>";
|
||
}
|
||
h += bodyHtml(f, fi, list);
|
||
}
|
||
h += "</div>";
|
||
});
|
||
container.innerHTML = h + "</div>";
|
||
loadImages();
|
||
focusBox();
|
||
bind();
|
||
return handle();
|
||
|
||
function loadImages() {
|
||
if (!opts.imageUrl) return;
|
||
var seq = st.seq;
|
||
var imgs = container.querySelectorAll("img[data-f]");
|
||
Array.prototype.forEach.call(imgs, function (img) {
|
||
var f = files[+img.getAttribute("data-f")], side = img.getAttribute("data-side");
|
||
var cacheKey = fileKey(f) + "@" + side;
|
||
st.urls = st.urls || {};
|
||
var fail = function () {
|
||
var pic = img.parentNode;
|
||
if (!pic || !pic.parentNode) return;
|
||
var d = doc.createElement("div");
|
||
d.className = "aiad-nopic";
|
||
d.innerHTML = svg(I.imageOff) + esc(t(lang, "could not load image"));
|
||
pic.parentNode.replaceChild(d, pic);
|
||
};
|
||
img.onerror = fail;
|
||
var p = st.urls[cacheKey] || (st.urls[cacheKey] = Promise.resolve().then(function () { return opts.imageUrl(f, side); }));
|
||
p.then(function (url) {
|
||
if (st.seq !== seq && !img.isConnected) return;
|
||
if (url) img.src = url; else fail();
|
||
}, function () { delete st.urls[cacheKey]; fail(); });
|
||
});
|
||
}
|
||
function focusBox() {
|
||
var ta = container.querySelector(".aiad-box-c textarea");
|
||
if (ta && (st.draft || st.edit) && ta.focus) {
|
||
try { ta.focus({ preventScroll: true }); } catch (e) { ta.focus(); }
|
||
var n = ta.value.length;
|
||
try { ta.setSelectionRange(n, n); } catch (e2) {}
|
||
}
|
||
}
|
||
function bind() {
|
||
if (st.bound) return;
|
||
st.bound = true;
|
||
container.addEventListener("click", onClick);
|
||
container.addEventListener("change", onChange);
|
||
container.addEventListener("input", onInput);
|
||
container.addEventListener("keydown", onKey);
|
||
}
|
||
function handle() {
|
||
return {
|
||
open: function (path) {
|
||
files.forEach(function (f) { if (f.path === path) st.open[fileKey(f)] = true; });
|
||
renderFiles(container, st.files, st.opts);
|
||
},
|
||
scrollTo: function (path) { scrollToFile(doc, path); }
|
||
};
|
||
}
|
||
}
|
||
|
||
function rerender(container) {
|
||
var st = container.__aiad;
|
||
renderFiles(container, st.files, st.opts);
|
||
}
|
||
function stateOf(e) {
|
||
var c = e.currentTarget;
|
||
return { c: c, st: c.__aiad };
|
||
}
|
||
function onClick(e) {
|
||
var s = stateOf(e), st = s.st, opts = st.opts, el = e.target.closest ? e.target.closest("[data-act]") : null;
|
||
if (!el || !s.c.contains(el)) return;
|
||
var act = el.getAttribute("data-act"), f = st.files[+el.getAttribute("data-f")];
|
||
if (act === "toggle" && f) {
|
||
var k = fileKey(f), was = s.c.querySelector("#" + anchor(f));
|
||
st.open[k] = !(was && was.className.indexOf("aiad-open") >= 0);
|
||
rerender(s.c);
|
||
} else if (act === "cfile" && f) {
|
||
st.open[fileKey(f)] = true;
|
||
st.edit = null;
|
||
st.draft = { k: fileKey(f), f: f, line: null, side: null, text: "" };
|
||
rerender(s.c);
|
||
} else if (act === "cline" && f) {
|
||
var ln = ((f.hunks[+el.getAttribute("data-h")] || {}).lines || [])[+el.getAttribute("data-l")];
|
||
if (!ln) return;
|
||
st.edit = null;
|
||
st.draft = { k: fileKey(f), f: f, line: lineNo(ln), side: lineSide(ln), lineText: ln.text, lineType: ln.type, text: "" };
|
||
rerender(s.c);
|
||
} else if (act === "cdel") {
|
||
var c = (opts.comments || [])[+el.getAttribute("data-ci")];
|
||
if (c && opts.onDeleteComment) opts.onDeleteComment(c);
|
||
} else if (act === "cedit") {
|
||
var ci = +el.getAttribute("data-ci"), c2 = (opts.comments || [])[ci];
|
||
if (!c2) return;
|
||
st.draft = null;
|
||
st.edit = { i: ci, c: c2, text: c2.text || "" };
|
||
rerender(s.c);
|
||
} else if (act === "bcancel") {
|
||
st.draft = null; st.edit = null;
|
||
rerender(s.c);
|
||
} else if (act === "bsave") {
|
||
save(s.c);
|
||
} else if (act === "img") {
|
||
var fi = +el.getAttribute("data-f"), file = st.files[fi];
|
||
if (!opts.onOpenImage || !file) return;
|
||
var imgs = s.c.querySelectorAll('img[data-f="' + fi + '"]'), urls = [], idx = 0;
|
||
Array.prototype.forEach.call(imgs, function (im) {
|
||
if (!im.src) return;
|
||
if (im.getAttribute("data-side") === el.getAttribute("data-side")) idx = urls.length;
|
||
urls.push(im.src);
|
||
});
|
||
if (urls.length) opts.onOpenImage(urls, idx, file);
|
||
}
|
||
}
|
||
function save(container) {
|
||
var st = container.__aiad, opts = st.opts;
|
||
var ta = container.querySelector(".aiad-box-c textarea");
|
||
var text = ta ? ta.value : "";
|
||
var seq = st.seq;
|
||
if (st.edit) {
|
||
var ed = st.edit;
|
||
st.edit = null;
|
||
if (!text.trim()) { if (opts.onDeleteComment) opts.onDeleteComment(ed.c); }
|
||
else if (opts.onEditComment) opts.onEditComment(ed.c, text);
|
||
} else if (st.draft) {
|
||
var d = st.draft;
|
||
st.draft = null;
|
||
if (text.trim() && opts.onComment) {
|
||
var c = { path: d.f.path, file: d.k, repo: d.f.repo || null, text: text };
|
||
if (d.line != null) { c.line = d.line; c.side = d.side; c.lineText = d.lineText; c.lineType = d.lineType; }
|
||
opts.onComment(c);
|
||
}
|
||
}
|
||
if (st.seq === seq) rerender(container); // the host didn't draw again itself
|
||
}
|
||
function onChange(e) {
|
||
var s = stateOf(e), el = e.target;
|
||
if (!el || el.getAttribute("data-act") !== "viewed") return;
|
||
var f = s.st.files[+el.getAttribute("data-f")];
|
||
if (!f || !s.st.opts.onToggleViewed) return;
|
||
s.st.open[fileKey(f)] = !el.checked;
|
||
var seq = s.st.seq;
|
||
s.st.opts.onToggleViewed(f.path, !!el.checked, f);
|
||
if (s.st.seq === seq) rerender(s.c);
|
||
}
|
||
function onInput(e) {
|
||
var s = stateOf(e), ta = e.target;
|
||
if (!ta || ta.tagName !== "TEXTAREA") return;
|
||
if (s.st.draft) s.st.draft.text = ta.value;
|
||
if (s.st.edit) s.st.edit.text = ta.value;
|
||
var b = ta.parentNode && ta.parentNode.querySelector('[data-act="bsave"]');
|
||
if (b) b.disabled = !ta.value.trim();
|
||
}
|
||
function onKey(e) {
|
||
if (!e.target || e.target.tagName !== "TEXTAREA") return;
|
||
var s = stateOf(e);
|
||
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) { e.preventDefault(); save(s.c); }
|
||
else if (e.key === "Escape") { e.preventDefault(); s.st.draft = null; s.st.edit = null; rerender(s.c); }
|
||
}
|
||
|
||
function scrollToFile(doc, f) {
|
||
doc = doc || root.document;
|
||
var el = doc.getElementById(typeof f === "string" ? anchorForPath(doc, f) : anchor(f));
|
||
if (el && el.scrollIntoView) el.scrollIntoView({ behavior: "smooth", block: "start" });
|
||
}
|
||
function anchorForPath(doc, path) {
|
||
// a path alone: the first card whose title is that path
|
||
var cards = doc.querySelectorAll(".aiad-file");
|
||
for (var i = 0; i < cards.length; i++) {
|
||
var p = cards[i].querySelector(".aiad-path");
|
||
if (p && p.getAttribute("title") === path) return cards[i].id;
|
||
}
|
||
return anchor(path);
|
||
}
|
||
|
||
root.AiaDiff = {
|
||
css: css,
|
||
injectStyles: injectStyles,
|
||
fileList: fileList,
|
||
renderFiles: renderFiles,
|
||
stat: stat,
|
||
esc: esc,
|
||
// additions
|
||
fileTree: fileTree,
|
||
fileKey: fileKey,
|
||
signature: signature,
|
||
anchor: anchor,
|
||
scrollToFile: scrollToFile,
|
||
isImage: isImage,
|
||
statusLetter: statusLetter,
|
||
statHtml: statHtml,
|
||
highlight: highlight,
|
||
t: t
|
||
};
|
||
})(typeof window !== "undefined" ? window : this);
|
||
|
||
</script>
|
||
<script>
|
||
/*
|
||
* common.js — what the diff-viewer's frames share (inlined by build.sh before
|
||
* each frame's own script, after diff-render.js): the app language, strings,
|
||
* reads with or without `aiAgentPlugin.query`, glyphs, commit helpers.
|
||
*/
|
||
(function (root) {
|
||
"use strict";
|
||
var P = root.aiAgentPlugin || {};
|
||
var init = P.init || {};
|
||
|
||
var FR = {
|
||
// the Changes tab (the app's old ChangesView)
|
||
"No commits or uncommitted changes in this conversation.": "Aucun commit ni changement non commité dans cette conversation.",
|
||
"Commits": "Commits",
|
||
"All changes": "Tous les changements",
|
||
"All": "Tout",
|
||
"Uncommitted": "Non commité",
|
||
"{n} file": "{n} fichier",
|
||
"{n} files": "{n} fichiers",
|
||
"Older conversation: these commits are guessed from when it ran — other work landing then may show.": "Ancienne conversation : ces commits sont devinés d'après le moment où elle a tourné — d'autres travaux arrivés à ce moment-là peuvent apparaître.",
|
||
"Files": "Fichiers",
|
||
"{done} / {total} viewed": "{done} / {total} vus",
|
||
"Reading the commit from the worker…": "Lecture du commit depuis le worker…",
|
||
"Loading the diff…": "Chargement du diff…",
|
||
"A merge — its changes are the branch's own commits.": "Un merge — ses changements sont les commits de la branche elle-même.",
|
||
"No file changes.": "Aucune modification de fichier.",
|
||
"{message} — showing what the transcript recorded.": "{message} — voici ce que la transcription a enregistré.",
|
||
"merge {from} → {to}": "merge {from} → {to}",
|
||
"Not committed yet": "Pas encore commité",
|
||
"Every commit, as one diff": "Tous les commits, en un seul diff",
|
||
"{n} comment": "{n} commentaire",
|
||
"{n} comments": "{n} commentaires",
|
||
"on {n} file": "sur {n} fichier",
|
||
"on {n} files": "sur {n} fichiers",
|
||
"drafts are saved": "brouillons enregistrés",
|
||
"Discard": "Abandonner",
|
||
"Send review to Claude": "Envoyer la revue à Claude",
|
||
"Send review": "Envoyer la revue",
|
||
"Retry": "Réessayer",
|
||
"Could not load this diff.": "Impossible de charger ce diff.",
|
||
"A push in this conversation sent it to the remote": "Un push de cette conversation l'a envoyé au dépôt distant",
|
||
"pushed": "poussé",
|
||
"concurrent": "concurrent",
|
||
"Another command was running in the same repo when this commit landed — it may be another agent's": "Une autre commande tournait dans le même dépôt quand ce commit est arrivé — il peut venir d'un autre agent",
|
||
// the Details card (the app's old CommitLinks, its uncommitted row)
|
||
"Uncommitted changes": "Changements non commités",
|
||
"Uncommitted changes in the {branch} worktree (real git diff)": "Changements non commités dans le worktree {branch} (vrai diff git)",
|
||
"Changes not committed yet, replayed from this conversation's file edits": "Changements pas encore commités, rejoués à partir des modifications de fichiers de cette conversation",
|
||
"file": "fichier",
|
||
"files": "fichiers",
|
||
// the page (the app's old DiffView)
|
||
"{n} file changed": "{n} fichier modifié",
|
||
"{n} files changed": "{n} fichiers modifiés",
|
||
"Read with a real git diff from the {dir} worktree": "Lu avec un vrai git diff depuis le worktree {dir}",
|
||
"Net diff across the conversation's commits (base…tip); interleaved commits from other work may be included.": "Diff net des commits de la conversation (base…pointe) ; des commits intercalés d'autres travaux peuvent être inclus.",
|
||
"aggregated": "agrégé",
|
||
"No file changes found for this conversation.": "Aucune modification de fichier trouvée pour cette conversation.",
|
||
"No file changes found for this commit.": "Aucune modification de fichier trouvée pour ce commit.",
|
||
"Unknown diff route.": "Route de diff inconnue.",
|
||
"Open the conversation": "Ouvrir la conversation",
|
||
"Couldn't send the review: {error}": "Impossible d'envoyer la revue : {error}"
|
||
};
|
||
|
||
var LANG = "en";
|
||
function setLang(l) {
|
||
LANG = String(l || "en").slice(0, 2).toLowerCase() === "fr" ? "fr" : "en";
|
||
return LANG;
|
||
}
|
||
setLang(init.lang || (init.update && init.update.lang) || (root.document && root.document.documentElement.lang) || (root.navigator && root.navigator.language));
|
||
|
||
function t(s, vars) {
|
||
var out = LANG === "fr" && FR[s] ? FR[s] : s;
|
||
return out.replace(/\{(\w+)\}/g, function (m, k) { return vars && vars[k] != null ? String(vars[k]) : m; });
|
||
}
|
||
function tn(n, one, many) { return t(n === 1 ? one : many, { n: n }); }
|
||
|
||
/** A read: `aiAgentPlugin.query` (cached answer first, then the fresh one),
|
||
* else a plain action. → {refresh(), stop()} */
|
||
function read(name, payload, cb) {
|
||
if (P.query) return P.query(name, payload, cb);
|
||
var stopped = false;
|
||
function go() {
|
||
return P.action(name, payload).then(
|
||
function (d) { if (!stopped) cb(d, { fromCache: false, fetching: false, at: Date.now() }); },
|
||
function (e) { if (!stopped) cb(null, { error: String((e && e.message) || e), fromCache: false, fetching: false, at: Date.now() }); });
|
||
}
|
||
go();
|
||
return { refresh: go, stop: function () { stopped = true; } };
|
||
}
|
||
|
||
function svg(body, cls) {
|
||
return '<svg class="dv-i' + (cls ? " " + cls : "") + '" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' + body + "</svg>";
|
||
}
|
||
var ICONS = {
|
||
gitCommit: '<circle cx="12" cy="12" r="3"/><line x1="3" x2="9" y1="12" y2="12"/><line x1="15" x2="21" y1="12" y2="12"/>',
|
||
gitBranch: '<line x1="6" x2="6" y1="3" y2="15"/><circle cx="18" cy="6" r="3"/><circle cx="6" cy="18" r="3"/><path d="M18 9a9 9 0 0 1-9 9"/>',
|
||
gitMerge: '<circle cx="18" cy="18" r="3"/><circle cx="6" cy="6" r="3"/><path d="M6 21V9a9 9 0 0 0 9 9"/>',
|
||
layers: '<path d="m12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83Z"/><path d="m22 17.65-9.17 4.16a2 2 0 0 1-1.66 0L2 17.65"/><path d="m22 12.65-9.17 4.16a2 2 0 0 1-1.66 0L2 12.65"/>',
|
||
fileDiff: '<path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M9 10h6"/><path d="M12 13V7"/><path d="M9 17h6"/>',
|
||
alert: '<path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"/><path d="M12 9v4"/><path d="M12 17h.01"/>',
|
||
loader: '<path d="M21 12a9 9 0 1 1-6.219-8.56"/>',
|
||
send: '<path d="M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z"/><path d="m21.854 2.147-10.94 10.939"/>',
|
||
upload: '<path d="m18 9-6-6-6 6"/><path d="M12 3v14"/><path d="M5 21h14"/>',
|
||
server: '<rect width="20" height="8" x="2" y="2" rx="2" ry="2"/><rect width="20" height="8" x="2" y="14" rx="2" ry="2"/><line x1="6" x2="6.01" y1="6" y2="6"/><line x1="6" x2="6.01" y1="18" y2="18"/>'
|
||
};
|
||
function icon(name, cls) { return svg(ICONS[name] || "", cls); }
|
||
|
||
/** Two shas name the same commit — one may be abbreviated. */
|
||
function sameSha(a, b) {
|
||
a = String(a || ""); b = String(b || "");
|
||
var n = Math.min(a.length, b.length);
|
||
return n >= 7 && a.slice(0, n) === b.slice(0, n);
|
||
}
|
||
function short(c) { return String((c && (c.short || c.sha)) || "").slice(0, 7); }
|
||
function mergeLabel(c) {
|
||
var m = /^Merge (?:remote-tracking )?branch '([^']+)'(?: into (\S+))?/.exec(c.subject || "");
|
||
return m ? t("merge {from} → {to}", { from: m[1], to: m[2] || c.branch || "main" }) : c.subject;
|
||
}
|
||
|
||
/** `/api/diff-blob` for one side of a file: at the commit (new) or its
|
||
* parent (old) when there is one sha, else the working-tree copy (from
|
||
* the file's own worktree, `wt`). null when the file has no repo token. */
|
||
function blobPath(file, side, sha) {
|
||
var repo = file.repo;
|
||
if (!repo) return null;
|
||
var path = side === "old" ? file.oldPath || file.path : file.path;
|
||
var qs = "repo=" + encodeURIComponent(repo) + "&path=" + encodeURIComponent(path);
|
||
if (file.wt) qs += "&wt=" + encodeURIComponent(file.wt);
|
||
if (sha) qs += "&sha=" + encodeURIComponent(side === "new" ? sha : sha + "^");
|
||
return "/api/diff-blob?" + qs;
|
||
}
|
||
function imageUrlFor(sha) {
|
||
return function (file, side) {
|
||
var p = blobPath(file, side, sha);
|
||
if (!p || !P.mediaUrl) return Promise.resolve(null);
|
||
return P.mediaUrl(p).then(function (u) { return u || null; }, function () { return null; });
|
||
};
|
||
}
|
||
function openImages(urls, index) {
|
||
if (P.openMediaViewer) P.openMediaViewer({ slides: urls, index: index }).catch(function () {});
|
||
}
|
||
|
||
/** The theme switch: the `dark` class is the renderer's dark-mode hook. */
|
||
function followTheme() {
|
||
var th = init.theme;
|
||
if (th && th.scheme) root.document.documentElement.classList.toggle("dark", th.scheme === "dark");
|
||
if (P.onTheme) P.onTheme(function (x) {
|
||
if (x && x.scheme) root.document.documentElement.classList.toggle("dark", x.scheme === "dark");
|
||
});
|
||
}
|
||
|
||
root.DV = {
|
||
P: P, init: init, t: t, tn: tn, setLang: setLang, lang: function () { return LANG; },
|
||
read: read, icon: icon, sameSha: sameSha, short: short, mergeLabel: mergeLabel,
|
||
blobPath: blobPath, imageUrlFor: imageUrlFor, openImages: openImages, followTheme: followTheme,
|
||
esc: root.AiaDiff.esc, statHtml: root.AiaDiff.statHtml
|
||
};
|
||
})(window);
|
||
|
||
</script>
|
||
<script>
|
||
/*
|
||
* changes.js — the conversation's "Changes" tab (`conversation.tab` slot
|
||
* `changes`, the app's old ChangesView): its commits (and uncommitted work) on
|
||
* the left, the chosen diff on the right — each file tickable as Viewed, each
|
||
* line commentable — and a bar that sends the comments back to the
|
||
* conversation as one prompt (`aiAgentPlugin.reply`).
|
||
*
|
||
* Params: {c: "all" | "uncommitted" | <sha>} (`?view=changes&c=` too, through
|
||
* `legacyView`). The frame tells the header whether to draw the tab and its
|
||
* badge: `setTab({hidden, badge})` — hidden while the conversation has no
|
||
* commit and nothing uncommitted, badge = the commit count.
|
||
*/
|
||
(function () {
|
||
"use strict";
|
||
var D = window.AiaDiff, DV = window.DV, P = DV.P, init = DV.init, t = DV.t, tn = DV.tn, esc = DV.esc, icon = DV.icon;
|
||
DV.followTheme();
|
||
D.injectStyles(document);
|
||
|
||
var first = init.update || {};
|
||
// reuseFrame: the host keeps this frame across conversation switches; the
|
||
// ids and active flag come in init.update / onUpdate (init.* on older hosts).
|
||
var conversationId = String(first.conversationId || init.conversationId || "");
|
||
var sessionId = String(first.sessionId || init.sessionId || "");
|
||
var running = !!first.running;
|
||
var active = first.active != null ? !!first.active : !!init.active;
|
||
var params = (first.params && typeof first.params === "object") ? first.params : (init.params || {});
|
||
var sel = typeof params.c === "string" && params.c ? params.c : null; // null = not chosen yet
|
||
var chosen = !!sel;
|
||
|
||
var app = document.getElementById("app");
|
||
app.innerHTML =
|
||
'<aside class="dv-rail" id="rail"></aside>' +
|
||
'<div class="dv-chips" id="chips"></div>' +
|
||
'<div class="dv-main"><div class="dv-scroll" id="scroll"><div class="dv-inner">' +
|
||
'<div id="head"></div><div id="mprog"></div><div id="msg"></div><div id="files"></div>' +
|
||
'</div></div><div id="bar"></div></div>' +
|
||
'<div class="dv-empty" id="empty" hidden></div>';
|
||
var $ = function (id) { return document.getElementById(id); };
|
||
var filesEl = $("files");
|
||
|
||
var list = null; // the `commits` answer
|
||
var listErr = null;
|
||
var diffs = {}; // sel → {data, error, loading}
|
||
var listQ = null, reviewQ = null;
|
||
var diffQ = null, diffSel = null;
|
||
var review = { viewed: {}, comments: [] };
|
||
var reviewLocal = false; // a local change was made: the read's answers no longer win
|
||
var sending = false, sendErr = null;
|
||
var tabShown = null;
|
||
var convGen = 0;
|
||
|
||
// ── reads ──────────────────────────────────────────────────────────────────
|
||
function startCommits() {
|
||
if (listQ || !conversationId) return;
|
||
var gen = convGen;
|
||
listQ = DV.read("commits", { conversationId: conversationId, uncommitted: true }, function (d, meta) {
|
||
if (gen !== convGen) return;
|
||
if (meta && meta.error && !d) { listErr = meta.error; if (!list) report(true, null); return draw(); }
|
||
if (!d || typeof d !== "object") return;
|
||
list = d; listErr = null;
|
||
var n = commits().length, unc = uncFiles();
|
||
report(!(n || unc), n || null);
|
||
if (!chosen) sel = n ? "all" : unc ? "uncommitted" : null;
|
||
if (active && sel && (n || unc || chosen)) loadDiff();
|
||
draw();
|
||
});
|
||
}
|
||
function startReview() {
|
||
if (reviewQ || !conversationId) return;
|
||
var gen = convGen;
|
||
reviewQ = DV.read("review", { conversationId: conversationId }, function (d) {
|
||
if (gen !== convGen) return;
|
||
if (!d || typeof d !== "object" || reviewLocal) return;
|
||
review = { viewed: d.viewed || {}, comments: d.comments || [] };
|
||
draw();
|
||
});
|
||
}
|
||
function start() {
|
||
if (!conversationId) { report(true, null); return; }
|
||
startCommits();
|
||
// Defer heavy diff and review reads until this tab is actually visible.
|
||
if (active) {
|
||
startReview();
|
||
if (sel) loadDiff();
|
||
}
|
||
}
|
||
|
||
function commits() { return (list && list.commits) || []; }
|
||
function uncFiles() { var u = list && list.uncommitted; return (u && u.files && u.files.length) || 0; }
|
||
function selected() {
|
||
if (!sel || sel === "all" || sel === "uncommitted") return null;
|
||
var cs = commits();
|
||
for (var i = 0; i < cs.length; i++) if (DV.sameSha(cs[i].sha, sel)) return cs[i];
|
||
return null;
|
||
}
|
||
function report(hidden, badge) {
|
||
var key = hidden + ":" + badge;
|
||
if (key === tabShown || !P.setTab) return;
|
||
tabShown = key;
|
||
P.setTab({ hidden: hidden, badge: badge });
|
||
}
|
||
|
||
function diffRead(s) {
|
||
if (s === "all") return ["aggregate", { conversationId: conversationId }];
|
||
if (s === "uncommitted") return ["uncommitted", { conversationId: conversationId }];
|
||
var c = selected(), p = { conversationId: conversationId, sha: s };
|
||
if (c && c.root) p.root = c.root;
|
||
return ["commit", p];
|
||
}
|
||
function loadDiff() {
|
||
if (!sel || !conversationId) return;
|
||
var r = diffRead(sel), key = sel + "|" + JSON.stringify(r[1]);
|
||
if (diffQ && diffSel === key) return;
|
||
if (diffQ) diffQ.stop();
|
||
diffSel = key;
|
||
var mine = sel, gen = convGen;
|
||
if (!diffs[mine]) diffs[mine] = { loading: true };
|
||
diffQ = DV.read(r[0], r[1], function (d, meta) {
|
||
if (gen !== convGen) return;
|
||
var slot = diffs[mine] || (diffs[mine] = {});
|
||
if (meta && meta.error && !d) { slot.loading = false; slot.error = meta.error; }
|
||
else if (d && typeof d === "object") { slot.data = d; slot.error = null; slot.loading = false; }
|
||
if (mine === sel) draw();
|
||
});
|
||
}
|
||
|
||
function select(c, fromHost) {
|
||
if (!c || c === sel) return;
|
||
sel = c; chosen = true;
|
||
var st = filesEl.__aiad;
|
||
if (st) { st.open = {}; st.draft = null; st.edit = null; }
|
||
if (active) loadDiff();
|
||
draw();
|
||
$("scroll").scrollTop = 0;
|
||
if (!fromHost && P.openTab) {
|
||
try { P.openTab({ slot: "changes", params: { c: c } }); } catch (e) {}
|
||
}
|
||
}
|
||
|
||
// ── the review (Viewed ticks + comments, saved per user and conversation) ──
|
||
var saving = Promise.resolve(), pendingOps = 0;
|
||
function saveOp(op) {
|
||
var gen = convGen, cid = conversationId;
|
||
reviewLocal = true;
|
||
saving = saving.then(function () {
|
||
return P.action("review-save", Object.assign({ conversationId: cid }, op));
|
||
}).then(function (r) {
|
||
if (gen === convGen && r && r.comments && pendingOps === 1) review = { viewed: r.viewed || {}, comments: r.comments || [] };
|
||
}, function () {}).then(function () { if (gen === convGen) { pendingOps--; draw(); } });
|
||
pendingOps++;
|
||
}
|
||
function newId() { return "c" + Date.now().toString(36) + Math.random().toString(36).slice(2, 6); }
|
||
|
||
function viewedMap(files) {
|
||
var m = {};
|
||
files.forEach(function (f) { var k = D.fileKey(f); if (review.viewed[k] && review.viewed[k] === D.signature(f)) m[k] = true; });
|
||
return m;
|
||
}
|
||
function viewComments() {
|
||
return review.comments.filter(function (c) { return c.view === sel; }).map(function (c) {
|
||
return { id: c.id, file: c.file, path: c.path, text: c.body, line: c.line ? c.line.no : undefined, side: c.line ? c.line.side : undefined };
|
||
});
|
||
}
|
||
|
||
/** The review as the prompt sent back to the session (lib/reviewStore's
|
||
* reviewPrompt, word for word): one block per file, each comment under the
|
||
* line it is about. */
|
||
function reviewPrompt(comments, scope) {
|
||
var byFile = {}, order = [], n = 0;
|
||
comments.forEach(function (c) {
|
||
if (!String(c.body || "").trim()) return;
|
||
if (!byFile[c.path]) { byFile[c.path] = []; order.push(c.path); }
|
||
byFile[c.path].push(c); n++;
|
||
});
|
||
var out = ["Review of " + scope + " — " + n + " comment" + (n === 1 ? "" : "s") + ". Address each one, then commit the fixes."];
|
||
order.forEach(function (path) {
|
||
out.push("", "### `" + path + "`");
|
||
byFile[path].slice().sort(function (a, b) { return ((a.line && a.line.no) || 0) - ((b.line && b.line.no) || 0); }).forEach(function (c) {
|
||
if (c.line) {
|
||
var mark = c.line.type === "add" ? "+" : c.line.type === "del" ? "-" : " ";
|
||
var where = c.line.side === "old" ? "old line " + c.line.no : "line " + c.line.no;
|
||
out.push("", "- " + where + ":", " ```", " " + mark + c.line.text, " ```");
|
||
} else {
|
||
out.push("", "- the whole file:");
|
||
}
|
||
String(c.body).trim().split("\n").forEach(function (l) { out.push(" > " + l); });
|
||
});
|
||
});
|
||
return out.join("\n");
|
||
}
|
||
/** What the comments are about: the view they were all written on (a
|
||
* comment keeps its `view`), whatever view is open when Send is pressed;
|
||
* comments from several views → the whole conversation. */
|
||
function scopeText(comments) {
|
||
var views = {};
|
||
(comments || []).forEach(function (c) { views[c.view || "all"] = true; });
|
||
var keys = Object.keys(views), v = keys.length === 1 ? keys[0] : "all";
|
||
if (v === "all") return "this conversation's changes";
|
||
if (v === "uncommitted") return "the uncommitted changes";
|
||
var c = commits().filter(function (x) { return x.sha === v; })[0];
|
||
return "commit " + (c ? DV.short(c) : String(v).slice(0, 7)) + (c ? " (" + c.subject + ")" : "");
|
||
}
|
||
function send() {
|
||
if (sending || !review.comments.length) return;
|
||
if (!P.reply) { sendErr = "reply is not available here"; return draw(); }
|
||
var gen = convGen;
|
||
sending = true; sendErr = null; draw();
|
||
var text = reviewPrompt(review.comments, scopeText(review.comments));
|
||
P.reply({ text: text, send: true }).then(function (r) {
|
||
if (gen !== convGen) return;
|
||
sending = false;
|
||
if (r && r.ok === false) { sendErr = (r && r.error) || "not sent"; return draw(); }
|
||
review.comments = [];
|
||
saveOp({ op: "clear" });
|
||
draw();
|
||
}, function (e) {
|
||
if (gen !== convGen) return;
|
||
sending = false; sendErr = String((e && e.message) || e); draw();
|
||
});
|
||
}
|
||
|
||
// ── drawing ────────────────────────────────────────────────────────────────
|
||
function selRow(on, attrs, cls, inner, title) {
|
||
return '<button type="button" class="dv-sel' + (on ? " dv-on" : "") + (cls ? " " + cls : "") + '" ' + attrs +
|
||
(title ? ' title="' + esc(title) + '"' : "") + ">" + inner + "</button>";
|
||
}
|
||
function drawRail(files, vmap) {
|
||
var cs = commits().slice(), s = selected(), h = '<div class="dv-label">' + esc(t("Commits")) + "</div>";
|
||
h += selRow(sel === "all", 'data-sel="all"', "", icon("layers", "dv-pri") + '<span class="dv-grow dv-b">' + esc(t("All changes")) + "</span>" +
|
||
DV.statHtml(list ? list.additions : 0, list ? list.deletions : 0));
|
||
cs.forEach(function (c) {
|
||
h += selRow(c === s, 'data-sel="' + esc(c.sha) + '"', c.merge ? "dv-mut" : "",
|
||
'<span class="dv-sha">' + esc(DV.short(c)) + '</span><span class="dv-grow">' + esc(c.merge ? DV.mergeLabel(c) : c.subject) + "</span>" +
|
||
(c.merge ? "" : DV.statHtml(c.additions, c.deletions)), c.subject);
|
||
});
|
||
if (uncFiles()) {
|
||
h += selRow(sel === "uncommitted", 'data-sel="uncommitted"', "dv-amber", icon("fileDiff") +
|
||
'<span class="dv-grow">' + esc(t("Uncommitted")) + '</span><span class="dv-xs">' + esc(tn(uncFiles(), "{n} file", "{n} files")) + "</span>");
|
||
}
|
||
if (list && list.exact === false) h += '<p class="dv-hint">' + esc(t("Older conversation: these commits are guessed from when it ran — other work landing then may show.")) + "</p>";
|
||
if (files.length) {
|
||
var done = files.filter(function (f) { return vmap[D.fileKey(f)]; }).length;
|
||
h += '<div class="dv-fhead"><div class="dv-label dv-grow">' + esc(t("Files")) + '</div><span class="dv-xs">' +
|
||
esc(t("{done} / {total} viewed", { done: done, total: files.length })) + "</span></div>" + progress(done / files.length) + '<div id="flist"></div>';
|
||
}
|
||
$("rail").innerHTML = h;
|
||
if (files.length) {
|
||
var all = viewComments();
|
||
D.fileList($("flist"), files, { lang: DV.lang(), viewed: vmap, comments: all, onOpen: function (path, f) { D.scrollToFile(document, f); } });
|
||
}
|
||
}
|
||
function drawChips() {
|
||
var h = chip(sel === "all", "all", "<b>" + esc(t("All")) + "</b> " + DV.statHtml(list ? list.additions : 0, list ? list.deletions : 0));
|
||
var s = selected();
|
||
commits().forEach(function (c) { h += chip(c === s, c.sha, '<span class="dv-sha">' + esc(DV.short(c)) + "</span>"); });
|
||
if (uncFiles()) h += chip(sel === "uncommitted", "uncommitted", '<span class="dv-amb">' + esc(t("Uncommitted")) + "</span>");
|
||
$("chips").innerHTML = h;
|
||
}
|
||
function chip(on, s, inner) {
|
||
return '<button type="button" class="dv-chip' + (on ? " dv-on" : "") + '" data-sel="' + esc(s) + '">' + inner + "</button>";
|
||
}
|
||
function progress(v) {
|
||
return '<div class="dv-prog"><div style="width:' + Math.round(v * 100) + '%"></div></div>';
|
||
}
|
||
function pills(c) {
|
||
var h = '<div class="dv-pills">';
|
||
if (c.worker) h += '<span class="dv-pill">' + icon("server") + esc(c.worker) + "</span>";
|
||
if (c.branch) h += '<span class="dv-pill dv-mono">' + icon("gitBranch") + '<span class="dv-trunc">' + esc(c.branch) + "</span></span>";
|
||
if (c.pushed) h += '<span class="dv-pill dv-ok" title="' + esc(t("A push in this conversation sent it to the remote")) + '">' + icon("upload") + esc(t("pushed")) + "</span>";
|
||
if (c.files > 0) h += '<span class="dv-pill">' + esc(tn(c.files, "{n} file", "{n} files")) + "</span>";
|
||
if (c.shared) h += '<span class="dv-warn" title="' + esc(t("Another command was running in the same repo when this commit landed — it may be another agent's")) + '">' + icon("alert") + esc(t("concurrent")) + "</span>";
|
||
return h + "</div>";
|
||
}
|
||
function drawHead(data) {
|
||
var c = selected(), h;
|
||
if (!c) {
|
||
h = '<div class="dv-headrow"><span class="dv-b dv-fg">' + esc(sel === "uncommitted" ? t("Not committed yet") : t("Every commit, as one diff")) + "</span>";
|
||
if (data) h += "<span>" + esc(tn(data.files.length, "{n} file", "{n} files")) + "</span>" + DV.statHtml(data.additions, data.deletions);
|
||
if (data && data.subtitle && sel === "uncommitted") h += '<span class="dv-trunc">' + esc(data.subtitle) + "</span>";
|
||
h += "</div>";
|
||
} else {
|
||
h = '<div class="dv-ch">' + icon(c.merge ? "gitMerge" : "gitCommit", "dv-pri dv-i16") + '<span class="dv-sha dv-12">' + esc(DV.short(c)) + "</span>" +
|
||
'<span class="dv-subj" title="' + esc(c.subject) + '">' + esc(c.subject) + "</span>" + DV.statHtml(c.additions, c.deletions) + "</div>" + pills(c);
|
||
}
|
||
$("head").innerHTML = h;
|
||
}
|
||
function unavailable(message) {
|
||
return '<div class="dv-unav">' + icon("alert", "dv-amb") + '<span class="dv-grow">' + esc(message) + '</span><button type="button" class="dv-retry" data-act="retry">' + esc(t("Retry")) + "</button></div>";
|
||
}
|
||
function drawBar() {
|
||
var n = review.comments.length, bar = $("bar");
|
||
if (!n) { bar.innerHTML = ""; bar.className = ""; return; }
|
||
var files = {};
|
||
review.comments.forEach(function (c) { files[c.file] = 1; });
|
||
var nf = Object.keys(files).length;
|
||
bar.className = "dv-bar";
|
||
bar.innerHTML = '<div class="dv-barin"><span class="dv-grow dv-trunc dv-12"><b>' + esc(tn(n, "{n} comment", "{n} comments")) + "</b> " +
|
||
'<span class="dv-mutc">' + esc(tn(nf, "on {n} file", "on {n} files")) + (sendErr ? "" : " · " + esc(t("drafts are saved"))) + "</span>" +
|
||
(sendErr ? '<span class="dv-err"> — ' + esc(sendErr) + "</span>" : "") + "</span>" +
|
||
'<button type="button" class="aia-btn aia-btn-sm" data-act="discard"' + (sending ? " disabled" : "") + ">" + esc(t("Discard")) + "</button>" +
|
||
'<button type="button" class="aia-btn aia-btn-sm aia-btn-primary" data-act="send"' + (sending ? " disabled" : "") + ">" +
|
||
(sending ? icon("loader", "aia-spin") : icon("send")) + '<span class="dv-wide">' + esc(t("Send review to Claude")) + '</span><span class="dv-narrow">' + esc(t("Send review")) + "</span></button></div>";
|
||
}
|
||
|
||
function draw() {
|
||
var empty = $("empty");
|
||
if (list && !commits().length && !uncFiles()) {
|
||
empty.hidden = false;
|
||
empty.innerHTML = icon("gitCommit", "dv-i24") + "<div>" + esc(t("No commits or uncommitted changes in this conversation.")) + "</div>";
|
||
app.classList.add("dv-isempty");
|
||
drawBar();
|
||
return;
|
||
}
|
||
empty.hidden = true;
|
||
app.classList.remove("dv-isempty");
|
||
var slot = (sel && diffs[sel]) || { loading: true };
|
||
var data = slot.data, files = (data && data.files) || [];
|
||
var vmap = viewedMap(files);
|
||
drawRail(files, vmap);
|
||
drawChips();
|
||
drawHead(data);
|
||
var done = files.filter(function (f) { return vmap[D.fileKey(f)]; }).length;
|
||
$("mprog").innerHTML = files.length ? '<div class="dv-mprog">' + progress(done / files.length) + '<span class="dv-xs">' +
|
||
esc(t("{done} / {total} viewed", { done: done, total: files.length })) + "</span></div>" : "";
|
||
var msg = "", c = selected();
|
||
if (!data && (slot.loading || !list)) {
|
||
msg = '<div class="dv-center">' + icon("loader", "aia-spin") + esc(c && c.worker ? t("Reading the commit from the worker…") : t("Loading the diff…")) + "</div>";
|
||
} else if (!data && slot.error) {
|
||
msg = unavailable(slot.error);
|
||
} else if (data && !files.length) {
|
||
msg = '<div class="dv-center">' + esc(c && c.merge ? t("A merge — its changes are the branch's own commits.") : t("No file changes.")) + "</div>";
|
||
} else if (data && data.unavailable) {
|
||
msg = unavailable(t("{message} — showing what the transcript recorded.", { message: data.unavailable.message }));
|
||
}
|
||
$("msg").innerHTML = msg;
|
||
if (files.length) {
|
||
filesEl.hidden = false;
|
||
D.renderFiles(filesEl, files, {
|
||
lang: DV.lang(),
|
||
viewed: vmap,
|
||
comments: viewComments(),
|
||
imageUrl: DV.imageUrlFor(c ? c.sha : null),
|
||
onOpenImage: DV.openImages,
|
||
onToggleViewed: function (path, on, f) {
|
||
var k = D.fileKey(f);
|
||
if (on) review.viewed[k] = D.signature(f); else delete review.viewed[k];
|
||
saveOp({ op: "viewed", file: k, sig: on ? D.signature(f) : null });
|
||
draw();
|
||
},
|
||
onComment: function (cm) {
|
||
var item = { id: newId(), file: cm.file, path: cm.path, view: sel, body: cm.text, at: Date.now() };
|
||
if (cm.line != null) item.line = { side: cm.side, no: cm.line, text: cm.lineText || "", type: cm.lineType || "ctx" };
|
||
review.comments = review.comments.concat([item]);
|
||
saveOp({ op: "add", comment: item });
|
||
draw();
|
||
},
|
||
onEditComment: function (cm, text) {
|
||
review.comments = review.comments.map(function (x) { return x.id === cm.id ? Object.assign({}, x, { body: text }) : x; });
|
||
saveOp({ op: "edit", id: cm.id, body: text });
|
||
draw();
|
||
},
|
||
onDeleteComment: function (cm) {
|
||
review.comments = review.comments.filter(function (x) { return x.id !== cm.id; });
|
||
saveOp({ op: "delete", id: cm.id });
|
||
draw();
|
||
}
|
||
});
|
||
} else {
|
||
filesEl.hidden = true;
|
||
filesEl.innerHTML = "";
|
||
}
|
||
drawBar();
|
||
}
|
||
|
||
// ── events ─────────────────────────────────────────────────────────────────
|
||
app.addEventListener("click", function (e) {
|
||
var b = e.target.closest && e.target.closest("[data-sel],[data-act]");
|
||
if (!b || filesEl.contains(b)) return;
|
||
var s = b.getAttribute("data-sel");
|
||
if (s) return select(s, false);
|
||
var act = b.getAttribute("data-act");
|
||
if (act === "retry") {
|
||
if (listQ) listQ.refresh();
|
||
if (active) { startReview(); if (diffQ) diffQ.refresh(); else loadDiff(); }
|
||
}
|
||
else if (act === "discard") { review.comments = []; saveOp({ op: "clear" }); sendErr = null; draw(); }
|
||
else if (act === "send") send();
|
||
});
|
||
|
||
var timer = null, endTimer = null, lastRefresh = 0;
|
||
function refreshSoon(ms) {
|
||
if (timer || !listQ) return;
|
||
var wait = Math.max(ms, 8000 - (Date.now() - lastRefresh));
|
||
timer = setTimeout(function () {
|
||
timer = null; lastRefresh = Date.now();
|
||
if (listQ) listQ.refresh();
|
||
if (active && diffQ && (sel === "all" || sel === "uncommitted")) diffQ.refresh();
|
||
}, wait);
|
||
}
|
||
function mine(ev) {
|
||
if (!conversationId) return false;
|
||
if (ev.id && (ev.id === conversationId || ev.id === sessionId)) return true;
|
||
return (ev.ids || []).indexOf(conversationId) >= 0 || (sessionId && (ev.ids || []).indexOf(sessionId) >= 0);
|
||
}
|
||
function switchTo(ncid, nsid, u) {
|
||
convGen++;
|
||
if (listQ && listQ.stop) listQ.stop();
|
||
if (reviewQ && reviewQ.stop) reviewQ.stop();
|
||
if (diffQ && diffQ.stop) diffQ.stop();
|
||
listQ = reviewQ = diffQ = null;
|
||
diffSel = null;
|
||
clearTimeout(timer); timer = null; lastRefresh = 0;
|
||
clearTimeout(endTimer); endTimer = null;
|
||
conversationId = ncid;
|
||
sessionId = nsid;
|
||
running = typeof u.running === "boolean" ? u.running : false;
|
||
active = typeof u.active === "boolean" ? u.active : false;
|
||
var np = u.params && typeof u.params === "object" ? u.params : {};
|
||
params = np;
|
||
list = null; listErr = null;
|
||
diffs = {};
|
||
review = { viewed: {}, comments: [] };
|
||
reviewLocal = false;
|
||
pendingOps = 0; saving = Promise.resolve();
|
||
sending = false; sendErr = null;
|
||
sel = null;
|
||
chosen = false;
|
||
var c = typeof np.c === "string" && np.c ? np.c : null;
|
||
if (c) { sel = c; chosen = true; }
|
||
tabShown = null;
|
||
var st = filesEl.__aiad;
|
||
if (st) { st.open = {}; st.draft = null; st.edit = null; }
|
||
if ($("scroll")) $("scroll").scrollTop = 0;
|
||
report(true, null);
|
||
start();
|
||
draw();
|
||
}
|
||
if (P.onEvent) P.onEvent(function (ev) {
|
||
if (!ev || !ev.type) return;
|
||
if ((ev.type === "transcript" || ev.type === "meta") && (mine(ev) || (!ev.id && !ev.ids))) refreshSoon(500);
|
||
});
|
||
if (P.onUpdate) P.onUpdate(function (u) {
|
||
if (!u || typeof u !== "object") return;
|
||
if (u.lang) { var was = DV.lang(); if (DV.setLang(u.lang) !== was) draw(); }
|
||
var ncid = u.conversationId !== undefined ? String(u.conversationId || "") : conversationId;
|
||
var nsid = u.sessionId !== undefined ? String(u.sessionId || "") : sessionId;
|
||
if (ncid !== conversationId || nsid !== sessionId) { switchTo(ncid, nsid, u); return; }
|
||
var c = u.params && typeof u.params.c === "string" ? u.params.c : null;
|
||
var selChanged = !!(c && c !== sel);
|
||
if (selChanged) {
|
||
sel = c; chosen = true;
|
||
var st = filesEl.__aiad;
|
||
if (st) { st.open = {}; st.draft = null; st.edit = null; }
|
||
$("scroll").scrollTop = 0;
|
||
}
|
||
var becameActive = false;
|
||
if (typeof u.active === "boolean" && u.active !== active) {
|
||
active = u.active;
|
||
becameActive = active;
|
||
}
|
||
if (active && (becameActive || selChanged)) {
|
||
startReview();
|
||
if (selChanged || !diffQ) loadDiff();
|
||
else if (sel === "all" || sel === "uncommitted") diffQ.refresh();
|
||
draw();
|
||
} else if (selChanged) {
|
||
draw();
|
||
}
|
||
if (typeof u.running === "boolean" && u.running !== running) {
|
||
running = u.running;
|
||
if (!running) {
|
||
clearTimeout(endTimer);
|
||
var g = convGen;
|
||
endTimer = setTimeout(function () { if (g !== convGen) return; lastRefresh = 0; refreshSoon(0); }, 3000);
|
||
}
|
||
}
|
||
});
|
||
start();
|
||
draw();
|
||
})();
|
||
|
||
</script>
|
||
</body></html>
|