@avatarsd-llc/libtracer-client 0.11.0 → 0.13.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/dist/fwd.d.ts CHANGED
@@ -147,6 +147,15 @@ export interface ParsedFwd {
147
147
  readonly mintRequest: boolean;
148
148
  /** @brief `dst` is a `PATH_REF` (`0x14`), not a canonical `PATH` (RFC-0024 §4). */
149
149
  readonly dstBound: boolean;
150
+ /**
151
+ * @brief The trailing reverse-direction list a mint-flagged FORWARDED request carries — a
152
+ * `PATH_REF_REVERSE` (`0x15`), RFC-0024 §7.1 amendments 1 and 2 (else `null`).
153
+ *
154
+ * Identified by its TYPE, never by its position: a WRITE's payload is whatever stands in
155
+ * the payload slot as long as it is not this code, INCLUDING a raw `PATH_REF`. The origin
156
+ * never emits the child, so this is `null` on every frame a client builds.
157
+ */
158
+ readonly reverse: Tlv | null;
150
159
  }
151
160
  /**
152
161
  * @brief The opcode field of the `op` byte — bits 5-0 (RFC-0024 §7.5).
package/dist/fwd.js CHANGED
@@ -278,7 +278,9 @@ export function parseFwdTlv(fwd) {
278
278
  payload = ch[i++];
279
279
  }
280
280
  else if (op === FWD_OP.WRITE) {
281
- if (i < ch.length)
281
+ // The reverse list is told from the payload by its TYPE (RFC-0024 §7.1 amendment 2), so a
282
+ // raw PATH_REF payload is a payload and only 0x15 is the list.
283
+ if (i < ch.length && ch[i].type !== TYPE.PATH_REF_REVERSE)
282
284
  payload = ch[i++];
283
285
  }
284
286
  else if (op === FWD_OP.AWAIT) {
@@ -287,7 +289,10 @@ export function parseFwdTlv(fwd) {
287
289
  i++;
288
290
  }
289
291
  }
290
- return { op, dst, field, src, kind, payload, awaitTimeoutNs, mintRequest, dstBound };
292
+ // Licensed only on a mint-flagged request (§7.1 amendment 1): on an unflagged frame a
293
+ // trailing 0x15 binds no route and stays unparsed.
294
+ const reverse = mintRequest && ch[i]?.type === TYPE.PATH_REF_REVERSE ? ch[i] : null;
295
+ return { op, dst, field, src, kind, payload, awaitTimeoutNs, mintRequest, dstBound, reverse };
291
296
  }
292
297
  /**
293
298
  * @brief Decode a complete FWD frame's bytes into its parsed children.
package/dist/index.d.ts CHANGED
@@ -16,9 +16,9 @@
16
16
  export declare const CLIENT_EXPERIMENTAL: true;
17
17
  export { LibtracerClient, FwdError, CompactFlowError } from './client.js';
18
18
  export type { ClientTransport, ValueHandler, Unsubscribe, ClientOptions, } from './client.js';
19
- export { encodeValue, encodePath, encodeSubscriber, encodeConnSpec, firstChild, DELIVERY_DURABILITY_REQUEST } from './tlv.js';
19
+ export { encodeValue, encodePath, encodeSubscriber, encodeConnSpec, firstChild, pathSegments, PACKED_ESCAPE_LEN, DELIVERY_DURABILITY_REQUEST, } from './tlv.js';
20
20
  export type { ValueOptions, SubscriberOptions, ConnSpecOptions, ConnRole } from './tlv.js';
21
- export { walkTopology, routeKey } from './topology.js';
21
+ export { walkTopology, routeKey, CONN_ENDPOINT_NAME } from './topology.js';
22
22
  export type { TopologyGraph, TopologyNode, TopologyEdge, TopologyBusPeers, TopologyGap, WalkOptions, } from './topology.js';
23
23
  export { FWD_OP, FWD_OPCODE_MASK, FWD_OP_FLAG_MINT_REQUEST, FWD_KIND, FWD_ERROR, FWD_ERROR_PATH, fwdErrorName, fwdErrorPath, fwdErrorCodeForPath, encodeFwd, encodeField, parseField, decodeFwd, parseFwdTlv, replyErrorCode, replyErrorPath, } from './fwd.js';
24
24
  export type { FwdRequest, ParsedFwd, FieldLevel } from './fwd.js';
package/dist/index.js CHANGED
@@ -17,6 +17,6 @@
17
17
  */
