-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog_diagnostics.js
More file actions
149 lines (140 loc) · 5.29 KB
/
Copy pathlog_diagnostics.js
File metadata and controls
149 lines (140 loc) · 5.29 KB
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
// Local-only power-user diagnostics for the probe log viewer.
globalThis.__static_log_diagnostics__ = (() => {
const CFG = globalThis.__static_config__ || {};
const CHROME_EXT_ID_RE = /^[a-p]{32}$/;
const UUID_EXT_ID_RE = /^[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}$/i;
const isValidExtensionId = (id) =>
typeof id === "string" && (CHROME_EXT_ID_RE.test(id) || UUID_EXT_ID_RE.test(id));
const fmt = (n) => n.toLocaleString();
const sortedCountEntries = (counts, limit = 6) =>
Object.entries(counts || {})
.filter(([, count]) => typeof count === "number" && count > 0)
.sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
.slice(0, limit);
const formatCountEntries = (counts) => {
const entries = sortedCountEntries(counts);
return entries.length
? entries.map(([key, count]) => `${key} ${fmt(count)}`).join(", ")
: "none";
};
const countIdPressure = (counts) => {
const entries = Object.entries(counts || {}).filter(([, count]) => count > 0);
const unique = entries.length;
const repeated = entries.filter(([, count]) => count >= 2).length;
const oneShot = entries.filter(([, count]) => count === 1).length;
return {
oneShot,
oneShotPct: unique ? Math.round((oneShot / unique) * 100) : 0,
repeated,
unique,
};
};
const knownNoiseIds = () => {
const ids = new Set();
for (const slotIds of Object.values(CFG.conflictSlots || {})) {
for (const id of slotIds) ids.add(id);
}
return ids;
};
const noiseReadinessFor = (entry) => {
const knownIds = knownNoiseIds();
const minKnown = CFG.personaMinCount || 2;
const minUnknown = CFG.unknownPersonaMinCount || 20;
let knownEligible = 0;
let unknownEligible = 0;
const eligibleIds = [];
for (const [id, count] of Object.entries((entry && entry.idCounts) || {})) {
const safeId = id.toLowerCase();
const known = knownIds.has(safeId);
const minCount = known ? minKnown : minUnknown;
if (isValidExtensionId(safeId) && typeof count === "number" && count >= minCount) {
knownEligible += known ? 1 : 0;
unknownEligible += known ? 0 : 1;
eligibleIds.push(safeId);
}
}
return { eligibleIds, knownEligible, minKnown, minUnknown, unknownEligible };
};
const buildMetricDetail = (titleText, rows) => {
const box = document.createElement("div");
box.className = "drift-detail";
const title = document.createElement("div");
title.className = "drift-detail-title";
title.textContent = titleText;
box.appendChild(title);
const list = document.createElement("ul");
list.className = "metric-list";
for (const [key, value] of rows.filter(([, rowValue]) => rowValue)) {
const li = document.createElement("li");
const k = document.createElement("span");
k.className = "k";
k.textContent = key;
const v = document.createElement("span");
v.className = "v";
v.textContent = value;
li.appendChild(k);
li.appendChild(v);
list.appendChild(li);
}
box.appendChild(list);
return box;
};
const buildPlaybookDetail = (entry, comparison) => {
if (!comparison) return null;
const { latestKey, current, baseline } = comparison;
const latestIds = countIdPressure(current.idCounts);
const weekCount = Object.keys((entry.playbook && entry.playbook.weeks) || {}).length;
const priorWeeks = Math.max(0, weekCount - 1);
return buildMetricDetail("Probe playbook", [
["Latest week", `${latestKey}; ${fmt(current.total || 0)} probes`],
[
"Baseline",
`${fmt(baseline.total || 0)} probes across ${fmt(priorWeeks)} prior week${
priorWeeks === 1 ? "" : "s"
}`,
],
["Latest vectors", formatCountEntries(current.vectorCounts)],
["Latest path kinds", formatCountEntries(current.pathKindCounts)],
[
"Latest ID pressure",
`${fmt(latestIds.unique)} unique, ${fmt(latestIds.repeated)} repeated, ${
latestIds.oneShotPct
}% one-shot`,
],
]);
};
const buildNoiseReadinessDetail = (entry) => {
const readiness = noiseReadinessFor(entry);
const target = CFG.personaSize || { min: 3, max: 8 };
const pressure = countIdPressure(entry.idCounts);
const rotationWeeks = CFG.personaRotationWeeks || 1;
return buildMetricDetail("Noise readiness", [
[
"Eligible pool",
`${fmt(readiness.knownEligible + readiness.unknownEligible)} IDs (${fmt(
readiness.knownEligible
)} known-list, ${fmt(readiness.unknownEligible)} repeated unknown)`,
],
[
"Persona target",
`${fmt(target.min || 3)}-${fmt(target.max || 8)} IDs; rotates every ${fmt(
rotationWeeks
)} week${rotationWeeks === 1 ? "" : "s"}`,
],
[
"Thresholds",
`known IDs need ${fmt(readiness.minKnown)} probes; unknown IDs need ${fmt(
readiness.minUnknown
)} probes`,
],
[
"Canary pressure",
`${fmt(pressure.oneShot)} one-shot IDs out of ${fmt(pressure.unique)} unique (${
pressure.oneShotPct
}%)`,
],
["Eligible IDs", readiness.eligibleIds.slice(0, 12).join(", ") || "none yet"],
]);
};
return { buildNoiseReadinessDetail, buildPlaybookDetail, noiseReadinessFor };
})();