{"draft":null,"from":150,"to":151,"files":[{"path":"server/src/issues/seats.ts","added":49,"removed":0,"diff":"--- /dev/null\n+++ b/server/src/issues/seats.ts\n@@ -0,0 +1,49 @@\n+// Asks go to seats: an ask to a name that isn't an agent in the project would\n+// wait on nobody, so it's refused, with the closest seat named. Seats are only\n+// ever this project's own.\n+\n+/** A name as people write it: lower case, letters and digits only (\"abso - Cloud Infra Lead\" → \"absocloudinfralead\"). */\n+function plain(name: string): string {\n+\treturn name.toLowerCase().replace(/[^a-z0-9]/g, \"\");\n+}\n+\n+/** Edits from a to b: insertions, deletions and substitutions. */\n+function distance(a: string, b: string): number {\n+\tlet row = Array.from({ length: b.length + 1 }, (_, i) => i);\n+\tfor (let i = 1; i <= a.length; i++) {\n+\t\tconst next = [i];\n+\t\tfor (let j = 1; j <= b.length; j++)\n+\t\t\tnext[j] = Math.min(row[j]! + 1, next[j - 1]! + 1, row[j - 1]! + (a[i - 1] === b[j - 1] ? 0 : 1));\n+\t\trow = next;\n+\t}\n+\treturn row[b.length]!;\n+}\n+\n+/**\n+ * The seat a name most likely meant, or null. The same name written another way wins; then the longest seat\n+ * the name holds (\"abso - Cloud Infra Lead\" holds cloud), or that holds the name; then a near spelling.\n+ */\n+export function closestSeat(name: string, seats: readonly string[]): string | null {\n+\tconst n = plain(name);\n+\tif (n === \"\") return null;\n+\tconst same = seats.find((s) => plain(s) === n);\n+\tif (same) return same;\n+\tconst held = seats\n+\t\t.filter((s) => plain(s).length >= 3 && (n.includes(plain(s)) || plain(s).includes(n)))\n+\t\t.sort((a, b) => plain(b).length - plain(a).length);\n+\tif (held[0]) return held[0];\n+\tlet best: string | null = null;\n+\tlet least = Math.max(2, Math.floor(n.length / 3)) + 1;\n+\tfor (const s of seats) {\n+\t\tconst d = distance(n, plain(s));\n+\t\tif (d < least) [best, least] = [s, d];\n+\t}\n+\treturn best;\n+}\n+\n+/** Why an ask to `of` is refused, or null when `of` is a seat. */\n+export function seatRefusal(of: string, project: string, seats: readonly string[]): string | null {\n+\tif (seats.includes(of)) return null;\n+\tconst near = closestSeat(of, seats);\n+\treturn `${JSON.stringify(of)} isn't an agent in ${project}, so nobody would hear the ask${near ? `; did you mean ${near}?` : \".\"} abso status lists the agents.`;\n+}"}],"unmatched":[]}