18
18
  export const CLIENT_EXPERIMENTAL = true;
19
19
  export { LibtracerClient, FwdError, CompactFlowError } from './client.js';
20
- export { encodeValue, encodePath, encodeSubscriber, encodeConnSpec, firstChild, DELIVERY_DURABILITY_REQUEST } from './tlv.js';
21
- export { walkTopology, routeKey } from './topology.js';
20
+ export { encodeValue, encodePath, encodeSubscriber, encodeConnSpec, firstChild, pathSegments, PACKED_ESCAPE_LEN, DELIVERY_DURABILITY_REQUEST, } from './tlv.js';
21
+ export { walkTopology, routeKey, CONN_ENDPOINT_NAME } from './topology.js';
22
22
  export { FWD_OP, FWD_OPCODE_MASK, FWD_OP_FLAG_MINT_REQUEST, FWD_KIND, FWD_ERROR, FWD_ERROR_PATH, fwdErrorName, fwdErrorPath, fwdErrorCodeForPath, encodeFwd, encodeField, parseField, decodeFwd, parseFwdTlv, replyErrorCode, replyErrorPath, } from './fwd.js';
package/dist/tlv.d.ts CHANGED
@@ -66,8 +66,8 @@ export declare function encodeValue(value: Uint8Array, opts?: ValueOptions): Uin
66
66
  */
67
67
  export declare function nameTlv(segment: string): Tlv;
68
68
  /**
69
- * @brief Build a PATH TLV (`type=0x06`, PL=1) from path segments — a NAME child
70
- * per segment.
69
+ * @brief Build a PATH TLV (`type=0x06`, PL=0) from path segments — one packed
70
+ * `[u8 len][utf8]` record per segment (RFC-0018).
71
71
  *
72
72
  * Vector-pinned: `path-sensor-temp`; normative byte layout: spec/v1.md §3.1.
73
73
  *
@@ -78,6 +78,32 @@ export declare function nameTlv(segment: string): Tlv;
78
78
  export declare function encodePath(segments: string[]): Uint8Array;
79
79
  /** @brief The PATH TLV node (shared by {@link encodePath}, {@link encodeSubscriber}, and `./fwd.ts`). */
80
80
  export declare function pathTlv(segments: string[]): Tlv;
81
+ /**
82
+ * @brief The `len == 0` ESCAPE record's length byte — RFC-0018 §8 / §5.4 Amendment 1.
83
+ *
84
+ * An escape is `00 <u8 kind> <u8 len> <len bytes>`. It is **admissible in a frame path** — a
85
+ * forwarder steps over one whose `kind` it does not implement instead of dropping a frame it
86
+ * is only relaying — and **rejected in canonical / key context**, because a label is not
87
+ * canonical bytes. This client never mints one; `kind = 0x16` is reserved for RFC-0027.
88
+ */
89
+ export declare const PACKED_ESCAPE_LEN = 0;
90
+ /**
91
+ * @brief Read a PATH TLV's packed body back into its segments — the inverse of
92
+ * {@link encodePath}, in **canonical / key** context.
93
+ *
94
+ * `encodePath(segs)` then `decode` then this yields `segs` again; the round trip is exact
95
+ * because a packed record has exactly one spelling per segment (RFC-0018 §4).
96
+ *
97
+ * The escape is REFUSED here rather than skipped: a caller reading segments wants an ADDRESS,
98
+ * and an address carrying a label is not one. A forwarder that only relays the frame never
99
+ * calls this.
100
+ *
101
+ * @param path a decoded PATH TLV
102
+ * @returns its segments, in order (empty for the graph root)
103
+ * @throws {RangeError} if the TLV is not a packed PATH, the records do not tile the body, or
104
+ * a record is the escape
105
+ */
106
+ export declare function pathSegments(path: Tlv): string[];
81
107
  /** @brief The link direction of a connection (`role`), per ADR-0027 / `conn_role_t`. */
82
108
  export type ConnRole = 'dial' | 'listen';
83
109
  /** @brief The connection SPEC a {@link encodeConnSpec} call describes (ADR-0027 / reference/13). */
package/dist/tlv.js CHANGED
@@ -9,7 +9,7 @@
9
9
  * (`@avatarsd-llc/libtracer`) — nothing here invents wire structure:
10
10
  *
11
11
  * - encodeValue -> VALUE TLV (0x01) : value-bool-true / value-ll-u32 / value-ts-abs
12
- * - encodePath -> PATH TLV (0x06, PL=1) : path-sensor-temp + spec/v1.md §3.1
12
+ * - encodePath -> PATH TLV (0x06, PL=0) : path-sensor-temp + spec/v1.md §3.1
13
13
  * - encodeSubscriber -> SUBSCRIBER TLV (0x04) : subscriber-path (the subscribe-write payload)
14
14
  *
15
15
  * Reading back, `firstChild` is the package's single child-by-type accessor and
@@ -50,17 +50,19 @@ export function firstChild(tlv, type) {
50
50
  /** @brief Path-segment constraints from reference/03-addressing.md §path syntax. */
51
51
  const MAX_SEGMENT_BYTES = 64;
52
52
  /**
53
- * @brief Maximum NAME segments in one PATH (reference/03 §path syntax; `core` `kMaxSegments`).
53
+ * @brief Maximum segments in one PATH (reference/03 §path syntax; `core` `kMaxSegments`).
54
54
  *
55
55
  * Repriced 32 -> 255 by RFC-0023 — chosen so every per-segment quantity stays u8-representable,
56
- * not inherited from a parser guard. Under this body encoding each segment costs `4 + len`, so
57
- * {@link MAX_PATH_BYTES} admits at most 204 segments and the BYTE cap binds first; this is the
58
- * encoding-independent ceiling.
56
+ * not inherited from a parser guard. Under RFC-0018's packed body a segment costs `1 + len`, so
57
+ * {@link MAX_PATH_BYTES} admits 512 one-byte records and this COUNT is what binds. (Before the
58
+ * packing a segment cost `4 + len`, 204 segments filled the byte cap, and the count clause
59
+ * could never fire.)
59
60
  */
60
61
  const MAX_SEGMENTS = 255;
61
62
  /**
62
- * @brief Maximum encoded PATH body — the concatenated NAME TLVs, i.e. exactly the PATH TLV's own
63
- * `length` field (reference/03 §path syntax, 2026-07-31 erratum; `core` `kMaxPathBytes`).
63
+ * @brief Maximum encoded PATH body — the concatenated packed `[u8 len][utf8]` segment records,
64
+ * i.e. exactly the PATH TLV's own `length` field (reference/03 §path syntax, 2026-07-31
65
+ * erratum; RFC-0018 §5; `core` `kMaxPathBytes`).
64
66
  */
65
67
  const MAX_PATH_BYTES = 1024;
66
68
  /** @brief Reserved characters that MUST NOT appear inside a NAME segment (reference/03, /05 §NAME). */
@@ -126,8 +128,8 @@ export function nameTlv(segment) {
126
128
  return { type: TYPE.NAME, opt: opt(), payload: bytes, children: [], trailer: null };
127
129
  }
128
130
  /**
129
- * @brief Build a PATH TLV (`type=0x06`, PL=1) from path segments — a NAME child
130
- * per segment.
131
+ * @brief Build a PATH TLV (`type=0x06`, PL=0) from path segments — one packed
132
+ * `[u8 len][utf8]` record per segment (RFC-0018).
131
133
  *
132
134
  * Vector-pinned: `path-sensor-temp`; normative byte layout: spec/v1.md §3.1.
133
135
  *
@@ -144,22 +146,77 @@ export function pathTlv(segments) {
144
146
  throw new RangeError('a path must have at least one segment');
145
147
  if (segments.length > MAX_SEGMENTS)
146
148
  throw new RangeError(`a path may have at most ${MAX_SEGMENTS} segments (got ${segments.length})`);
147
- const children = segments.map(nameTlv);
149
+ // `nameTlv` is still the SEGMENT PREDICATE — 1..64 UTF-8 bytes, no reserved character — even
150
+ // though its NAME framing is no longer what a PATH carries. Reusing it keeps one home for
151
+ // the addressing grammar; only the bytes it is turned into changed (RFC-0018).
152
+ const records = segments.map((seg) => nameTlv(seg).payload);
148
153
  // The encode-time byte check the spec has always required and this client never had
149
154
  // (RFC-0023 §5.6): the 1024-byte budget is measured as the PATH TLV's own `length` field —
150
- // each NAME costs its 4-byte header plus its UTF-8 bytes. It binds BEFORE the segment count
151
- // under this encoding (204 * 5 = 1020), so it is the bound that actually fires.
152
- const bodyBytes = children.reduce((n, child) => n + 4 + child.payload.length, 0);
155
+ // each packed record costs one length byte plus its UTF-8 bytes. Under the packing it is the
156
+ // segment COUNT that binds first (255 one-byte records are 510 bytes), so this clause now
157
+ // fires only on genuinely long segments.
158
+ const bodyBytes = records.reduce((n, r) => n + 1 + r.length, 0);
153
159
  if (bodyBytes > MAX_PATH_BYTES)
154
160
  throw new RangeError(`a path's encoded body may be at most ${MAX_PATH_BYTES} bytes (got ${bodyBytes})`);
161
+ const payload = new Uint8Array(bodyBytes);
162
+ let at = 0;
163
+ for (const r of records) {
164
+ payload[at++] = r.length;
165
+ payload.set(r, at);
166
+ at += r.length;
167
+ }
155
168
  return {
156
169
  type: TYPE.PATH,
157
- opt: opt({ pl: true }),
158
- payload: new Uint8Array(0),
159
- children,
170
+ // PL = 0: a packed body is NOT a child run, and a set PL would make a generic walker read
171
+ // the first body bytes as a TLV header and mis-frame the whole address (RFC-0018 §5).
172
+ opt: opt(),
173
+ payload,
174
+ children: [],
160
175
  trailer: null,
161
176
  };
162
177
  }
178
+ /**
179
+ * @brief The `len == 0` ESCAPE record's length byte — RFC-0018 §8 / §5.4 Amendment 1.
180
+ *
181
+ * An escape is `00 <u8 kind> <u8 len> <len bytes>`. It is **admissible in a frame path** — a
182
+ * forwarder steps over one whose `kind` it does not implement instead of dropping a frame it
183
+ * is only relaying — and **rejected in canonical / key context**, because a label is not
184
+ * canonical bytes. This client never mints one; `kind = 0x16` is reserved for RFC-0027.
185
+ */
186
+ export const PACKED_ESCAPE_LEN = 0;
187
+ /**
188
+ * @brief Read a PATH TLV's packed body back into its segments — the inverse of
189
+ * {@link encodePath}, in **canonical / key** context.
190
+ *
191
+ * `encodePath(segs)` then `decode` then this yields `segs` again; the round trip is exact
192
+ * because a packed record has exactly one spelling per segment (RFC-0018 §4).
193
+ *
194
+ * The escape is REFUSED here rather than skipped: a caller reading segments wants an ADDRESS,
195
+ * and an address carrying a label is not one. A forwarder that only relays the frame never
196
+ * calls this.
197
+ *
198
+ * @param path a decoded PATH TLV
199
+ * @returns its segments, in order (empty for the graph root)
200
+ * @throws {RangeError} if the TLV is not a packed PATH, the records do not tile the body, or
201
+ * a record is the escape
202
+ */
203
+ export function pathSegments(path) {
204
+ if (path.type !== TYPE.PATH || path.opt.pl || path.children.length > 0)
205
+ throw new RangeError('not a packed PATH TLV (RFC-0018: type 0x06 with opt.PL = 0)');
206
+ const decoder = new TextDecoder('utf-8', { fatal: true });
207
+ const out = [];
208
+ let at = 0;
209
+ while (at < path.payload.length) {
210
+ const len = path.payload[at];
211
+ if (len === PACKED_ESCAPE_LEN)
212
+ throw new RangeError('a PATH escape record (len == 0) is not admissible in key context');
213
+ if (at + 1 + len > path.payload.length)
214
+ throw new RangeError('a PATH segment record runs past the body');
215
+ out.push(decoder.decode(path.payload.subarray(at + 1, at + 1 + len)));
216
+ at += 1 + len;
217
+ }
218
+ return out;
219
+ }
163
220
  /**
164
221
  * @brief Build a NAME TLV (`type=0x02`) for FREE TEXT — a SETTINGS key or a string
165
222
  * config value — WITHOUT the path-segment validation {@link nameTlv} applies.
@@ -249,6 +249,17 @@ export interface WalkOptions {
249
249
  }
250
250
  /** @brief `["b","c"]` → `"/b/c"`; `[]` → `"/"` (the vantage). */
251
251
  export declare function routeKey(route: string[]): string;
252
+ /**
253
+ * @brief The RESERVED, protocol-owned leaf NAME of a module's creator endpoint —
254
+ * `/net/<module>/conn` (RFC-0014 §1/§3).
255
+ *
256
+ * A module's `:children[]` lists this alongside its member connections, because the
257
+ * endpoint IS a vertex under the module. It is not a link: it is the write-driven control
258
+ * a creator sends `SPEC`/`NAME` to, with no peer behind it. Hiding it from the listing is
259
+ * RFC-0014 S4; a walker skips it either way, since a node older than S4 will keep listing
260
+ * it and a topology projection must not grow a node for a control surface.
261
+ */
262
+ export declare const CONN_ENDPOINT_NAME = "conn";
252
263
  /**
253
264
  * @brief Walk the reachable topology from `client`'s vantage and stitch it into a graph.
254
265
  *
package/dist/topology.js CHANGED
@@ -17,6 +17,17 @@ const RESERVED_SEGMENT_CHARS = /[/:.[\]*?]/;
17
17
  export function routeKey(route) {
18
18
  return route.length === 0 ? '/' : '/' + route.join('/');
19
19
  }
20
+ /**
21
+ * @brief The RESERVED, protocol-owned leaf NAME of a module's creator endpoint —
22
+ * `/net/<module>/conn` (RFC-0014 §1/§3).
23
+ *
24
+ * A module's `:children[]` lists this alongside its member connections, because the
25
+ * endpoint IS a vertex under the module. It is not a link: it is the write-driven control
26
+ * a creator sends `SPEC`/`NAME` to, with no peer behind it. Hiding it from the listing is
27
+ * RFC-0014 S4; a walker skips it either way, since a node older than S4 will keep listing
28
+ * it and a topology projection must not grow a node for a control surface.
29
+ */
30
+ export const CONN_ENDPOINT_NAME = 'conn';
20
31
  /** @brief The NAME strings of a `:children[]` POINT listing. */
21
32
  function listingNames(tlv) {
22
33
  const names = [];
@@ -162,8 +173,16 @@ export async function walkTopology(client, opts = {}) {
162
173
  for (const module of modules) {
163
174
  try {
164
175
  const names = listingNames(await client.readField([...route, netRoot, module], ':children[]'));
165
- for (const name of names)
176
+ // `conn` is the module's RESERVED creator endpoint, not a connection (RFC-0014
177
+ // §3): it is a control surface with no peer behind it, so descending into it
178
+ // would mint a phantom node the walk could never identify. RFC-0014 S4 will hide
179
+ // it from this listing at the source; until then the reserved name is skipped
180
+ // HERE, which is also what a walker must do against any node that predates S4.
181
+ for (const name of names) {
182
+ if (name === CONN_ENDPOINT_NAME)
183
+ continue;
166
184
  links.push({ module, name });
185
+ }
167
186
  }
168
187
  catch (err) {
169
188
  noteGap('module', route, id, module, null, err, `could not read connections of module "${module}" at ${routeKey(route)}: ${String(err)}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avatarsd-llc/libtracer-client",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "description": "EXPERIMENTAL libtracer client SDK (#56, ADR-0034/0035) — a path-addressed client over the cross-validated codec (@avatarsd-llc/libtracer) and an injected transport seam (e.g. @avatarsd-llc/libtracer-ws). Speaks the RFC-0004 remote operations over FWD: read / write / await / readField / subscribe, each a FWD frame whose source-routed FWD{REPLY} is decoded back. Pre-1.0 and experimental.",
5
5
  "author": "avatarsd LLC",
6
6
  "license": "Apache-2.0",
@@ -33,8 +33,8 @@
33
33
  "access": "public"
34
34
  },
35
35
  "peerDependencies": {
36
- "@avatarsd-llc/libtracer": ">=0.11.0 <0.12.0",
37
- "@avatarsd-llc/libtracer-ws": ">=0.11.0 <0.12.0"
36
+ "@avatarsd-llc/libtracer": ">=0.13.0 <0.14.0",
37
+ "@avatarsd-llc/libtracer-ws": ">=0.13.0 <0.14.0"
38
38
  },
39
39
  "peerDependenciesMeta": {
40
40
  "@avatarsd-llc/libtracer-ws": {