@mnemom/mnemom 0.17.2-next.5 → 0.17.2-next.6

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.
@@ -40,6 +40,12 @@ export type ThreadIndex = Map<string, Map<string, Set<string>>>;
40
40
  export declare function buildThreadIndex(posts: Iterable<PostRecord>): ThreadIndex;
41
41
  /** Normalise a session name for comparison (same shape the launcher emits). */
42
42
  export declare function normSession(raw: string): string;
43
+ /**
44
+ * The live session `name` addresses: an exact (normalised) match, else the ONE live
45
+ * session whose name ends in `-<name>` — so `mnemom-design-helper` reaches
46
+ * `agent-user-mnemom-design-helper`. Ambiguous or unknown → undefined.
47
+ */
48
+ export declare function resolveLiveSession(name: string, live: Map<string, string>): string | undefined;
43
49
  /**
44
50
  * The sessions `ev` is addressed to. `liveSessions` are the names with a running
45
51
  * listener; `botUserId` is the app's bot user (from auth.test). Returns [] for
@@ -44,6 +44,21 @@ export function normSession(raw) {
44
44
  .replace(/^-+|-+$/g, "");
45
45
  }
46
46
  const HANDLE_RE = /(?:^|[\s(])@([a-z0-9][a-z0-9-]*[a-z0-9])(?=$|[\s,.:;!?)])/gi;
47
+ /**
48
+ * The live session `name` addresses: an exact (normalised) match, else the ONE live
49
+ * session whose name ends in `-<name>` — so `mnemom-design-helper` reaches
50
+ * `agent-user-mnemom-design-helper`. Ambiguous or unknown → undefined.
51
+ */
52
+ export function resolveLiveSession(name, live) {
53
+ const n = normSession(name);
54
+ if (!n)
55
+ return undefined;
56
+ const exact = live.get(n);
57
+ if (exact)
58
+ return exact;
59
+ const hits = [...live.keys()].filter((k) => k.endsWith(`-${n}`));
60
+ return hits.length === 1 ? live.get(hits[0]) : undefined;
61
+ }
47
62
  /**
48
63
  * The sessions `ev` is addressed to. `liveSessions` are the names with a running
49
64
  * listener; `botUserId` is the app's bot user (from auth.test). Returns [] for
@@ -70,7 +85,7 @@ export function routeMessage(ev, ctx) {
70
85
  while (at !== -1) {
71
86
  const after = text.slice(at + mention.length).match(/^[\s,:]*@?([A-Za-z0-9][A-Za-z0-9-]*)/);
72
87
  if (after) {
73
- const hit = live.get(normSession(after[1]));
88
+ const hit = resolveLiveSession(after[1], live);
74
89
  if (hit)
75
90
  out.add(hit);
76
91
  }
@@ -78,7 +93,7 @@ export function routeMessage(ev, ctx) {
78
93
  }
79
94
  // 3. plain @handle for a known live session
80
95
  for (const m of text.matchAll(HANDLE_RE)) {
81
- const hit = live.get(normSession(m[1]));
96
+ const hit = resolveLiveSession(m[1], live);
82
97
  if (hit)
83
98
  out.add(hit);
84
99
  }
@@ -90,10 +105,10 @@ export function routeMessage(ev, ctx) {
90
105
  * A word after the mention that is NOT a live session is kept (it is content).
91
106
  */
92
107
  export function stripAddressing(text, botUserId, liveSessions) {
93
- const live = new Set([...liveSessions].map(normSession));
108
+ const live = new Map([...liveSessions].map((s) => [normSession(s), s]));
94
109
  const re = new RegExp(`<@${botUserId}>[\\s,:]*(?:@?([A-Za-z0-9][A-Za-z0-9-]*)[\\s,:]*)?`, "g");
95
110
  return text
96
- .replace(re, (_whole, name) => name && !live.has(normSession(name)) ? `${name} ` : "")
111
+ .replace(re, (_whole, name) => name && !resolveLiveSession(name, live) ? `${name} ` : "")
97
112
  .replace(/[ \t]{2,}/g, " ")
98
113
  .trim();
99
114
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mnemom/mnemom",
3
- "version": "0.17.2-next.5",
3
+ "version": "0.17.2-next.6",
4
4
  "description": "Transparent AI agent tracing",
5
5
  "type": "module",
6
6
  "bin": {