diffdesk 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. diffdesk/__init__.py +3 -0
  2. diffdesk/agent.py +414 -0
  3. diffdesk/agent_guide.md +112 -0
  4. diffdesk/cli.py +329 -0
  5. diffdesk/config.py +130 -0
  6. diffdesk/gitio.py +391 -0
  7. diffdesk/index.py +635 -0
  8. diffdesk/mcp.py +472 -0
  9. diffdesk/server.py +750 -0
  10. diffdesk/static/app.js +402 -0
  11. diffdesk/static/index.html +129 -0
  12. diffdesk/static/js/api.js +58 -0
  13. diffdesk/static/js/boot.js +12 -0
  14. diffdesk/static/js/diffview.js +359 -0
  15. diffdesk/static/js/dom.js +82 -0
  16. diffdesk/static/js/editor-cm.js +225 -0
  17. diffdesk/static/js/editor-monaco.js +116 -0
  18. diffdesk/static/js/flow.js +227 -0
  19. diffdesk/static/js/hunks.js +40 -0
  20. diffdesk/static/js/markdown.js +102 -0
  21. diffdesk/static/js/settings.js +228 -0
  22. diffdesk/static/js/subject.js +127 -0
  23. diffdesk/static/js/tree.js +492 -0
  24. diffdesk/static/js/treemap.js +217 -0
  25. diffdesk/static/style.css +508 -0
  26. diffdesk/static/vendor/LICENSES.txt +603 -0
  27. diffdesk/static/vendor/codemirror.js +24 -0
  28. diffdesk/static/vendor/fonts/KaTeX_AMS-Regular.woff2 +0 -0
  29. diffdesk/static/vendor/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
  30. diffdesk/static/vendor/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
  31. diffdesk/static/vendor/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
  32. diffdesk/static/vendor/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
  33. diffdesk/static/vendor/fonts/KaTeX_Main-Bold.woff2 +0 -0
  34. diffdesk/static/vendor/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
  35. diffdesk/static/vendor/fonts/KaTeX_Main-Italic.woff2 +0 -0
  36. diffdesk/static/vendor/fonts/KaTeX_Main-Regular.woff2 +0 -0
  37. diffdesk/static/vendor/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
  38. diffdesk/static/vendor/fonts/KaTeX_Math-Italic.woff2 +0 -0
  39. diffdesk/static/vendor/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
  40. diffdesk/static/vendor/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
  41. diffdesk/static/vendor/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
  42. diffdesk/static/vendor/fonts/KaTeX_Script-Regular.woff2 +0 -0
  43. diffdesk/static/vendor/fonts/KaTeX_Size1-Regular.woff2 +0 -0
  44. diffdesk/static/vendor/fonts/KaTeX_Size2-Regular.woff2 +0 -0
  45. diffdesk/static/vendor/fonts/KaTeX_Size3-Regular.woff2 +0 -0
  46. diffdesk/static/vendor/fonts/KaTeX_Size4-Regular.woff2 +0 -0
  47. diffdesk/static/vendor/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
  48. diffdesk/static/vendor/fonts/OFL.txt +102 -0
  49. diffdesk/static/vendor/katex.css +2 -0
  50. diffdesk/static/vendor/katex.js +258 -0
  51. diffdesk/static/vendor/marked.js +72 -0
  52. diffdesk/subject.schema.json +59 -0
  53. diffdesk-0.1.0.dist-info/METADATA +520 -0
  54. diffdesk-0.1.0.dist-info/RECORD +59 -0
  55. diffdesk-0.1.0.dist-info/WHEEL +4 -0
  56. diffdesk-0.1.0.dist-info/entry_points.txt +2 -0
  57. diffdesk-0.1.0.dist-info/licenses/LICENSE +21 -0
  58. diffdesk-0.1.0.dist-info/licenses/src/diffdesk/static/vendor/LICENSES.txt +603 -0
  59. diffdesk-0.1.0.dist-info/licenses/src/diffdesk/static/vendor/fonts/OFL.txt +102 -0
