@zswarm/core 0.4.0 → 0.4.1

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.
@@ -21,8 +21,9 @@ export type SenderOrigin = {
21
21
  };
22
22
  /**
23
23
  * Clean one origin part for the `[zswarm from=…]` header: non-strings and
24
- * blanks become null, header-breaking characters become spaces, runs of
25
- * whitespace collapse, and the result is capped at 64 chars.
24
+ * blanks become null, header-breaking characters and whitespace runs become a
25
+ * single `_` (a value never holds a space, so `key=value` pairs stay
26
+ * splittable), and the result is capped at 64 chars.
26
27
  */
27
28
  export declare function sanitizeOriginPart(raw: unknown): string | null;
28
29
  /** The origin of the caller's own process, read from its environment. */
@@ -33,7 +34,10 @@ export declare function resolveSenderOrigin(env: NodeJS.ProcessEnv): SenderOrigi
33
34
  * client) keeps every part null but still records that serve carried it.
34
35
  */
35
36
  export declare function originFromServeRequest(raw: unknown): SenderOrigin;
36
- /** " @ session/pane on host via serve" (or the parts that are known). */
37
+ /**
38
+ * " src=session/pane host=host via=serve" (only the parts that are known).
39
+ * `from=` stays the bare label, so a reader can split the header on spaces.
40
+ */
37
41
  export declare function originSuffix(origin: SenderOrigin | null | undefined): string;
38
42
  export type DeliveryResult = {
39
43
  to: string;
@@ -6,18 +6,19 @@ import { isTrue, numberArg, optionalString } from "./util.js";
6
6
  const ORIGIN_PART_MAX = 64;
7
7
  /**
8
8
  * Clean one origin part for the `[zswarm from=…]` header: non-strings and
9
- * blanks become null, header-breaking characters become spaces, runs of
10
- * whitespace collapse, and the result is capped at 64 chars.
9
+ * blanks become null, header-breaking characters and whitespace runs become a
10
+ * single `_` (a value never holds a space, so `key=value` pairs stay
11
+ * splittable), and the result is capped at 64 chars.
11
12
  */
12
13
  export function sanitizeOriginPart(raw) {
13
14
  if (typeof raw !== "string")
14
15
  return null;
15
- const cleaned = raw.replace(/[\r\n[\]]+/g, " ").replace(/\s+/g, " ").trim();
16
+ const cleaned = raw.replace(/[\r\n[\]\s]+/g, " ").trim().replace(/ /g, "_");
16
17
  if (!cleaned)
17
18
  return null;
18
19
  return cleaned.length <= ORIGIN_PART_MAX
19
20
  ? cleaned
20
- : cleaned.slice(0, ORIGIN_PART_MAX).trimEnd();
21
+ : cleaned.slice(0, ORIGIN_PART_MAX).replace(/_+$/, "");
21
22
  }
22
23
  /** The origin of the caller's own process, read from its environment. */
23
24
  export function resolveSenderOrigin(env) {
@@ -50,15 +51,18 @@ export function originFromServeRequest(raw) {
50
51
  via: "serve",
51
52
  };
52
53
  }
53
- /** " @ session/pane on host via serve" (or the parts that are known). */
54
+ /**
55
+ * " src=session/pane host=host via=serve" (only the parts that are known).
56
+ * `from=` stays the bare label, so a reader can split the header on spaces.
57
+ */
54
58
  export function originSuffix(origin) {
55
59
  if (!origin)
56
60
  return "";
57
61
  const { session, pane, host, via } = origin;
58
- const loc = session && pane ? `${session}/${pane}` : (pane ?? session ?? null);
59
- return ((loc ? " @ " + loc : "") +
60
- (host ? " on " + host : "") +
61
- (via === "serve" ? " via serve" : ""));
62
+ const src = session && pane ? `${session}/${pane}` : (pane ?? session ?? null);
63
+ return ((src ? " src=" + src : "") +
64
+ (host ? " host=" + host : "") +
65
+ (via === "serve" ? " via=serve" : ""));
62
66
  }
63
67
  /**
64
68
  * An args-supplied origin, cleaned again (a direct caller may skip dispatch),
package/dist/schema.js CHANGED
@@ -281,7 +281,7 @@ export const PARAMS = [
281
281
  type: "string",
282
282
  flags: ["--from", "-f"],
283
283
  ops: ["send", "broadcast"],
284
- description: "send: sender label in the [zswarm from=…] prefix (default: ZSWARM_FROM, else the sending pane's title, else swarm). zswarm appends the sender's session/pane, host (ZSWARM_HOST) and `via serve`",
284
+ description: "send: sender label in the [zswarm from=…] prefix (default: ZSWARM_FROM, else the sending pane's title, else swarm). zswarm appends src=<session>/<pane>, host=<host> (ZSWARM_HOST) and via=serve",
285
285
  },
286
286
  {
287
287
  name: "raw",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zswarm/core",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "type": "module",
5
5
  "description": "zSwarm Zellij client and shared ops dispatch",
6
6
  "exports": {