@estiva-app/protocol 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,54 @@ Every entry answers the wire question explicitly, including when the answer is
4
4
  nothing (ADR 0002 §4b). A change to the bytes an app publishes is a MAJOR — in
5
5
  `0.x`, a MINOR — even when no TypeScript signature moved.
6
6
 
7
+ ## 0.6.0 — 2026-09-02
8
+
9
+ **Wire behaviour: unchanged.** No builder, tag layout, id computation or
10
+ signature input moved. This release adds a parser, and a parser reads bytes
11
+ somebody else already published.
12
+
13
+ **What it does change is what readers draw**, which is not the wire and is not
14
+ nothing: an app that upgrades starts rendering backtick spans in messages that
15
+ have been on the relay for weeks. Measured 2026-09-02, that is **200 of 548
16
+ published message bodies** — the most common construct in the corpus, more
17
+ common than bold, and until now rendered by nobody. Upgrading is visible to
18
+ users on history, not only on new messages.
19
+
20
+ - **New: `content.ts` — the message marker dialect, SPEC §13.2.** `parseInlineMarks`,
21
+ `wrapInlineMarks`, `parseBodySegments` and `stripInlineFormatting`, moved out
22
+ of Peek's `src/lib/textParsing.ts` rather than written fresh, so the behaviour
23
+ that was already shipping is preserved by construction. Peek's own tests for
24
+ them are ported verbatim into `test/content.test.ts` as the proof.
25
+
26
+ Only the **mark** layer moved. Peek's mentions and bracket references resolve
27
+ against its own directory and fixtures, and they stay there — a mention is
28
+ RIC-2's, and dragging its regexes along would have imported one app's mock
29
+ data into the shared package.
30
+
31
+ - **New in the dialect: `code` and fenced code** (SPEC §13.1, §13.2). A code
32
+ span carries `code` and never combines with another mark, and its content is
33
+ never parsed for further marks — so `` `**x**` `` is four literal characters
34
+ and a name.
35
+
36
+ - **SPEC §13.2's rule 2 does not fence a backtick**, and the corpus is why.
37
+ Rule 2 keeps `2*3*4` literal, which an asymmetric prose marker needs and a
38
+ backtick does not — applying it anyway left `` `main`s `` unparsed, a code
39
+ span followed by a plural or possessive. Eight such spans in six published
40
+ messages. SPEC was amended to say so (estiva-docs#56) rather than the parser
41
+ quietly disagreeing with it.
42
+
43
+ - **Fixed while extracting: `stripInlineFormatting` was not idempotent.** It
44
+ removed the heading prefix before the quote prefix, so `> # Heading` — the
45
+ shape every project brief in this workspace is written in — came back as
46
+ `# Heading` and previews showed a stray `#`. Prefixes are now stripped until
47
+ the line stops changing. **This bug was invisible to the tests it shipped
48
+ with** and was found by running the function over 152 real published bodies.
49
+
50
+ - **New: `test/corpus-bodies.json`** — 152 real message bodies from production.
51
+ A parser checked only against fixtures written beside it is checked against
52
+ its own assumptions; both defects above came from this file and neither came
53
+ from the unit tests.
54
+
7
55
  ## 0.5.0 — 2026-09-01
8
56
 
9
57
  **Wire behaviour: unchanged.** No builder, tag layout, id computation or
@@ -0,0 +1,83 @@
1
+ /**
2
+ * The message marker dialect — SPEC §13.1 and §13.2.
3
+ *
4
+ * ## Why content is in a package that "interprets nothing"
5
+ *
6
+ * `index.ts` draws the line at *interpretation*: the fold stays in the apps,
7
+ * because how an app turns events into current truth is where apps are supposed
8
+ * to differ. A body's formatting is on the other side of that line for the same
9
+ * reason the event id is — **it is wire-visible, and two apps disagreeing about
10
+ * it produces a divergence each copy is self-consistent about and nobody
11
+ * notices.** That is not a hypothetical: measured on production 2026-09-02,
12
+ * 261 of 548 published messages carry structure, Peek parses it, Ship renders
13
+ * it literally, and neither is wrong about its own behaviour.
14
+ *
15
+ * Being honest about the usual test: the relay would *not* notice if two apps
16
+ * disagreed here, so §10's question is a poor fit. What makes this belong is the
17
+ * failure shape rather than the arbiter — see RFC 0.4 §14.3, which put the
18
+ * inline layer here, and SPEC §13.1, which made it normative.
19
+ *
20
+ * **What is deliberately not here.** Mentions resolved against a directory,
21
+ * bracket references to an app's own objects, and anything that needs to know
22
+ * what a topic or a file is. Peek's `textParsing.ts` mixes those with the marks;
23
+ * only the marks moved. A `nostr:` reference is a mark and its *token* is in
24
+ * scope, but what a mention does is RIC-2's.
25
+ */
26
+ /** Marks a run of text can carry. `code` is exclusive — see {@link parseInlineMarks}. */
27
+ export type InlineMark = 'bold' | 'italic' | 'underline' | 'code';
28
+ /** A run of text and the marks on it. */
29
+ export interface InlineMarkSpan {
30
+ text: string;
31
+ bold?: boolean;
32
+ italic?: boolean;
33
+ underline?: boolean;
34
+ code?: boolean;
35
+ }
36
+ /** A block-level run, parsed from line prefixes. */
37
+ export type BodySegment = {
38
+ type: 'text';
39
+ lines: string[];
40
+ } | {
41
+ type: 'bullet';
42
+ items: string[];
43
+ } | {
44
+ type: 'numbered';
45
+ items: string[];
46
+ } | {
47
+ type: 'heading';
48
+ level: 1 | 2;
49
+ text: string;
50
+ } | {
51
+ type: 'quote';
52
+ lines: string[];
53
+ } | {
54
+ type: 'code';
55
+ language?: string;
56
+ lines: string[];
57
+ };
58
+ /**
59
+ * Parse one plain-text run into styled spans.
60
+ *
61
+ * Split mentions and app-specific references out first — this function knows
62
+ * about marks and nothing else.
63
+ */
64
+ export declare function parseInlineMarks(text: string): InlineMarkSpan[];
65
+ /**
66
+ * Wrap a run of text in the markers for the marks it carries.
67
+ *
68
+ * Edge whitespace is hoisted outside the markers, because `**word **` would not
69
+ * parse back under rule 1 — so bolding "word " round-trips as `**word** `.
70
+ *
71
+ * `code` wins alone, for the same reason the parser never emits it combined.
72
+ */
73
+ export declare function wrapInlineMarks(text: string, markNames: ReadonlySet<string>): string;
74
+ /**
75
+ * Split a body into block segments.
76
+ *
77
+ * Blank lines split runs of plain text into separate `text` segments. `# ` and
78
+ * `## ` become headings; three or more `#`s, and a `#123` reference with no
79
+ * space, stay plain text.
80
+ */
81
+ export declare function parseBodySegments(body: string): BodySegment[];
82
+ export declare function stripInlineFormatting(text: string): string;
83
+ //# sourceMappingURL=content.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,yFAAyF;AACzF,MAAM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AG,MAAM,CAM1D"}
@@ -0,0 +1,281 @@
1
+ /**
2
+ * The message marker dialect — SPEC §13.1 and §13.2.
3
+ *
4
+ * ## Why content is in a package that "interprets nothing"
5
+ *
6
+ * `index.ts` draws the line at *interpretation*: the fold stays in the apps,
7
+ * because how an app turns events into current truth is where apps are supposed
8
+ * to differ. A body's formatting is on the other side of that line for the same
9
+ * reason the event id is — **it is wire-visible, and two apps disagreeing about
10
+ * it produces a divergence each copy is self-consistent about and nobody
11
+ * notices.** That is not a hypothetical: measured on production 2026-09-02,
12
+ * 261 of 548 published messages carry structure, Peek parses it, Ship renders
13
+ * it literally, and neither is wrong about its own behaviour.
14
+ *
15
+ * Being honest about the usual test: the relay would *not* notice if two apps
16
+ * disagreed here, so §10's question is a poor fit. What makes this belong is the
17
+ * failure shape rather than the arbiter — see RFC 0.4 §14.3, which put the
18
+ * inline layer here, and SPEC §13.1, which made it normative.
19
+ *
20
+ * **What is deliberately not here.** Mentions resolved against a directory,
21
+ * bracket references to an app's own objects, and anything that needs to know
22
+ * what a topic or a file is. Peek's `textParsing.ts` mixes those with the marks;
23
+ * only the marks moved. A `nostr:` reference is a mark and its *token* is in
24
+ * scope, but what a mention does is RIC-2's.
25
+ */
26
+ /**
27
+ * Longest token first so `***` is not consumed as `**` plus a dangling `*`.
28
+ *
29
+ * Order only decides ties at one index — the scanner walks left to right, so the
30
+ * leftmost opening delimiter wins regardless of what is listed first.
31
+ */
32
+ const MARK_TOKENS = [
33
+ { token: '***', keys: ['bold', 'italic'] },
34
+ { token: '**', keys: ['bold'] },
35
+ { token: '__', keys: ['underline'] },
36
+ { token: '*', keys: ['italic'] },
37
+ { token: '`', keys: ['code'], literal: true },
38
+ ];
39
+ const isWordChar = (ch) => ch !== undefined && /[A-Za-z0-9]/.test(ch);
40
+ /**
41
+ * SPEC §13.2 rule 2 — a marker adjacent to an alphanumeric is not a marker, so
42
+ * `2*3*4` stays literal math.
43
+ *
44
+ * **It does not apply to a backtick.** Rule 2 resolves an ambiguity that only
45
+ * asymmetric prose markers have: `*` is multiplication and a glob, `_` is in
46
+ * identifiers. A backtick is not used as ordinary punctuation, so there is no
47
+ * ambiguity to resolve — and applying the fence anyway leaves `` `main`s ``
48
+ * literal, which is a code span followed by a plural or possessive. Measured
49
+ * against production 2026-09-02: 8 such spans in 6 published messages, and zero
50
+ * cases of the opening side needing the fence. CommonMark agrees.
51
+ */
52
+ function findMarkClose(text, token, from, fenced) {
53
+ let idx = text.indexOf(token, from);
54
+ while (idx !== -1) {
55
+ if (!fenced || !isWordChar(text[idx + token.length]))
56
+ return idx;
57
+ idx = text.indexOf(token, idx + 1);
58
+ }
59
+ return -1;
60
+ }
61
+ function toMarkSpan(text, active) {
62
+ const span = { text };
63
+ for (const key of active)
64
+ span[key] = true;
65
+ return span;
66
+ }
67
+ function scanMarks(text, active) {
68
+ for (let i = 0; i < text.length; i++) {
69
+ for (const { token, keys, literal } of MARK_TOKENS) {
70
+ if (keys.some((k) => active.includes(k)))
71
+ continue;
72
+ if (!text.startsWith(token, i))
73
+ continue;
74
+ const fenced = !literal;
75
+ if (fenced && isWordChar(text[i - 1]))
76
+ continue;
77
+ const close = findMarkClose(text, token, i + token.length, fenced);
78
+ if (close === -1)
79
+ continue;
80
+ const inner = text.slice(i + token.length, close);
81
+ // SPEC §13.2 rule 1: whitespace at the inner edges means it is not a pair.
82
+ if (!inner || /^\s/.test(inner) || /\s$/.test(inner))
83
+ continue;
84
+ const spans = [];
85
+ const before = text.slice(0, i);
86
+ if (before)
87
+ spans.push(toMarkSpan(before, active));
88
+ if (literal) {
89
+ /*
90
+ SPEC §13.1: code MUST NOT combine with any other mark, and its content
91
+ MUST NOT be parsed for further marks. So the span carries `code` alone
92
+ even inside an enclosing bold — dropping the outer mark rather than
93
+ emitting a combination the spec forbids.
94
+ */
95
+ spans.push({ text: inner, code: true });
96
+ }
97
+ else {
98
+ spans.push(...scanMarks(inner, [...active, ...keys]));
99
+ }
100
+ spans.push(...scanMarks(text.slice(close + token.length), active));
101
+ return spans;
102
+ }
103
+ }
104
+ return text ? [toMarkSpan(text, active)] : [];
105
+ }
106
+ /**
107
+ * Parse one plain-text run into styled spans.
108
+ *
109
+ * Split mentions and app-specific references out first — this function knows
110
+ * about marks and nothing else.
111
+ */
112
+ export function parseInlineMarks(text) {
113
+ return scanMarks(text, []);
114
+ }
115
+ /**
116
+ * Wrap a run of text in the markers for the marks it carries.
117
+ *
118
+ * Edge whitespace is hoisted outside the markers, because `**word **` would not
119
+ * parse back under rule 1 — so bolding "word " round-trips as `**word** `.
120
+ *
121
+ * `code` wins alone, for the same reason the parser never emits it combined.
122
+ */
123
+ export function wrapInlineMarks(text, markNames) {
124
+ if (!text)
125
+ return text;
126
+ const bold = markNames.has('bold');
127
+ const italic = markNames.has('italic');
128
+ const underline = markNames.has('underline');
129
+ const code = markNames.has('code');
130
+ if (!bold && !italic && !underline && !code)
131
+ return text;
132
+ const m = text.match(/^(\s*)([\s\S]*?)(\s*)$/);
133
+ const [, lead, core, trail] = m;
134
+ if (!core)
135
+ return text;
136
+ if (code)
137
+ return `${lead}\`${core}\`${trail}`;
138
+ let out = core;
139
+ if (bold && italic)
140
+ out = `***${out}***`;
141
+ else if (bold)
142
+ out = `**${out}**`;
143
+ else if (italic)
144
+ out = `*${out}*`;
145
+ if (underline)
146
+ out = `__${out}__`;
147
+ return lead + out + trail;
148
+ }
149
+ const HEADING_LINE_RE = /^#{1,2}\s/;
150
+ /** `> ` with the space required — a bare `>` typed at a line start ("5 > 3")
151
+ * stays literal, the same conservatism as the inline markers. */
152
+ const QUOTE_LINE_RE = /^>\s/;
153
+ const FENCE_RE = /^```/;
154
+ /**
155
+ * Where the fence opened at `from` closes, or -1 if it never does.
156
+ *
157
+ * An unclosed fence is not a fence: SPEC §13.2 requires an unmatched marker to
158
+ * render literally, and swallowing the rest of the body because somebody typed
159
+ * three backticks is the opposite of that.
160
+ */
161
+ function fenceCloses(lines, from) {
162
+ if (!FENCE_RE.test(lines[from]))
163
+ return -1;
164
+ for (let j = from + 1; j < lines.length; j++)
165
+ if (FENCE_RE.test(lines[j]))
166
+ return j;
167
+ return -1;
168
+ }
169
+ /**
170
+ * Split a body into block segments.
171
+ *
172
+ * Blank lines split runs of plain text into separate `text` segments. `# ` and
173
+ * `## ` become headings; three or more `#`s, and a `#123` reference with no
174
+ * space, stay plain text.
175
+ */
176
+ export function parseBodySegments(body) {
177
+ const lines = body.split('\n');
178
+ const segments = [];
179
+ let i = 0;
180
+ while (i < lines.length) {
181
+ const line = lines[i];
182
+ const fenceEnd = fenceCloses(lines, i);
183
+ if (fenceEnd !== -1) {
184
+ const language = line.slice(3).trim();
185
+ segments.push({
186
+ type: 'code',
187
+ ...(language ? { language } : {}),
188
+ lines: lines.slice(i + 1, fenceEnd),
189
+ });
190
+ i = fenceEnd + 1;
191
+ }
192
+ else if (HEADING_LINE_RE.test(line) && !line.startsWith('###')) {
193
+ segments.push({
194
+ type: 'heading',
195
+ level: line.startsWith('##') ? 2 : 1,
196
+ text: line.replace(HEADING_LINE_RE, ''),
197
+ });
198
+ i++;
199
+ }
200
+ else if (/^[-•]\s/.test(line)) {
201
+ const items = [];
202
+ while (i < lines.length && /^[-•]\s/.test(lines[i])) {
203
+ items.push(lines[i].replace(/^[-•]\s/, ''));
204
+ i++;
205
+ }
206
+ segments.push({ type: 'bullet', items });
207
+ }
208
+ else if (/^\d+\.\s/.test(line)) {
209
+ const items = [];
210
+ while (i < lines.length && /^\d+\.\s/.test(lines[i])) {
211
+ items.push(lines[i].replace(/^\d+\.\s/, ''));
212
+ i++;
213
+ }
214
+ segments.push({ type: 'numbered', items });
215
+ }
216
+ else if (QUOTE_LINE_RE.test(line)) {
217
+ const quoteLines = [];
218
+ while (i < lines.length && QUOTE_LINE_RE.test(lines[i])) {
219
+ quoteLines.push(lines[i].replace(QUOTE_LINE_RE, ''));
220
+ i++;
221
+ }
222
+ segments.push({ type: 'quote', lines: quoteLines });
223
+ }
224
+ else {
225
+ const textLines = [];
226
+ while (i < lines.length &&
227
+ fenceCloses(lines, i) === -1 &&
228
+ !/^[-•]\s/.test(lines[i]) &&
229
+ !/^\d+\.\s/.test(lines[i]) &&
230
+ !QUOTE_LINE_RE.test(lines[i]) &&
231
+ !(HEADING_LINE_RE.test(lines[i]) && !lines[i].startsWith('###'))) {
232
+ textLines.push(lines[i]);
233
+ i++;
234
+ }
235
+ let chunk = [];
236
+ for (const l of textLines) {
237
+ if (l === '') {
238
+ if (chunk.length > 0) {
239
+ segments.push({ type: 'text', lines: chunk });
240
+ chunk = [];
241
+ }
242
+ }
243
+ else {
244
+ chunk.push(l);
245
+ }
246
+ }
247
+ if (chunk.length > 0)
248
+ segments.push({ type: 'text', lines: chunk });
249
+ }
250
+ }
251
+ return segments;
252
+ }
253
+ /**
254
+ * Markers, heading prefixes and fences removed — for one-line previews that
255
+ * render body text raw, outside any renderer.
256
+ *
257
+ * **Prefixes stack, and the order they are removed in is not cosmetic.** The
258
+ * version this was extracted from removed the heading prefix first and the
259
+ * quote prefix second, so `> # Heading` — a quoted heading, which the corpus is
260
+ * full of because every project brief quotes one — came back as `# Heading` and
261
+ * a preview showed a stray `#`. Stripping until the line stops changing removes
262
+ * whatever order they were written in. Found by running this over 152 real
263
+ * published bodies, not by reading the code.
264
+ */
265
+ function stripLinePrefixes(line) {
266
+ let out = line;
267
+ for (;;) {
268
+ const next = out.replace(/^>\s/, '').replace(/^#{1,2}\s/, '');
269
+ if (next === out)
270
+ return out;
271
+ out = next;
272
+ }
273
+ }
274
+ export function stripInlineFormatting(text) {
275
+ return text
276
+ .split('\n')
277
+ .filter((line) => !FENCE_RE.test(line))
278
+ .map((line) => parseInlineMarks(stripLinePrefixes(line)).map((s) => s.text).join(''))
279
+ .join('\n');
280
+ }
281
+ //# sourceMappingURL=content.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content.js","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAiCH;;;;;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AAC;AAED;;;;;;;;;;;GAWG;AACH,SAAS,iBAAiB,CAAC,IAAY;IACrC,IAAI,GAAG,GAAG,IAAI,CAAA;IACd,SAAS,CAAC;QACR,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA;QAC7D,IAAI,IAAI,KAAK,GAAG;YAAE,OAAO,GAAG,CAAA;QAC5B,GAAG,GAAG,IAAI,CAAA;IACZ,CAAC;AACH,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,OAAO,IAAI;SACR,KAAK,CAAC,IAAI,CAAC;SACX,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACtC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;SACpF,IAAI,CAAC,IAAI,CAAC,CAAA;AACf,CAAC"}
package/dist/index.d.ts CHANGED
@@ -46,7 +46,7 @@
46
46
  /** Bumped by hand with the version in package.json — `test/version.test.ts`
47
47
  * pins the two together. It exists so "the upgrade reached the app" can be
48
48
  * checked by grepping a built bundle rather than by trusting a lockfile. */
49
- export declare const PROTOCOL_VERSION = "0.5.0";
49
+ export declare const PROTOCOL_VERSION = "0.6.0";
50
50
  export { type NostrTag, type UnsignedEvent, type SignedEvent, type Profile, type ThreadRef, type ChannelVisibility, type ChannelKind, type MemberRole, type Label, type ResolutionAction, KIND, MAX_EMOJI_CHARS, MAX_MESSAGE_BYTES, MAX_MENTIONS, MAX_RATIONALE_BYTES, RELAY_AUTH_TOLERANCE_SECS, ASSERTION_SUBTYPE, computeEventId, toNostrSeconds, canonicalChannelName, threadTags, addr, relayAuthUrl, buildProfile, parseProfile, buildCreateChannel, buildDeleteChannel, buildEditChannelMetadata, buildAddMember, buildReaction, buildDeletion, buildMessage, buildResolution, buildFile, buildComponent, buildHighlight, buildUnsignedRelayAuthEvent, } from './events.js';
51
51
  export { type AddressPointer, type EventPointer, encodeNevent, decodeNevent, convertBits, bech32Encode, bech32Decode, encodeNaddr, decodeNaddr, pointerToAddress, addressToPointer, addrToNaddr, naddrToAddr, referenceToPointer, NADDR_RE, findNaddrs, stripNaddrs, } from './nip19.js';
52
52
  export { type AuthEventArgs, TIMESTAMP_TOLERANCE_SECS, normalizeUrl, buildUnsignedAuthEvent, base64, authorizationHeaderFor, authorizationHeader, } from './nip98.js';
@@ -54,4 +54,5 @@ export { type Signer, type SignerKind, publicKeyFromSecret, signEvent, secretKey
54
54
  export { type PublishResult, type QueryResult, type RelayHeaders, type RelayOptions, type FetchLike, type QueryAllOptions, parsePublishResponse, parseQueryResponse, RELAY_PAGE_CEILING, DEFAULT_QUERY_CONCURRENCY, Relay, } from './bridge.js';
55
55
  export { type RelayState, type SocketLike, type RelayCredential, type LiveRelayOptions, type Subscription, type LiveRelay, toWebSocketUrl, parseFrame, createLiveRelay, } from './live.js';
56
56
  export { type ChannelEventHandler, type ChannelSubscription, type ChannelSubscriptions, createChannelSubscriptions, } from './subscriptions.js';
57
+ export { type InlineMark, type InlineMarkSpan, type BodySegment, parseInlineMarks, wrapInlineMarks, parseBodySegments, stripInlineFormatting, } from './content.js';
57
58
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH;;4EAE4E;AAC5E,eAAO,MAAM,gBAAgB,UAAU,CAAA;AAEvC,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,WAAW,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AAM,YAAY,CAAA;AAEnB,OAAO,EACL,KAAK,aAAa,EAClB,wBAAwB,EACxB,YAAY,EACZ,sBAAsB,EACtB,MAAM,EACN,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,YAAY,CAAA;AAEnB,OAAO,EACL,KAAK,MAAM,EACX,KAAK,UAAU,EACf,mBAAmB,EACnB,SAAS,EACT,eAAe,GAChB,MAAM,WAAW,CAAA;AAElB,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,yBAAyB,EACzB,KAAK,GACN,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,cAAc,EACd,UAAU,EACV,eAAe,GAChB,MAAM,WAAW,CAAA;AAElB,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,0BAA0B,GAC3B,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EACL,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,cAAc,CAAA"}
package/dist/index.js CHANGED
@@ -46,7 +46,7 @@
46
46
  /** Bumped by hand with the version in package.json — `test/version.test.ts`
47
47
  * pins the two together. It exists so "the upgrade reached the app" can be
48
48
  * checked by grepping a built bundle rather than by trusting a lockfile. */
49
- export const PROTOCOL_VERSION = '0.5.0';
49
+ export const PROTOCOL_VERSION = '0.6.0';
50
50
  export {
51
51
  // constants
52
52
  KIND, MAX_EMOJI_CHARS, MAX_MESSAGE_BYTES, MAX_MENTIONS, MAX_RATIONALE_BYTES, RELAY_AUTH_TOLERANCE_SECS, ASSERTION_SUBTYPE,
@@ -60,4 +60,5 @@ export { publicKeyFromSecret, signEvent, secretKeySigner, } from './sign.js';
60
60
  export { parsePublishResponse, parseQueryResponse, RELAY_PAGE_CEILING, DEFAULT_QUERY_CONCURRENCY, Relay, } from './bridge.js';
61
61
  export { toWebSocketUrl, parseFrame, createLiveRelay, } from './live.js';
62
62
  export { createChannelSubscriptions, } from './subscriptions.js';
63
+ export { parseInlineMarks, wrapInlineMarks, parseBodySegments, stripInlineFormatting, } from './content.js';
63
64
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH;;4EAE4E;AAC5E,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAA;AAEvC,OAAO;AAYL,YAAY;AACZ,IAAI,EACJ,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB;AACjB,8CAA8C;AAC9C,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,UAAU,EACV,IAAI,EACJ,YAAY;AACZ,WAAW;AACX,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,cAAc,EACd,aAAa,EACb,aAAa,EACb,YAAY,EACZ,eAAe,EACf,SAAS,EACT,cAAc,EACd,cAAc,EACd,2BAA2B,GAC5B,MAAM,aAAa,CAAA;AAEpB,OAAO,EAGL,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,QAAQ,EACR,UAAU,EACV,WAAW,GACZ,MAAM,YAAY,CAAA;AAEnB,OAAO,EAEL,w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,OAAO,EAEL,wBAAwB,EACxB,YAAY,EACZ,sBAAsB,EACtB,MAAM,EACN,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,YAAY,CAAA;AAEnB,OAAO,EAGL,mBAAmB,EACnB,SAAS,EACT,eAAe,GAChB,MAAM,WAAW,CAAA;AAElB,OAAO,EAOL,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,yBAAyB,EACzB,KAAK,GACN,MAAM,aAAa,CAAA;AAEpB,OAAO,EAOL,cAAc,EACd,UAAU,EACV,eAAe,GAChB,MAAM,WAAW,CAAA;AAElB,OAAO,EAIL,0BAA0B,GAC3B,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAIL,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,cAAc,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@estiva-app/protocol",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "The Estiva wire format: Buzz-shaped Nostr event builders, NIP-01 ids, NIP-19 naddr, NIP-98 HTTP auth, and the relay clients. Speaks the protocol; interprets nothing.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/content.ts ADDED
@@ -0,0 +1,294 @@
1
+ /**
2
+ * The message marker dialect — SPEC §13.1 and §13.2.
3
+ *
4
+ * ## Why content is in a package that "interprets nothing"
5
+ *
6
+ * `index.ts` draws the line at *interpretation*: the fold stays in the apps,
7
+ * because how an app turns events into current truth is where apps are supposed
8
+ * to differ. A body's formatting is on the other side of that line for the same
9
+ * reason the event id is — **it is wire-visible, and two apps disagreeing about
10
+ * it produces a divergence each copy is self-consistent about and nobody
11
+ * notices.** That is not a hypothetical: measured on production 2026-09-02,
12
+ * 261 of 548 published messages carry structure, Peek parses it, Ship renders
13
+ * it literally, and neither is wrong about its own behaviour.
14
+ *
15
+ * Being honest about the usual test: the relay would *not* notice if two apps
16
+ * disagreed here, so §10's question is a poor fit. What makes this belong is the
17
+ * failure shape rather than the arbiter — see RFC 0.4 §14.3, which put the
18
+ * inline layer here, and SPEC §13.1, which made it normative.
19
+ *
20
+ * **What is deliberately not here.** Mentions resolved against a directory,
21
+ * bracket references to an app's own objects, and anything that needs to know
22
+ * what a topic or a file is. Peek's `textParsing.ts` mixes those with the marks;
23
+ * only the marks moved. A `nostr:` reference is a mark and its *token* is in
24
+ * scope, but what a mention does is RIC-2's.
25
+ */
26
+
27
+ /** Marks a run of text can carry. `code` is exclusive — see {@link parseInlineMarks}. */
28
+ export type InlineMark = 'bold' | 'italic' | 'underline' | 'code'
29
+
30
+ /** A run of text and the marks on it. */
31
+ export interface InlineMarkSpan {
32
+ text: string
33
+ bold?: boolean
34
+ italic?: boolean
35
+ underline?: boolean
36
+ code?: boolean
37
+ }
38
+
39
+ /** A block-level run, parsed from line prefixes. */
40
+ export type BodySegment =
41
+ | { type: 'text'; lines: string[] }
42
+ | { type: 'bullet'; items: string[] }
43
+ | { type: 'numbered'; items: string[] }
44
+ | { type: 'heading'; level: 1 | 2; text: string }
45
+ | { type: 'quote'; lines: string[] }
46
+ | { type: 'code'; language?: string; lines: string[] }
47
+
48
+ interface MarkToken {
49
+ token: string
50
+ keys: InlineMark[]
51
+ /**
52
+ * The content is taken literally and no mark may nest inside it, and the
53
+ * adjacency fence below does not apply to the delimiter.
54
+ */
55
+ literal?: boolean
56
+ }
57
+
58
+ /**
59
+ * Longest token first so `***` is not consumed as `**` plus a dangling `*`.
60
+ *
61
+ * Order only decides ties at one index — the scanner walks left to right, so the
62
+ * leftmost opening delimiter wins regardless of what is listed first.
63
+ */
64
+ const MARK_TOKENS: MarkToken[] = [
65
+ { token: '***', keys: ['bold', 'italic'] },
66
+ { token: '**', keys: ['bold'] },
67
+ { token: '__', keys: ['underline'] },
68
+ { token: '*', keys: ['italic'] },
69
+ { token: '`', keys: ['code'], literal: true },
70
+ ]
71
+
72
+ const isWordChar = (ch: string | undefined) => ch !== undefined && /[A-Za-z0-9]/.test(ch)
73
+
74
+ /**
75
+ * SPEC §13.2 rule 2 — a marker adjacent to an alphanumeric is not a marker, so
76
+ * `2*3*4` stays literal math.
77
+ *
78
+ * **It does not apply to a backtick.** Rule 2 resolves an ambiguity that only
79
+ * asymmetric prose markers have: `*` is multiplication and a glob, `_` is in
80
+ * identifiers. A backtick is not used as ordinary punctuation, so there is no
81
+ * ambiguity to resolve — and applying the fence anyway leaves `` `main`s ``
82
+ * literal, which is a code span followed by a plural or possessive. Measured
83
+ * against production 2026-09-02: 8 such spans in 6 published messages, and zero
84
+ * cases of the opening side needing the fence. CommonMark agrees.
85
+ */
86
+ function findMarkClose(text: string, token: string, from: number, fenced: boolean): number {
87
+ let idx = text.indexOf(token, from)
88
+ while (idx !== -1) {
89
+ if (!fenced || !isWordChar(text[idx + token.length])) return idx
90
+ idx = text.indexOf(token, idx + 1)
91
+ }
92
+ return -1
93
+ }
94
+
95
+ function toMarkSpan(text: string, active: InlineMark[]): InlineMarkSpan {
96
+ const span: InlineMarkSpan = { text }
97
+ for (const key of active) span[key] = true
98
+ return span
99
+ }
100
+
101
+ function scanMarks(text: string, active: InlineMark[]): InlineMarkSpan[] {
102
+ for (let i = 0; i < text.length; i++) {
103
+ for (const { token, keys, literal } of MARK_TOKENS) {
104
+ if (keys.some((k) => active.includes(k))) continue
105
+ if (!text.startsWith(token, i)) continue
106
+ const fenced = !literal
107
+ if (fenced && isWordChar(text[i - 1])) continue
108
+ const close = findMarkClose(text, token, i + token.length, fenced)
109
+ if (close === -1) continue
110
+ const inner = text.slice(i + token.length, close)
111
+ // SPEC §13.2 rule 1: whitespace at the inner edges means it is not a pair.
112
+ if (!inner || /^\s/.test(inner) || /\s$/.test(inner)) continue
113
+ const spans: InlineMarkSpan[] = []
114
+ const before = text.slice(0, i)
115
+ if (before) spans.push(toMarkSpan(before, active))
116
+ if (literal) {
117
+ /*
118
+ SPEC §13.1: code MUST NOT combine with any other mark, and its content
119
+ MUST NOT be parsed for further marks. So the span carries `code` alone
120
+ even inside an enclosing bold — dropping the outer mark rather than
121
+ emitting a combination the spec forbids.
122
+ */
123
+ spans.push({ text: inner, code: true })
124
+ } else {
125
+ spans.push(...scanMarks(inner, [...active, ...keys]))
126
+ }
127
+ spans.push(...scanMarks(text.slice(close + token.length), active))
128
+ return spans
129
+ }
130
+ }
131
+ return text ? [toMarkSpan(text, active)] : []
132
+ }
133
+
134
+ /**
135
+ * Parse one plain-text run into styled spans.
136
+ *
137
+ * Split mentions and app-specific references out first — this function knows
138
+ * about marks and nothing else.
139
+ */
140
+ export function parseInlineMarks(text: string): InlineMarkSpan[] {
141
+ return scanMarks(text, [])
142
+ }
143
+
144
+ /**
145
+ * Wrap a run of text in the markers for the marks it carries.
146
+ *
147
+ * Edge whitespace is hoisted outside the markers, because `**word **` would not
148
+ * parse back under rule 1 — so bolding "word " round-trips as `**word** `.
149
+ *
150
+ * `code` wins alone, for the same reason the parser never emits it combined.
151
+ */
152
+ export function wrapInlineMarks(text: string, markNames: ReadonlySet<string>): string {
153
+ if (!text) return text
154
+ const bold = markNames.has('bold')
155
+ const italic = markNames.has('italic')
156
+ const underline = markNames.has('underline')
157
+ const code = markNames.has('code')
158
+ if (!bold && !italic && !underline && !code) return text
159
+ const m = text.match(/^(\s*)([\s\S]*?)(\s*)$/)!
160
+ const [, lead, core, trail] = m
161
+ if (!core) return text
162
+ if (code) return `${lead}\`${core}\`${trail}`
163
+ let out = core
164
+ if (bold && italic) out = `***${out}***`
165
+ else if (bold) out = `**${out}**`
166
+ else if (italic) out = `*${out}*`
167
+ if (underline) out = `__${out}__`
168
+ return lead + out + trail
169
+ }
170
+
171
+ const HEADING_LINE_RE = /^#{1,2}\s/
172
+ /** `> ` with the space required — a bare `>` typed at a line start ("5 > 3")
173
+ * stays literal, the same conservatism as the inline markers. */
174
+ const QUOTE_LINE_RE = /^>\s/
175
+ const FENCE_RE = /^```/
176
+
177
+ /**
178
+ * Where the fence opened at `from` closes, or -1 if it never does.
179
+ *
180
+ * An unclosed fence is not a fence: SPEC §13.2 requires an unmatched marker to
181
+ * render literally, and swallowing the rest of the body because somebody typed
182
+ * three backticks is the opposite of that.
183
+ */
184
+ function fenceCloses(lines: string[], from: number): number {
185
+ if (!FENCE_RE.test(lines[from])) return -1
186
+ for (let j = from + 1; j < lines.length; j++) if (FENCE_RE.test(lines[j])) return j
187
+ return -1
188
+ }
189
+
190
+ /**
191
+ * Split a body into block segments.
192
+ *
193
+ * Blank lines split runs of plain text into separate `text` segments. `# ` and
194
+ * `## ` become headings; three or more `#`s, and a `#123` reference with no
195
+ * space, stay plain text.
196
+ */
197
+ export function parseBodySegments(body: string): BodySegment[] {
198
+ const lines = body.split('\n')
199
+ const segments: BodySegment[] = []
200
+ let i = 0
201
+ while (i < lines.length) {
202
+ const line = lines[i]
203
+ const fenceEnd = fenceCloses(lines, i)
204
+ if (fenceEnd !== -1) {
205
+ const language = line.slice(3).trim()
206
+ segments.push({
207
+ type: 'code',
208
+ ...(language ? { language } : {}),
209
+ lines: lines.slice(i + 1, fenceEnd),
210
+ })
211
+ i = fenceEnd + 1
212
+ } else if (HEADING_LINE_RE.test(line) && !line.startsWith('###')) {
213
+ segments.push({
214
+ type: 'heading',
215
+ level: line.startsWith('##') ? 2 : 1,
216
+ text: line.replace(HEADING_LINE_RE, ''),
217
+ })
218
+ i++
219
+ } else if (/^[-•]\s/.test(line)) {
220
+ const items: string[] = []
221
+ while (i < lines.length && /^[-•]\s/.test(lines[i])) {
222
+ items.push(lines[i].replace(/^[-•]\s/, ''))
223
+ i++
224
+ }
225
+ segments.push({ type: 'bullet', items })
226
+ } else if (/^\d+\.\s/.test(line)) {
227
+ const items: string[] = []
228
+ while (i < lines.length && /^\d+\.\s/.test(lines[i])) {
229
+ items.push(lines[i].replace(/^\d+\.\s/, ''))
230
+ i++
231
+ }
232
+ segments.push({ type: 'numbered', items })
233
+ } else if (QUOTE_LINE_RE.test(line)) {
234
+ const quoteLines: string[] = []
235
+ while (i < lines.length && QUOTE_LINE_RE.test(lines[i])) {
236
+ quoteLines.push(lines[i].replace(QUOTE_LINE_RE, ''))
237
+ i++
238
+ }
239
+ segments.push({ type: 'quote', lines: quoteLines })
240
+ } else {
241
+ const textLines: string[] = []
242
+ while (
243
+ i < lines.length &&
244
+ fenceCloses(lines, i) === -1 &&
245
+ !/^[-•]\s/.test(lines[i]) &&
246
+ !/^\d+\.\s/.test(lines[i]) &&
247
+ !QUOTE_LINE_RE.test(lines[i]) &&
248
+ !(HEADING_LINE_RE.test(lines[i]) && !lines[i].startsWith('###'))
249
+ ) {
250
+ textLines.push(lines[i])
251
+ i++
252
+ }
253
+ let chunk: string[] = []
254
+ for (const l of textLines) {
255
+ if (l === '') {
256
+ if (chunk.length > 0) { segments.push({ type: 'text', lines: chunk }); chunk = [] }
257
+ } else {
258
+ chunk.push(l)
259
+ }
260
+ }
261
+ if (chunk.length > 0) segments.push({ type: 'text', lines: chunk })
262
+ }
263
+ }
264
+ return segments
265
+ }
266
+
267
+ /**
268
+ * Markers, heading prefixes and fences removed — for one-line previews that
269
+ * render body text raw, outside any renderer.
270
+ *
271
+ * **Prefixes stack, and the order they are removed in is not cosmetic.** The
272
+ * version this was extracted from removed the heading prefix first and the
273
+ * quote prefix second, so `> # Heading` — a quoted heading, which the corpus is
274
+ * full of because every project brief quotes one — came back as `# Heading` and
275
+ * a preview showed a stray `#`. Stripping until the line stops changing removes
276
+ * whatever order they were written in. Found by running this over 152 real
277
+ * published bodies, not by reading the code.
278
+ */
279
+ function stripLinePrefixes(line: string): string {
280
+ let out = line
281
+ for (;;) {
282
+ const next = out.replace(/^>\s/, '').replace(/^#{1,2}\s/, '')
283
+ if (next === out) return out
284
+ out = next
285
+ }
286
+ }
287
+
288
+ export function stripInlineFormatting(text: string): string {
289
+ return text
290
+ .split('\n')
291
+ .filter((line) => !FENCE_RE.test(line))
292
+ .map((line) => parseInlineMarks(stripLinePrefixes(line)).map((s) => s.text).join(''))
293
+ .join('\n')
294
+ }
package/src/index.ts CHANGED
@@ -47,7 +47,7 @@
47
47
  /** Bumped by hand with the version in package.json — `test/version.test.ts`
48
48
  * pins the two together. It exists so "the upgrade reached the app" can be
49
49
  * checked by grepping a built bundle rather than by trusting a lockfile. */
50
- export const PROTOCOL_VERSION = '0.5.0'
50
+ export const PROTOCOL_VERSION = '0.6.0'
51
51
 
52
52
  export {
53
53
  // types
@@ -163,3 +163,13 @@ export {
163
163
  type ChannelSubscriptions,
164
164
  createChannelSubscriptions,
165
165
  } from './subscriptions.js'
166
+
167
+ export {
168
+ type InlineMark,
169
+ type InlineMarkSpan,
170
+ type BodySegment,
171
+ parseInlineMarks,
172
+ wrapInlineMarks,
173
+ parseBodySegments,
174
+ stripInlineFormatting,
175
+ } from './content.js'