@@ -0,0 +1,217 @@
1
+ // Treemap view on a canvas: packages, then subjects. Area = lines changed (added + deleted).
2
+ import { api } from './api.js';
3
+ import { h, frameOnce, STATUS_ORDER, STATUS_LABEL } from './dom.js';
4
+
5
+ /**
6
+ * Squarified treemap layout (Bruls, Huizing and van Wijk, 2000).
7
+ *
8
+ * Rectangle areas are proportional to `value`. Items with `value <= 0` get no rectangle.
9
+ *
10
+ * @param {{value: number}[]} items
11
+ * @param {{x: number, y: number, w: number, h: number}} rect
12
+ * @returns {{item: object, x: number, y: number, w: number, h: number}[]}
13
+ */
14
+ export function squarify(items, rect) {
15
+ const list = items.filter((it) => it.value > 0).sort((a, b) => b.value - a.value);
16
+ const total = list.reduce((s, it) => s + it.value, 0);
17
+ const out = [];
18
+ if (!total || !(rect.w > 0) || !(rect.h > 0)) return out;
19
+ const areas = list.map((it) => (it.value * rect.w * rect.h) / total);
20
+ // Worst aspect ratio of a row with area sum `s`, smallest area `lo`, largest `hi`, laid along `side`.
21
+ const worst = (s, lo, hi, side) => Math.max((side * side * hi) / (s * s), (s * s) / (side * side * lo));
22
+ let { x, y, w, h: ht } = rect;
23
+ let start = 0;
24
+ while (start < areas.length) {
25
+ const side = Math.min(w, ht);
26
+ let sum = areas[start];
27
+ let lo = sum;
28
+ let hi = sum;
29
+ let best = worst(sum, lo, hi, side);
30
+ let end = start + 1;
31
+ while (end < areas.length) {
32
+ const a = areas[end];
33
+ const next = worst(sum + a, Math.min(lo, a), Math.max(hi, a), side);
34
+ if (next > best) break;
35
+ sum += a;
36
+ lo = Math.min(lo, a);
37
+ hi = Math.max(hi, a);
38
+ best = next;
39
+ end++;
40
+ }
41
+ const thick = sum / side;
42
+ let offset = 0;
43
+ for (let k = start; k < end; k++) {
44
+ const len = areas[k] / thick;
45
+ if (w >= ht) out.push({ item: list[k], x, y: y + offset, w: thick, h: len });
46
+ else out.push({ item: list[k], x: x + offset, y, w: len, h: thick });
47
+ offset += len;
48
+ }
49
+ if (w >= ht) {
50
+ x += thick;
51
+ w = Math.max(0, w - thick);
52
+ } else {
53
+ y += thick;
54
+ ht = Math.max(0, ht - thick);
55
+ }
56
+ start = end;
57
+ }
58
+ return out;
59
+ }
60
+
61
+ function parseColor(text) {
62
+ const s = text.trim();
63
+ let m = /^#([0-9a-f]{3,8})$/i.exec(s);
64
+ if (m) {
65
+ let hex = m[1];
66
+ if (hex.length <= 4) hex = [...hex].map((c) => c + c).join('');
67
+ return [0, 2, 4].map((i) => parseInt(hex.slice(i, i + 2), 16));
68
+ }
69
+ m = /rgba?\(([^)]+)\)/.exec(s);
70
+ return m ? m[1].split(/[ ,/]+/).slice(0, 3).map(Number) : [128, 128, 128];
71
+ }
72
+
73
+ function luminance([r, g, b]) {
74
+ const f = (c) => {
75
+ const v = c / 255;
76
+ return v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
77
+ };
78
+ return 0.2126 * f(r) + 0.7152 * f(g) + 0.0722 * f(b);
79
+ }
80
+
81
+ /** Black or white, whichever has the larger WCAG contrast ratio on `fill`. */
82
+ function textOn(fill) {
83
+ const l = luminance(parseColor(fill));
84
+ return (l + 0.05) / 0.05 >= 1.05 / (l + 0.05) ? '#000' : '#fff';
85
+ }
86
+
87
+ const linesOf = (it) => (it.lines_added || 0) + (it.lines_deleted || 0);
88
+
89
+ export class TreemapView {
90
+ constructor(el, { onOpen }) {
91
+ this.el = el;
92
+ this.onOpen = onOpen;
93
+ this.items = [];
94
+ this.rects = [];
95
+ this.groups = [];
96
+ this.pkg = null;
97
+ this.box = h('div', { class: 'canvas-box' });
98
+ this.canvas = h('canvas', { role: 'img', 'aria-label': 'Treemap of subjects. Area is lines changed, colour is status.' });
99
+ this.box.append(this.canvas);
100
+ this.legend = h('div', { class: 'legend' });
101
+ this.note = h('div', { class: 'view-note' });
102
+ el.append(this.legend, this.box, this.note);
103
+ this.tooltip = document.getElementById('tooltip');
104
+ this.redraw = frameOnce(() => this.draw());
105
+ new ResizeObserver(this.redraw).observe(this.box);
106
+ this.canvas.addEventListener('mousemove', (e) => this.hover(e));
107
+ this.canvas.addEventListener('mouseleave', () => { this.tooltip.hidden = true; });
108
+ this.canvas.addEventListener('click', (e) => {
109
+ const hit = this.hit(e);
110
+ if (hit) this.onOpen(hit.item);
111
+ });
112
+ }
113
+
114
+ async refresh(pkg = this.pkg) {
115
+ this.pkg = pkg;
116
+ this.items = await api.treemap(pkg);
117
+ const zero = this.items.filter((it) => linesOf(it) <= 0);
118
+ this.note.replaceChildren(zero.length
119
+ ? `${zero.length} subject${zero.length === 1 ? ' has' : 's have'} no changed lines and ${zero.length === 1 ? 'is' : 'are'} not shown: ${zero.map((it) => it.id).join(', ')}.`
120
+ : '');
121
+ const counts = Object.fromEntries(STATUS_ORDER.map((s) => [s, this.items.filter((it) => it.status === s).length]));
122
+ this.legend.replaceChildren(...STATUS_ORDER.map((s) => h('span', {}, h('i', { class: `st-${s}` }), `${STATUS_LABEL[s]} ${counts[s]}`)));
123
+ this.redraw();
124
+ }
125
+
126
+ draw() {
127
+ const rect = this.box.getBoundingClientRect();
128
+ const dpr = window.devicePixelRatio || 1;
129
+ const width = Math.floor(rect.width);
130
+ const height = Math.floor(rect.height);
131
+ if (!width || !height) return;
132
+ this.canvas.width = width * dpr;
133
+ this.canvas.height = height * dpr;
134
+ const ctx = this.canvas.getContext('2d');
135
+ ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
136
+ const css = getComputedStyle(document.documentElement);
137
+ const color = (name) => css.getPropertyValue(name).trim();
138
+ const fills = Object.fromEntries(STATUS_ORDER.map((s) => [s, color(`--st-${s}`)]));
139
+ const bg = color('--bg');
140
+ const fg = color('--fg');
141
+ const font = parseFloat(css.getPropertyValue('--ui-font-size')) || 13;
142
+ ctx.clearRect(0, 0, width, height);
143
+
144
+ const byPkg = new Map();
145
+ for (const it of this.items) {
146
+ if (!byPkg.has(it.package)) byPkg.set(it.package, []);
147
+ byPkg.get(it.package).push(it);
148
+ }
149
+ const pkgs = [...byPkg].map(([name, list]) => ({ name, list, value: list.reduce((s, it) => s + linesOf(it), 0) }));
150
+ this.groups = squarify(pkgs, { x: 0, y: 0, w: width, h: height });
151
+ this.rects = [];
152
+ ctx.textBaseline = 'top';
153
+ ctx.font = `${font * 0.85}px ${css.fontFamily}`;
154
+ for (const g of this.groups) {
155
+ const cells = squarify(g.item.list.map((it) => ({ ...it, value: linesOf(it) })), g);
156
+ for (const c of cells) {
157
+ const fill = fills[c.item.status] || fills.pending;
158
+ ctx.fillStyle = fill;
159
+ ctx.fillRect(c.x, c.y, c.w, c.h);
160
+ ctx.strokeStyle = bg;
161
+ ctx.lineWidth = 1;
162
+ ctx.strokeRect(c.x + 0.5, c.y + 0.5, c.w - 1, c.h - 1);
163
+ const label = c.item.id;
164
+ const tw = ctx.measureText(label).width;
165
+ if (tw + 6 <= c.w && font + 4 <= c.h) {
166
+ ctx.fillStyle = textOn(fill);
167
+ ctx.fillText(label, c.x + 3, c.y + 3);
168
+ }
169
+ this.rects.push(c);
170
+ }
171
+ }
172
+ ctx.font = `600 ${font}px ${css.fontFamily}`;
173
+ for (const g of this.groups) {
174
+ ctx.strokeStyle = fg;
175
+ ctx.lineWidth = 2;
176
+ ctx.strokeRect(g.x + 1, g.y + 1, g.w - 2, g.h - 2);
177
+ const tw = ctx.measureText(g.item.name).width;
178
+ const lh = font * 1.3;
179
+ if (tw + 8 <= g.w && lh + 8 <= g.h) {
180
+ const y = g.y + g.h - lh - 3;
181
+ ctx.fillStyle = bg;
182
+ ctx.fillRect(g.x + 3, y, tw + 6, lh);
183
+ ctx.fillStyle = fg;
184
+ ctx.fillText(g.item.name, g.x + 6, y + (lh - font) / 2);
185
+ }
186
+ }
187
+ }
188
+
189
+ hit(e) {
190
+ const r = this.canvas.getBoundingClientRect();
191
+ const x = e.clientX - r.left;
192
+ const y = e.clientY - r.top;
193
+ return this.rects.find((c) => x >= c.x && x < c.x + c.w && y >= c.y && y < c.y + c.h) || null;
194
+ }
195
+
196
+ hover(e) {
197
+ const hit = this.hit(e);
198
+ const tip = this.tooltip;
199
+ if (!hit) {
200
+ tip.hidden = true;
201
+ return;
202
+ }
203
+ const it = hit.item;
204
+ tip.replaceChildren(
205
+ h('b', { text: it.id }), ` ${it.title}`,
206
+ h('div', { class: 'dim', text: `${it.package}${it.branch ? ` / ${it.branch}` : ''}. ${STATUS_LABEL[it.status] || it.status}. +${it.lines_added || 0} −${it.lines_deleted || 0} lines.` }),
207
+ );
208
+ tip.hidden = false;
209
+ const pad = 12;
210
+ const w = tip.offsetWidth;
211
+ const ht = tip.offsetHeight;
212
+ const left = e.clientX + pad + w > window.innerWidth ? e.clientX - pad - w : e.clientX + pad;
213
+ const top = e.clientY + pad + ht > window.innerHeight ? e.clientY - pad - ht : e.clientY + pad;
214
+ tip.style.left = `${Math.max(0, left)}px`;
215
+ tip.style.top = `${Math.max(0, top)}px`;
216
+ }
217
+ }