Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t.sh
569 linesCodeBlameRaw
1/**
2 * Coordinating work, as the site shows it: who is on which issue (claims),
3 * which harness sessions are running, what the merge queue found when it
4 * combined changes, and the decision records behind the result. Pure: the
5 * pages and components/coordination.tsx draw what these say.
6 */
7import type {
8 Claim,
9 ClaimState,
10 Decision,
11 DecisionConfidence,
12 EventType,
13 G1tEvent,
14 Harness,
15 LinkVia,
16 SessionState,
17 TouchKind,
18 WorkSession,
19} from "@g1t/contracts";
20
21/** How each harness is named. */
22export const HARNESS_NAMES: Record<Harness, string> = {
23 claude_code: "Claude Code",
24 claude_managed_agents: "Claude Managed Agents",
25 codex: "Codex",
26 cursor: "Cursor",
27 copilot: "Copilot",
28 other: "Another harness",
29};
30
31export function harnessName(harness: Harness | null | undefined): string | null {
32 return harness ? (HARNESS_NAMES[harness] ?? harness) : null;
33}
34
35/** The coordination events the Work page lists, newest first. */
36export const COORDINATION_TYPES = [
37 "work.claimed",
38 "work.released",
39 "work.claim_expired",
40 "work.handoff_requested",
41 "session.started",
42 "session.ended",
43 "dependency.changed",
44 "overlap.detected",
45 "integration.failed",
46 "integration.passed",
47 "decision.recorded",
48] as const satisfies readonly EventType[];
49
50export type CoordinationType = (typeof COORDINATION_TYPES)[number];
51
52// ── Time ────────────────────────────────────────────────────────────────
53
54const MINUTE = 60_000;
55
56/** "4m", "1h 20m", "2h": a span, for "expires in …". */
57export function span(ms: number): string {
58 const minutes = Math.max(0, Math.floor(ms / MINUTE));
59 if (minutes < 1) return "less than a minute";
60 if (minutes < 60) return `${minutes}m`;
61 const hours = Math.floor(minutes / 60);
62 const rest = minutes % 60;
63 return rest === 0 ? `${hours}h` : `${hours}h ${rest}m`;
64}
65
66/** When an active claim lapses, in words; null for one that is not active. */
67export function expiresIn(claim: Pick<Claim, "state" | "expiresAt">, now: number): string | null {
68 if (claim.state !== "active") return null;
69 const left = new Date(claim.expiresAt).getTime() - now;
70 return left <= 0 ? "expiring now" : `expires in ${span(left)}`;
71}
72
73/** What became of a claim that is no longer active. */
74export const CLAIM_ENDED: Record<Exclude<ClaimState, "active">, string> = {
75 released: "Released",
76 expired: "Expired",
77 handed_off: "Handed off",
78};
79
80export const SESSION_STATES: Record<SessionState, { label: string; hint: string }> = {
81 active: { label: "Active", hint: "Heard from in the last 15 minutes." },
82 idle: { label: "Idle", hint: "Not heard from for 15 minutes. It may still come back." },
83 ended: { label: "Ended", hint: "Ended, or not heard from for 2 hours." },
84};
85
86// ── Session titles ──────────────────────────────────────────────────────
87
88/** The most of a prompt's intent that titles a session. */
89export const TITLE_LIMIT = 80;
90
91/** A turn the harness starts itself, as a tag: `<command-name>`, `<task-notification>`, one with attributes. */
92const HARNESS_TAG = /^\s*<[a-z][\w-]*(?:\s[^>]*)?>/i;
93
94/**
95 * What a prompt is for, as a session's title: its first line or sentence,
96 * without code blocks or markdown, whitespace collapsed, clipped at
97 * TITLE_LIMIT on a word with "…". Null for a slash command, a turn the
98 * harness starts itself, or nothing to say. The Claude Code plugin
99 * (plugins/claude-code/hooks/g1t.mjs) titles its sessions the same way.
100 */
101export function intentTitle(prompt: string | null | undefined): string | null {
102 let text = String(prompt ?? "").replace(/^\uFEFF/, "");
103 // What the harness pasted in or attached is not what the prompt is for:
104 // pasted text (Claude Code's <pasted_content id="…">…</pasted_content>)
105 // and image placeholders ([Image #1], [Image: source: …]) go first.
106 text = text
107 .replace(/<pasted_content\b[^>]*>[\s\S]*?(?:<\/pasted_content[^>]*>|$)/gi, "\n")
108 .replace(/\[Image(?: #\d+)?(?::[^\]\n]*)?\]/g, " ");
109 if (/^\s*\//.test(text) || HARNESS_TAG.test(text)) return null;
110 text = text
111 .replace(/```[\s\S]*?(```|$)/g, "\n")
112 .replace(/~~~[\s\S]*?(~~~|$)/g, "\n")
113 .replace(/!\[([^\]]*)\]\([^)]*\)/g, "$1")
114 .replace(/\[([^\]]+)\]\([^)]*\)/g, "$1")
115 .replace(/`([^`]*)`/g, "$1");
116 const line = text
117 .split(/\r?\n/)
118 .map((l) => l.replace(/^\s*(?:#{1,6}\s+|>\s*|[-*+]\s+|\d+[.)]\s+)+/, "").replace(/(\*\*|__|~~)(.+?)\1/g, "$2").trim())
119 .find((l) => /[\p{L}\p{N}]/u.test(l));
120 if (!line) return null;
121 let intent = line.replace(/\s+/g, " ").split(/(?<=[.!?])\s+(?=\S)/)[0].trim();
122 if (intent.length > TITLE_LIMIT) {
123 const cut = intent.slice(0, TITLE_LIMIT - 1);
124 const space = cut.lastIndexOf(" ");
125 intent = `${(space > TITLE_LIMIT / 2 ? cut.slice(0, space) : cut).replace(/[\s,;:.\-–—]+$/, "")}…`;
126 } else {
127 intent = intent.replace(/[\s,;:.]+$/, "");
128 }
129 if (intent.length < 2) return null;
130 return intent[0].toLocaleUpperCase() + intent.slice(1);
131}
132
133/**
134 * What a session is called, never nothing: its title, else what its first
135 * prompt was for, else the branch it is on, else "Untitled session".
136 * `firstPrompt` stands in for the session's own when given.
137 */
138export function sessionTitle(
139 session: Pick<WorkSession, "title" | "branch" | "firstPrompt">,
140 firstPrompt: string | null | undefined = session.firstPrompt,
141): string {
142 // A title that is only a harness tag (an early plugin's from a pasted prompt) reads as none.
143 const title = session.title?.trim();
144 if (title && !HARNESS_TAG.test(title)) return title;
145 const intent = intentTitle(firstPrompt);
146 if (intent) return intent;
147 return session.branch ? `Session on ${session.branch}` : "Untitled session";
148}
149
150// ── Live now ────────────────────────────────────────────────────────────
151
152/** One issue being worked on: its claims and the sessions on it. */
153export type LiveIssue = { issue: number; claims: Claim[]; sessions: WorkSession[] };
154
155/** Sessions on no issue yet, together: on one pull request, on one branch of their own, or on neither. */
156export type LiveGroup =
157 | { kind: "pull"; pull: number; sessions: WorkSession[] }
158 | { kind: "branch"; branch: string; sessions: WorkSession[] }
159 | { kind: "none"; sessions: WorkSession[] };
160
161const latestSeen = (sessions: WorkSession[]) => Math.max(0, ...sessions.map((session) => Date.parse(session.lastSeenAt)));
162
163/**
164 * Active claims and sessions grouped by the issue they are on, the issue
165 * with the most recent activity first. Sessions on no issue are grouped
166 * after them (`groups`): by their pull request, else by their branch when
167 * it is not `defaultBranch`, the most recently heard from first; the rest,
168 * on no branch of their own, last together. `loose` is every session on no
169 * issue, as the groups hold them.
170 */
171export function liveByIssue(
172 claims: Claim[],
173 sessions: WorkSession[],
174 defaultBranch?: string | null,
175): { issues: LiveIssue[]; groups: LiveGroup[]; loose: WorkSession[] } {
176 const byIssue = new Map<number, LiveIssue>();
177 const at = (issue: number) => {
178 let group = byIssue.get(issue);
179 if (!group) byIssue.set(issue, (group = { issue, claims: [], sessions: [] }));
180 return group;
181 };
182 for (const claim of claims) at(claim.issue).claims.push(claim);
183 const byPull = new Map<number, LiveGroup & { kind: "pull" }>();
184 const byBranch = new Map<string, LiveGroup & { kind: "branch" }>();
185 const rest: WorkSession[] = [];
186 for (const session of sessions) {
187 if (session.issue != null) at(session.issue).sessions.push(session);
188 else if (session.pull != null) {
189 const group = byPull.get(session.pull) ?? { kind: "pull" as const, pull: session.pull, sessions: [] };
190 byPull.set(session.pull, group);
191 group.sessions.push(session);
192 } else if (session.branch && session.branch !== defaultBranch) {
193 const group = byBranch.get(session.branch) ?? { kind: "branch" as const, branch: session.branch, sessions: [] };
194 byBranch.set(session.branch, group);
195 group.sessions.push(session);
196 } else rest.push(session);
197 }
198 const latest = (group: LiveIssue) => Math.max(latestSeen(group.sessions), ...group.claims.map((claim) => Date.parse(claim.createdAt)));
199 const recent = (a: LiveGroup, b: LiveGroup) => latestSeen(b.sessions) - latestSeen(a.sessions);
200 const groups: LiveGroup[] = [...byPull.values(), ...byBranch.values()].sort(recent);
201 if (rest.length > 0) groups.push({ kind: "none", sessions: rest });
202 for (const group of groups) group.sessions.sort((a, b) => Date.parse(b.lastSeenAt) - Date.parse(a.lastSeenAt));
203 return {
204 issues: [...byIssue.values()].sort((a, b) => latest(b) - latest(a) || a.issue - b.issue),
205 groups,
206 loose: groups.flatMap((group) => group.sessions),
207 };
208}
209
210// ── Decisions ───────────────────────────────────────────────────────────
211
212export const CONFIDENCE: Record<DecisionConfidence, { label: string; hint: string; tone: "neutral" | "info" | "success" }> = {
213 claimed: { label: "Claimed", hint: "Someone said so: an agent or a person recorded it.", tone: "neutral" },
214 tested: { label: "Tested", hint: "A check or the merge queue proved it.", tone: "info" },
215 approved: { label: "Approved", hint: "A person approved it.", tone: "success" },
216};
217
218export const DECISION_KINDS: Record<Decision["kind"], string> = {
219 proposal: "Proposal",
220 claim: "Claim",
221 integration_failure: "Failed together",
222 integration_passed: "Passed together",
223 fix: "Fix",
224 approval: "Approval",
225 merge: "Merge",
226 note: "Note",
227};
228
229/** The check a decision's evidence names. */
230export type EvidenceCheck = { name: string; conclusion: string; url: string | null };
231
232/** What a decision rests on, read from its evidence as far as it says. */
233export type Evidence = {
234 commit: string | null;
235 check: EvidenceCheck | null;
236 /** The pull requests tested together, in queue order. */
237 combination: number[];
238 /** Those ahead it fails with. */
239 suspects: number[];
240 bisected: boolean;
241};
242
243function numbers(value: unknown): number[] {
244 return Array.isArray(value) ? value.filter((n): n is number => typeof n === "number" && Number.isInteger(n)) : [];
245}
246
247export function evidenceOf(decision: Pick<Decision, "evidence">): Evidence {
248 const raw = (decision.evidence ?? {}) as Record<string, unknown>;
249 const check = raw.check && typeof raw.check === "object" ? (raw.check as Record<string, unknown>) : null;
250 return {
251 commit: typeof raw.commit === "string" ? raw.commit : null,
252 check:
253 check && typeof check.name === "string"
254 ? {
255 name: check.name,
256 conclusion: typeof check.conclusion === "string" ? check.conclusion : "failure",
257 url: typeof check.url === "string" && check.url ? check.url : null,
258 }
259 : null,
260 combination: numbers(raw.combination),
261 suspects: numbers(raw.suspects),
262 bisected: raw.bisected === true,
263 };
264}
265
266/** Where a check's address leads on the site: its path when it is g1t's own, else the address as it is. */
267export function checkHref(url: string | null): string | null {
268 if (!url) return null;
269 try {
270 const parsed = new URL(url);
271 if (parsed.hostname === "g1t.sh" || parsed.hostname.endsWith(".g1t.sh")) return parsed.pathname + parsed.search;
272 return url;
273 } catch {
274 return url.startsWith("/") ? url : null;
275 }
276}
277
278/**
279 * The integration failure a pull request still answers for: its latest
280 * `integration_failure`, unless it passed in the queue or merged since.
281 * `decisions` in any order.
282 */
283export function standingFailure(decisions: Decision[], pull?: number): Decision | null {
284 const mine = decisions
285 .filter((decision) => pull == null || decision.pull === pull)
286 .filter((decision) => ["integration_failure", "integration_passed", "merge"].includes(decision.kind))
287 .sort((a, b) => Date.parse(b.createdAt) - Date.parse(a.createdAt));
288 return mine[0]?.kind === "integration_failure" ? mine[0] : null;
289}
290
291/** The decisions after a failure that answer it: a fix recorded since, and a combination that then passed. */
292export function resolutionOf(decisions: Decision[], failure: Decision): { fix: Decision | null; passed: Decision | null } {
293 const after = decisions
294 .filter((decision) => Date.parse(decision.createdAt) > Date.parse(failure.createdAt))
295 .sort((a, b) => Date.parse(a.createdAt) - Date.parse(b.createdAt));
296 return {
297 fix: after.find((decision) => decision.kind === "fix" && (decision.pull === failure.pull || decision.issue === failure.issue)) ?? null,
298 passed: after.find((decision) => decision.kind === "integration_passed" && decision.pull === failure.pull) ?? null,
299 };
300}
301
302// ── The feed ────────────────────────────────────────────────────────────
303
304/** One line of the coordination feed: what happened, in words, and what it links to. */
305export type FeedLine = {
306 id: string;
307 time: string;
308 type: CoordinationType;
309 /** Who did it, by username; null for g1t itself. */
310 who: string | null;
311 /** The harness it came from, when it says. */
312 harness: Harness | null;
313 /** The sentence, after the name. Numbers in it are written `#N`. */
314 text: string;
315 /** The issue or pull request it is about. */
316 number: number | null;
317 /** The harness session it is about, by id, for a link to its page. */
318 session?: string;
319 tone: "neutral" | "accent" | "success" | "warn" | "danger" | "info";
320};
321
322const list = (all: number[]) => all.map((n) => `#${n}`).join(", ");
323const plural = (n: number, one: string, many: string) => (n === 1 ? one : many);
324
325/** A session's pending updates as lines of the feed, oldest first. */
326export function pendingLines(updates: { id: string; kind: string; data: unknown; at: string }[]): FeedLine[] {
327 return updates.flatMap((update) => {
328 if (!(COORDINATION_TYPES as readonly string[]).includes(update.kind)) return [];
329 const event = { id: update.id, type: update.kind, time: update.at, source: "work", repoId: null, actor: null, data: update.data } as G1tEvent;
330 return feedLine(event) ?? [];
331 });
332}
333
334/** A coordination event as a line of the feed, or null for one it does not show. */
335export function feedLine(event: G1tEvent): FeedLine | null {
336 const base = { id: event.id, time: event.time, harness: null as Harness | null, number: null as number | null };
337 const data = event.data as Record<string, unknown> & { number?: number };
338 const number = typeof data.number === "number" ? data.number : null;
339 switch (event.type) {
340 case "work.claimed": {
341 const { claim, others = [], tookOver } = event.data;
342 const also = others.length > 0 ? ` (${others.map((other) => other.actor.username).join(", ")} ${plural(others.length, "is", "are")} on it too)` : "";
343 return {
344 ...base,
345 type: event.type,
346 who: claim.actor.username,
347 harness: claim.harness,
348 text: `${tookOver ? "took over" : "claimed"} #${claim.issue}${also}`,
349 number: claim.issue,
350 tone: others.length > 0 ? "warn" : "accent",
351 };
352 }
353 case "work.released": {
354 const { claim, reason } = event.data;
355 return {
356 ...base,
357 type: event.type,
358 who: claim.actor.username,
359 harness: claim.harness,
360 text: reason === "issue_closed" ? `no longer holds #${claim.issue}: the issue closed` : `released #${claim.issue}${reason ? `: ${reason}` : ""}`,
361 number: claim.issue,
362 tone: "neutral",
363 };
364 }
365 case "work.claim_expired": {
366 const { claim } = event.data;
367 return { ...base, type: event.type, who: claim.actor.username, harness: claim.harness, text: `let the claim on #${claim.issue} expire`, number: claim.issue, tone: "neutral" };
368 }
369 case "work.handoff_requested": {
370 const { claim, to, note } = event.data;
371 return {
372 ...base,
373 type: event.type,
374 who: claim.actor.username,
375 harness: claim.harness,
376 text: `handed #${claim.issue} off to ${to ?? "anyone"}${note ? `: ${note}` : ""}`,
377 number: claim.issue,
378 tone: "info",
379 };
380 }
381 case "session.started":
382 case "session.ended": {
383 const { session } = event.data;
384 const on = session.issue != null ? ` on #${session.issue}` : session.pull != null ? ` on #${session.pull}` : "";
385 const why = event.type === "session.ended" && session.endReason === "timed_out" ? " (timed out)" : "";
386 return {
387 ...base,
388 type: event.type,
389 who: session.actor.username,
390 harness: session.harness,
391 text: `${event.type === "session.started" ? "started a session" : "ended a session"}${on}${why}`,
392 number: session.issue ?? session.pull,
393 tone: event.type === "session.started" ? "accent" : "neutral",
394 };
395 }
396 case "dependency.changed": {
397 const { issue, added, removed, cleared, remaining, mergedPull } = event.data;
398 const parts = [
399 added.length > 0 && `now waits on ${list(added)}`,
400 removed.length > 0 && `no longer waits on ${list(removed)}`,
401 cleared.length > 0 && `${list(cleared)} ${mergedPull ? `landed (#${mergedPull} merged)` : "closed"}`,
402 ].filter(Boolean);
403 // What it still waits on, unless that is only what was just added.
404 const said = remaining.every((n) => added.includes(n)) && parts.length > 0;
405 const left = remaining.length === 0 ? "unblocked" : said ? null : `still waits on ${list(remaining)}`;
406 return {
407 ...base,
408 type: event.type,
409 who: null,
410 text: `#${issue} ${[...parts, left].filter(Boolean).join("; ")}`,
411 number: issue,
412 tone: remaining.length === 0 ? "success" : "info",
413 };
414 }
415 case "overlap.detected": {
416 if ("sessionId" in event.data) {
417 const { sessionId, otherActor, files, issue } = event.data;
418 return {
419 ...base,
420 type: event.type,
421 who: otherActor,
422 text: `touched the same ${plural(files.length, "file", "files")} in a session as another session: ${files.slice(0, 3).join(", ")}${files.length > 3 ? ` and ${files.length - 3} more` : ""}`,
423 number: issue ?? number,
424 session: sessionId,
425 tone: "warn",
426 };
427 }
428 const { pull, otherPull, files } = event.data;
429 return {
430 ...base,
431 type: event.type,
432 who: null,
433 text: `#${pull} and #${otherPull} change the same ${plural(files.length, "file", "files")}: ${files.slice(0, 3).join(", ")}${files.length > 3 ? ` and ${files.length - 3} more` : ""}`,
434 number: pull,
435 tone: "warn",
436 };
437 }
438 case "integration.failed": {
439 const { pull, combination, check, suspects } = event.data;
440 const together = combination.length > 1 ? ` combined as ${list(combination)}` : " on its own";
441 const with_ = suspects.length > 0 ? `; fails with ${list(suspects)}` : "";
442 return { ...base, type: event.type, who: null, text: `#${pull} failed in the merge queue${together}: ${check.name}${with_}`, number: pull, tone: "danger" };
443 }
444 case "integration.passed": {
445 const { pull, combination } = event.data;
446 return {
447 ...base,
448 type: event.type,
449 who: null,
450 text: combination.length > 1 ? `#${pull} passed in the merge queue combined as ${list(combination)}` : `#${pull} passed in the merge queue`,
451 number: pull,
452 tone: "success",
453 };
454 }
455 case "decision.recorded": {
456 const { decision } = event.data;
457 const kind = DECISION_KINDS[decision.kind as Decision["kind"]]?.toLowerCase() ?? decision.kind;
458 return {
459 ...base,
460 type: event.type,
461 who: decision.actor,
462 text: `recorded ${/^[aeiou]/.test(kind) ? "an" : "a"} ${kind}, ${decision.confidence}: ${decision.summary}`,
463 number: decision.pull ?? decision.issue ?? number,
464 tone: decision.kind === "integration_failure" ? "danger" : decision.confidence === "approved" ? "success" : "neutral",
465 };
466 }
467 // Steps of a session as it goes: for the pages showing it, not the feed.
468 case "session.progressed":
469 default:
470 return null;
471 }
472}
473
474// ── Session trees ───────────────────────────────────────────────────────
475
476/** A session with its subagents under it, and theirs under them. */
477export type SessionNode = { session: WorkSession; children: SessionNode[] };
478
479/**
480 * Sessions as trees, by `parentId`: the roots in the order given, each
481 * with its subagents in the order given. One whose parent is not in the
482 * list is a root of its own.
483 */
484export function sessionTree(sessions: WorkSession[]): SessionNode[] {
485 const nodes = new Map<string, SessionNode>();
486 for (const session of sessions) if (!nodes.has(session.id)) nodes.set(session.id, { session, children: [] });
487 const roots: SessionNode[] = [];
488 for (const node of nodes.values()) {
489 const parent = node.session.parentId ? nodes.get(node.session.parentId) : undefined;
490 // A parent that is the session itself or under it (a cycle) does not count.
491 if (parent && !contains(node, parent)) parent.children.push(node);
492 else roots.push(node);
493 }
494 return roots;
495}
496
497/** The sessions of several lists, each once (as the first list to have it says), in the order first given. */
498export function mergeSessions(...lists: (WorkSession[] | null | undefined)[]): WorkSession[] {
499 const seen = new Map<string, WorkSession>();
500 for (const list of lists) for (const session of list ?? []) if (!seen.has(session.id)) seen.set(session.id, session);
501 return [...seen.values()];
502}
503
504function contains(node: SessionNode, target: SessionNode): boolean {
505 return node === target || node.children.some((child) => contains(child, target));
506}
507
508/** How many sessions are under a tree's root, at any depth. */
509export function treeSize(node: SessionNode): number {
510 return node.children.reduce((total, child) => total + 1 + treeSize(child), 0);
511}
512
513/** How a session was tied to an issue or pull request, in a few words. */
514export const VIA_LABELS: Record<LinkVia, string> = {
515 attached: "attached",
516 claim: "claimed",
517 branch: "its branch",
518 commit: "its commit",
519 trailer: "commit trailer",
520 opened: "opened it",
521 ref: "named it",
522};
523
524export function viaLabel(via: LinkVia): string {
525 return VIA_LABELS[via] ?? via;
526}
527
528/** What each kind of thing a session touched is called. */
529export const TOUCH_KINDS: Record<TouchKind, string> = {
530 file: "Files",
531 commit: "Commits",
532 branch: "Branches",
533 pull: "Pull requests",
534 issue: "Issues",
535};
536
537/** What was touched, grouped by kind in TOUCH_KINDS' order, each value once, in the order given. */
538export function touchedByKind(touched: { kind: TouchKind; value: string }[]): { kind: TouchKind; values: string[] }[] {
539 return (Object.keys(TOUCH_KINDS) as TouchKind[])
540 .map((kind) => ({ kind, values: [...new Set(touched.filter((one) => one.kind === kind).map((one) => one.value))] }))
541 .filter((group) => group.values.length > 0);
542}
543
544/** "12s", "4m", "1h 20m": how long a session ran, or has run until `now`. */
545export function duration(session: Pick<WorkSession, "startedAt" | "endedAt" | "lastSeenAt" | "state">, now: number): string {
546 const end = session.endedAt ? Date.parse(session.endedAt) : session.state === "ended" ? Date.parse(session.lastSeenAt) : now;
547 const ms = Math.max(0, end - Date.parse(session.startedAt));
548 return ms < MINUTE ? `${Math.floor(ms / 1000)}s` : span(ms);
549}
550
551/** Splits text at `#N`, for linking each number. */
552export function numberedParts(text: string): (string | number)[] {
553 const parts: (string | number)[] = [];
554 let last = 0;
555 for (const match of text.matchAll(/#(\d+)\b/g)) {
556 if (match.index > last) parts.push(text.slice(last, match.index));
557 parts.push(Number(match[1]));
558 last = match.index + match[0].length;
559 }
560 if (last < text.length) parts.push(text.slice(last));
561 return parts;
562}
563
564/** `blocked_by` as typed: numbers, with or without `#`, by commas or spaces; null when any is not one. */
565export function parseBlockedBy(text: string): number[] | null {
566 const words = text.split(/[\s,]+/).map((word) => word.trim().replace(/^#/, "")).filter(Boolean);
567 if (words.some((word) => !/^\d+$/.test(word) || Number(word) <= 0)) return null;
568 return [...new Set(words.map(Number))];
569}