This commit is contained in:
2026-04-03 00:25:14 -03:00
parent d61e2a5492
commit cae9312db1
7 changed files with 341 additions and 91 deletions

View File

@@ -51,21 +51,37 @@ def _resolve_provider() -> AgentProvider:
return ClaudeSDKProvider()
def _expand_ref_nums(spec: str) -> list[int]:
"""Expand a ref spec like '2-6' or '2,4,6' or '2-4,6,8-10' into sorted ints."""
nums = set()
for part in spec.split(","):
part = part.strip()
if "-" in part:
a, b = part.split("-", 1)
try:
nums.update(range(int(a), int(b) + 1))
except ValueError:
pass
elif part:
try:
nums.add(int(part))
except ValueError:
pass
return sorted(nums)
def _parse_mentions(message: str, frames: list[FrameRef]) -> list[FrameRef]:
"""Extract @-references from message. Accepts:
@F0001 @f1 @1 @001 — all match frame F0001
"""
"""Extract @F references. Accepts @F1, @F2-6, @F2,4,6, @F2-4,6,8-10."""
mentioned = []
seen = set()
for match in re.finditer(r"@([Ff]?\d+)", message):
raw = match.group(1).lstrip("Ff")
num = int(raw)
fid = f"F{num:04d}"
if fid not in seen:
frame = next((f for f in frames if f.id == fid), None)
if frame:
mentioned.append(frame)
seen.add(fid)
for match in re.finditer(r"@[Ff]([\d,\-]+)", message):
for num in _expand_ref_nums(match.group(1)):
fid = f"F{num:04d}"
if fid not in seen:
frame = next((f for f in frames if f.id == fid), None)
if frame:
mentioned.append(frame)
seen.add(fid)
return mentioned
@@ -111,17 +127,17 @@ def _load_transcript(transcript_dir: Path) -> list[TranscriptRef]:
def _parse_transcript_mentions(message: str, segments: list[TranscriptRef]) -> list[TranscriptRef]:
"""Extract @T references from message. Accepts @T0001, @t1, @T1."""
"""Extract @T references. Accepts @T1, @T2-6, @T2,4,6, @T1-3,5,7-10."""
mentioned = []
seen = set()
for match in re.finditer(r"@[Tt](\d+)", message):
num = int(match.group(1))
tid = f"T{num:04d}"
if tid not in seen:
seg = next((s for s in segments if s.id == tid), None)
if seg:
mentioned.append(seg)
seen.add(tid)
for match in re.finditer(r"@[Tt]([\d,\-]+)", message):
for num in _expand_ref_nums(match.group(1)):
tid = f"T{num:04d}"
if tid not in seen:
seg = next((s for s in segments if s.id == tid), None)
if seg:
mentioned.append(seg)
seen.add(tid)
return mentioned