Skip to main content

Module envelope

Module envelope 

Source
Expand description

Envelope parsing for the bracket-wrapped prose forge_workspace injects into user-turn text, plus the Slack mrkdwn converter.

Seven header shapes: the three peer kinds the workspace produces (Message, DeliveryFailure, WorkerSpawnFailed), the Gotify, Cron and Slack external sources, and forge’s own Voice note. Nothing here renders or holds state.

Three of the parser’s arms are replay-only. The Question and Reply headers and the Ask ... failed to deliver header are what a transcript recorded before the peer surface collapsed to one verb holds, and resuming replays that history through this same parser - so those rows keep drawing as peer blocks rather than as raw bracket text. The two message headers resolve to the one kind that replaced them; the recorded failure keeps its own, which is still the failure kind today.

Enums§

PeerInboundKind
One inbound peer block parsed from the user-turn text.

Functions§

bundle_member_count 🔒
The member count a delivered bundle’s header carries, and None for a single message - which is what tells the two apart, since one message’s text may wrap over as many lines as a bundle’s members do.
decode_entities 🔒
Slack escapes &, < and > in message text. The angle-bracket entities decode first so a doubly-escaped &amp;lt; stays the literal it was.
detect_inbound
Detect a peer wrapper at the start of a user-message text. Returns None for any text that isn’t a bracket-prefixed peer wrapper (the chat renderer falls through to the default text rendering in that case).
extract_from_agent_after 🔒
Given a slice starting at 'X' (org 'Y') ..., extract X and Y. Returns None when the format doesn’t match.
extract_from_agent_after_with_trailer 🔒
Same as extract_from_agent_after but also returns the trailer - the substring after '). Used by the delivery-failure parser which needs name, org, AND the trailing reason text.
first_closer 🔒
The first index able to close a span opened at open: the same marker, with non-space before it, no word character after it, and no ability to open a span of its own - otherwise the two * of a pair of globs would close a span between them.
inbound_envelope_id
The envelope’s own message id out of a peer wrapper header ([Message id=m-1a2b3c from agent ...]). Unique per delivered envelope, so it keys an inbound-led messaging group independently of where the message sits in the session - unlike a positional key, it survives history pruning and index shifts.
is_slack_id
True for a raw Slack id (C0C0T5E6RM1, U9ABCD) rather than a name: an uppercase first character followed by uppercase letters and digits only. Both message.user and a DM’s conversation label reach the prose as one until the producer resolves a handle. The shape is a heuristic, not a guarantee: an all-caps channel name matches it and loses its #.
opens_a_span 🔒
A marker opens a span only at a word boundary, with text after it and no doubled marker on either side - the _ inside an identifier and the ** of a glob are both literals rather than openers.
rest_after_id 🔒
After the id= slice has been peeled off, look for the marker that comes after the id (e.g. to agent or from agent). Returns the slice after the marker.
strip_emphasis 🔒
Drop the markers around an emphasised span. A marker pair is only emphasis when each end sits at a word boundary with a single marker, so the _ in an identifier, an unpaired _ and the ** of a glob all stay literal.
take_until 🔒
Split s at the first occurrence of marker. Returns (before, after_marker) - the marker itself is consumed. None when the marker isn’t found.
tidy_mrkdwn
Strip Slack’s mrkdwn down to plain text: emphasis markers drop, a labelled link becomes label: url, and the &/</> entities decode.