husteno-o feat: P0 critical fixes + rich code review + watchtower events · 9/10/2026
5d7e43b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
export interface BarChartItem {
label: string;
value: number;
displayValue?: string | number;
}
export function renderProgressBar(percentage: number, totalBlocks = 10): string {
const clamped = Math.max(0, Math.min(100, percentage));
const filledBlocks = Math.round((clamped / 100) * totalBlocks);
const emptyBlocks = totalBlocks - filledBlocks;
return `${"█".repeat(filledBlocks)}${"░".repeat(emptyBlocks)} ${clamped.toFixed(0)}%`;
}
export function renderHorizontalBarChart(
items: BarChartItem[],
options: {
maxBarLength?: number;
showValues?: boolean;
barChar?: string;
} = {},
): string {
if (items.length === 0) return "No data available";
const { maxBarLength = 12, showValues = true, barChar = "█" } = options;
const maxValue = Math.max(...items.map((i) => i.value), 1);
const maxLabelLength = Math.max(...items.map((i) => i.label.length), 0);
return items
.map((item) => {
const labelPadded = item.label.padEnd(maxLabelLength, " ");
const barLength = Math.max(0, Math.round((item.value / maxValue) * maxBarLength));
const bar = barLength > 0 ? barChar.repeat(barLength) : "▏";
const valStr = showValues ? ` ${item.displayValue ?? item.value}` : "";
return `${labelPadded} ${bar}${valStr}`;
})
.join("\n");
}
export function renderSparkline(values: number[]): string {
if (values.length === 0) return "";
const ticks = [" ", "▂", "▃", "▄", "▅", "▆", "▇", "█"];
const min = Math.min(...values);
const max = Math.max(...values);
const range = max - min;
return values
.map((val) => {
if (range === 0) return ticks[0];
const index = Math.min(ticks.length - 1, Math.floor(((val - min) / range) * ticks.length));
return ticks[index];
})
.join("");
}
export function renderAsciiTable(headers: string[], rows: string[][]): string {
if (rows.length === 0) return "Empty table";
const colWidths = headers.map((h, i) => {
const rowMax = rows.reduce((max, row) => Math.max(max, (row[i] || "").length), 0);
return Math.max(h.length, rowMax);
});
const headerLine = headers.map((h, i) => h.padEnd(colWidths[i])).join(" | ");
const separatorLine = colWidths.map((w) => "-".repeat(w)).join("-+-");
const dataLines = rows.map((row) =>
headers.map((_, i) => (row[i] || "").padEnd(colWidths[i])).join(" | "),
);
return [headerLine, separatorLine, ...dataLines].join("\n");
}
export interface PieSlice {
label: string;
value: number;
color?: string;
}
const PIE_COLORS = ["🟦", "🟩", "🟧", "🟥", "🟪", "🟨", "⬜", "🟫"];
export function renderPieChart(slices: PieSlice[], size = 4): string {
const total = slices.reduce((sum, s) => sum + s.value, 0);
if (total === 0) return "No data";
const normalized = slices.map((s, i) => ({
...s,
pct: (s.value / total) * 100,
icon: s.color || PIE_COLORS[i % PIE_COLORS.length],
}));
const grid: string[][] = [];
const rows = size * 2;
const cols = size * 4;
const cy = size;
const cx = size * 2;
const ry = size;
const rx = size * 2;
for (let y = 0; y < rows; y++) {
grid[y] = [];
for (let x = 0; x < cols; x++) {
const dy = (y - cy) / ry;
const dx = (x - cx) / rx;
const dist = dx * dx + dy * dy;
if (dist > 1) {
grid[y][x] = " ";
continue;
}
const angle = Math.atan2(dy, dx);
const normalizedAngle = angle < 0 ? angle + 2 * Math.PI : angle;
let cumulative = 0;
let sliceIndex = 0;
for (let i = 0; i < normalized.length; i++) {
cumulative += (normalized[i].pct / 100) * 2 * Math.PI;
if (normalizedAngle <= cumulative) {
sliceIndex = i;
break;
}
}
grid[y][x] = normalized[sliceIndex].icon;
}
}
const legend = normalized.map((s) => `${s.icon} ${s.label} (${s.pct.toFixed(0)}%)`).join("\n");
return grid.map((row) => row.join("")).join("\n") + "\n" + legend;
}
export function renderDonutChart(slices: PieSlice[], size = 4): string {
const total = slices.reduce((sum, s) => sum + s.value, 0);
if (total === 0) return "No data";
const normalized = slices.map((s, i) => ({
...s,
pct: (s.value / total) * 100,
icon: s.color || PIE_COLORS[i % PIE_COLORS.length],
}));
const grid: string[][] = [];
const rows = size * 2;
const cols = size * 4;
const cy = size;
const cx = size * 2;
const ry = size;
const rx = size * 2;
const innerRy = size * 0.5;
const innerRx = size * 1.0;
for (let y = 0; y < rows; y++) {
grid[y] = [];
for (let x = 0; x < cols; x++) {
const dy = (y - cy) / ry;
const dx = (x - cx) / rx;
const dist = dx * dx + dy * dy;
const innerDy = (y - cy) / innerRy;
const innerDx = (x - cx) / innerRx;
const innerDist = innerDx * innerDx + innerDy * innerDy;
if (dist > 1 || innerDist < 1) {
grid[y][x] = " ";
continue;
}
const angle = Math.atan2(dy, dx);
const normalizedAngle = angle < 0 ? angle + 2 * Math.PI : angle;
let cumulative = 0;
let sliceIndex = 0;
for (let i = 0; i < normalized.length; i++) {
cumulative += (normalized[i].pct / 100) * 2 * Math.PI;
if (normalizedAngle <= cumulative) {
sliceIndex = i;
break;
}
}
grid[y][x] = normalized[sliceIndex].icon;
}
}
const centerText = `${total}`;
const centerX = Math.floor(cols / 2) - Math.floor(centerText.length / 2);
const centerY = Math.floor(rows / 2);
for (let i = 0; i < centerText.length; i++) {
if (grid[centerY] && grid[centerY][centerX + i] === " ") {
grid[centerY][centerX + i] = centerText[i] + " ";
}
}
return grid.map((row) => row.join("")).join("\n");
}
export function renderHeatmap(data: number[][], options: { maxCols?: number; maxRows?: number } = {}): string {
const { maxCols = 14, maxRows = 7 } = options;
if (data.length === 0 || data[0].length === 0) return "No data";
const flat = data.flat();
const min = Math.min(...flat);
const max = Math.max(...flat);
const range = max - min || 1;
const heatChars = [" ", "░", "▒", "▓", "█"];
const result: string[] = [];
for (let r = 0; r < Math.min(data.length, maxRows); r++) {
let row = "";
for (let c = 0; c < Math.min(data[r].length, maxCols); c++) {
const val = data[r][c];
const idx = Math.min(heatChars.length - 1, Math.floor(((val - min) / range) * heatChars.length));
row += heatChars[idx];
}
result.push(row);
}
return result.join("\n");
}
export function renderRadarChart(
axes: { label: string; value: number }[],
size = 8,
): string {
if (axes.length < 3) return "Need at least 3 axes";
const n = axes.length;
const centerX = size * 2;
const centerY = size;
const radius = size;
const grid: string[][] = [];
for (let y = 0; y <= size * 2; y++) {
grid[y] = [];
for (let x = 0; x <= size * 4; x++) {
grid[y][x] = " ";
}
}
const points: { x: number; y: number }[] = [];
for (let i = 0; i < n; i++) {
const angle = (Math.PI * 2 * i) / n - Math.PI / 2;
const x = centerX + Math.cos(angle) * radius;
const y = centerY + Math.sin(angle) * radius;
points.push({ x, y });
}
for (let ring = 1; ring <= 3; ring++) {
const ringRadius = (radius * ring) / 3;
for (let i = 0; i < n; i++) {
const angle = (Math.PI * 2 * i) / n - Math.PI / 2;
const px = centerX + Math.cos(angle) * ringRadius;
const py = centerY + Math.sin(angle) * ringRadius;
const ix = Math.round(px);
const iy = Math.round(py);
if (grid[iy] && grid[iy][ix] === " ") {
grid[iy][ix] = "·";
}
}
}
for (let i = 0; i < n; i++) {
const angle = (Math.PI * 2 * i) / n - Math.PI / 2;
const valRadius = (radius * (axes[i].value || 0)) / 100;
const px = centerX + Math.cos(angle) * valRadius;
const py = centerY + Math.sin(angle) * valRadius;
const ix = Math.round(px);
const iy = Math.round(py);
if (grid[iy] && grid[iy][ix]) {
grid[iy][ix] = "●";
}
}
const axisLabels = axes.map((a, i) => {
const angle = (Math.PI * 2 * i) / n - Math.PI / 2;
const lx = centerX + Math.cos(angle) * (radius + 1.5);
const ly = centerY + Math.sin(angle) * (radius + 0.5);
return { label: a.label.slice(0, 4), x: Math.round(lx), y: Math.round(ly) };
});
let result = grid.map((row) => row.join("")).join("\n");
result += "\n" + axisLabels.map((l) => `${l.label}: ${axes.find((a) => a.label.startsWith(l.label))?.value ?? 0}%`).join(" | ");
return result;
}
export function renderStackedBar(label: string, segments: { value: number; color?: string }[], totalWidth = 20): string {
const total = segments.reduce((sum, s) => sum + s.value, 0);
if (total === 0) return `${label.padEnd(12)} ${"░".repeat(totalWidth)} 0`;
const blocks = ["█", "▓", "▒", "░"];
let bar = "";
let pos = 0;
for (let i = 0; i < segments.length; i++) {
const segWidth = Math.round((segments[i].value / total) * totalWidth);
const blockChar = segments[i].color || blocks[i % blocks.length];
bar += blockChar.repeat(Math.max(0, segWidth));
pos += segWidth;
}
if (pos < totalWidth) bar += "░".repeat(totalWidth - pos);
if (pos > totalWidth) bar = bar.slice(0, totalWidth);
return `${label.padEnd(12)} ${bar} ${total}`;
}
export function renderCommitActivityGrid(weeks: number[][]): string {
const days = ["S", "M", "T", "W", "T", "F", "S"];
let result = " " + days.join(" ") + "\n";
const flat = weeks.flat();
const max = Math.max(...flat, 1);
const levels = [" ", "▁", "▃", "▅", "▇"];
for (let w = 0; w < weeks.length; w++) {
const week = weeks[w];
const rowNum = String(w + 1).padStart(2);
let row = `${rowNum} `;
for (let d = 0; d < 7; d++) {
const val = week[d] || 0;
const idx = Math.min(levels.length - 1, Math.floor((val / max) * levels.length));
row += levels[idx] + " ";
}
result += row + "\n";
}
return result;
}