Files
gabrielvidalandClaude Opus 5.5 fd871bd128 refactor(parse): a neutral event layer between transcript records and the fold
Readers (parse/readers/) turn each record into the v1 events of
parse/events.py; ParserState.feed hands the record to its reader and
folds the events (apply). Claude Code's record shapes and text
conventions (claude.py, claudetext.py), the hub's envelopes
(hubtext.py) and the pi / opencode / agy converters' quirks (legacy.py)
left the fold; the ResourceMiner, Code Mode, task notifications, Bash
hooks and commits are fed from events. No _raw pass-through.

Verified: parse-ab --base e85a2ff2 500 files x 2 modes 0 differing;
--chunked 0 mismatches; pricing-dump identical; test_parse_fixtures OK;
parser test modules in the service image same as e85a2ff2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 00:56:13 +01:00

61 lines
2.6 KiB
Python

"""Text conventions. What the fold itself still reads: the DONE / COMPLETED
markers of a last message, the skill-prompt cap and a skill's repo-relative
path.
Everything else that used to live here now belongs to a reader —
``readers/hubtext.py`` (the hub's inbox / cancel / relay / author envelopes)
and ``readers/claudetext.py`` (Claude Code's interrupt marker, held feedback,
image note, "No response requested.", skill prompts, slash commands,
compaction summaries, absorbed follow-ups). They are re-exported here so the
names ``conversations.parse`` always had stay importable."""
import re
from .readers.hubtext import ( # noqa: F401
_AUTHOR_RE, _CANCEL_RE, _INBOX_RE, _RELAY_RE, _cancelled_text,
_relayed_message, _split_author, _unwrap_inbox,
)
from .readers.claudetext import ( # noqa: F401
_COMPACT_LEAD_RE, _COMPACT_REMINDER_RE, _HELD_MIN_RE, _HELD_RE,
_HELD_SECS_RE, _IMAGE_NOTE_RE, _INTERRUPT_RE, _NO_RESPONSE_RE,
_SKILL_BODY_RE, _SKILL_NOTE_RE, _SLASH_ARGS_RE, _SLASH_CMD_RE,
_absorbed_followup, _compact_summary_text, _held_label, _skill_body,
_slash_command,
)
# The legacy sign-off: a last message ending with the literal marker ``DONE``
# (the old "When work is done" rule — the turn's end, ``turn_ended``, now says
# it on its own). Matched as an upper-case word so ordinary prose ("done",
# "well done") doesn't trip it. Combined with a recorded notification, it
# still flips a stale "running" marker to finished in the viewer.
_DONE_RE = re.compile(r"\bDONE\b")
# The `complete` skill's end-of-task pass (summary published, memories, docs,
# artefacts, cleanup) continues the same session, so its own reply becomes the
# transcript's last message; it signs off with the distinct marker ``COMPLETED``
# rather than ``DONE``, which lets the viewer tell "the task finished" apart
# from "the task finished AND was tidied up after" (`meta.completedAt`).
_COMPLETED_RE = re.compile(r"\bCOMPLETED\b")
# The catalog shows a skill's latest prompt whole; this only bounds the DB row.
MAX_SKILL_PROMPT = 100_000
def _rel_skill_path(base_dir: str, cwd: str | None) -> str | None:
"""Repo-relative path to the skill's SKILL.md (for a link into the editor),
or None when the skill lives outside the repo (built-in/plugin skills)."""
if not base_dir:
return None
marker = ".claude/skills/"
idx = base_dir.find(marker)
if idx != -1:
return base_dir[idx:].rstrip("/") + "/SKILL.md"
if cwd:
root = cwd.rstrip("/") + "/"
if base_dir.startswith(root):
return base_dir[len(root):].rstrip("/") + "/SKILL.md"
return None