diff --git a/bin/_claude-triage b/bin/_claude-triage index 938f7f2..17fe6cf 100755 --- a/bin/_claude-triage +++ b/bin/_claude-triage @@ -89,6 +89,22 @@ def get_text(entry: dict) -> str: return "" +def read_cwd_only(jsonl: Path) -> str: + """Cheap version of compress_session that stops at the first cwd field.""" + try: + with jsonl.open(encoding="utf-8", errors="replace") as f: + for line in f: + try: + entry = json.loads(line) + except json.JSONDecodeError: + continue + if entry.get("cwd"): + return entry["cwd"] + except OSError: + return "" + return "" + + def compress_session(jsonl: Path) -> tuple[str, str, str]: """Return (cwd, first_user_text, transcript_excerpt).""" first_user = "" @@ -208,12 +224,20 @@ async def main_async(args: argparse.Namespace) -> None: cache_key = f"{jsonl.stem}:{mtime}" hit = None if args.refresh else cache.get(template_id, cache_key) if hit is not None: - # Carry through identifying metadata in case the cached payload - # was written by an older script revision that didn't enrich. + # The SDK cache stores the raw LLM response (priority/status/ + # summary/next_action); enrichment (uuid/cwd/mtime) is added at + # read time by the SDK. Since we bypass run_batched for cached + # items, re-enrich here. cwd needs a tiny disk read (first cwd + # line of the jsonl) but no LLM call. + cwd = hit.get("cwd") or read_cwd_only(jsonl) + if not cwd: + # Couldn't determine cwd → skip; rclaude can't resume without it. + continue cached_results.append({ **hit, - "uuid": hit.get("uuid", jsonl.stem), - "mtime": hit.get("mtime", mtime), + "uuid": hit.get("uuid") or jsonl.stem, + "mtime": hit.get("mtime") or mtime, + "cwd": cwd, }) continue uncached.append((mtime, jsonl, cache_key))