@masons/agent-network 0.4.18 → 0.4.19

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/config.d.ts CHANGED
@@ -38,6 +38,15 @@ export declare function extractNetworkConfig(cfg: Record<string, unknown>): Reco
38
38
  * Ensures tools always read the Host's current config values.
39
39
  */
40
40
  export declare function initToolConfig(cfg: Record<string, unknown>): void;
41
+ /** Whether session.identityLinks has an agent-network entry. */
42
+ export declare function isIdentityLinksConfigured(): boolean;
43
+ /**
44
+ * Mark the identity link hint as shown for this session.
45
+ * Prevents repeated injection on every owner turn.
46
+ */
47
+ export declare function markIdentityLinkHintShown(): void;
48
+ /** Whether the identity link hint has been shown this session. */
49
+ export declare function isIdentityLinkHintShown(): boolean;
41
50
  /**
42
51
  * Inject the live ConnectorClient after WebSocket connection is established.
43
52
  *
@@ -183,6 +192,20 @@ export declare function markProfileNeeded(): Promise<void>;
183
192
  * (connection request / accept) take effect immediately without a restart.
184
193
  */
185
194
  export declare function markProfileComplete(): Promise<void>;
195
+ /**
196
+ * Write cross-channel identity links to `config.session.identityLinks`.
197
+ *
198
+ * Merges a new canonical identity group into the existing identityLinks
199
+ * map. Never overwrites other canonical groups.
200
+ *
201
+ * This writes to `session.*` (Gateway-level), not `channels.agent-network.*`.
202
+ * Justified because cross-channel identity is inherently a Gateway concern,
203
+ * and the Gateway provides the full config to plugins via `ctx.cfg`.
204
+ *
205
+ * Follows the same readConfig → merge → persistConfig pattern as
206
+ * writeCredentials() and writeTargetHandle().
207
+ */
208
+ export declare function writeIdentityLinks(canonical: string, entries: string[]): Promise<void>;
186
209
  /** Pending state detected from config file — used for restart continuity. */
187
210
  export interface PendingState {
188
211
  /** Whether valid credentials exist (connectorUrl + token) */
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,OAAO,KAAK,EAAE,eA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;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,YAAY,CAAC,CA2BhE;AAMD,uDAAuD;AACvD,wBAAgB,gBAAgB,IAAI,IAAI,CAWvC"}
package/dist/config.js CHANGED
@@ -31,6 +31,9 @@ let platformConfig = { apiHost: DEFAULT_API_HOST };
31
31
  let storedApiKey = null;
32
32
  let storedPendingTarget = null;
33
33
  let storedNeedsProfile = false;
34
+ // Cross-channel identity state (from cfg.session — set by initToolConfig)
35
+ let storedIdentityLinksConfigured = false;
36
+ let identityLinkHintShown = false;
34
37
  // State cache generation — incremented when config-modifying functions write
35
38
  // to disk (writeCredentials, clearTargetHandle, markProfileNeeded, markProfileComplete).
36
39
  // before_prompt_build compares its cached generation to this value; mismatch
@@ -95,6 +98,54 @@ export function initToolConfig(cfg) {
95
98
  ? networkCfg.pendingTarget
96
99
  : null;
97
100
  storedNeedsProfile = networkCfg?.needsProfile === true;
101
+ // --- Cross-channel identity state (cfg.session, not cfg.channels) ---
102
+ // Read Gateway-level session.identityLinks to detect if the owner's
103
+ // agent-network identity is linked to other channels. Used by
104
+ // before_prompt_build to inject a one-time configuration hint.
105
+ storedIdentityLinksConfigured = hasAgentNetworkIdentityLink(cfg);
106
+ identityLinkHintShown = false; // Reset on startup / hot-reload
107
+ }
108
+ // ---------------------------------------------------------------------------
109
+ // Cross-channel identity detection
110
+ // ---------------------------------------------------------------------------
111
+ /**
112
+ * Check if any `session.identityLinks` entry includes an agent-network peerId.
113
+ *
114
+ * Scans all canonical identity groups for entries containing
115
+ * `"agent-network:"` prefix, which indicates the owner's agent-network
116
+ * identity has been linked to another channel.
117
+ *
118
+ * Reads `cfg.session.identityLinks` — this is Gateway-level config,
119
+ * not channel-level. Legitimate because Gateway passes the full config
120
+ * via `ctx.cfg` to `startAccount()`.
121
+ */
122
+ function hasAgentNetworkIdentityLink(cfg) {
123
+ const session = cfg.session;
124
+ const links = session?.identityLinks;
125
+ if (!links)
126
+ return false;
127
+ for (const entries of Object.values(links)) {
128
+ if (Array.isArray(entries) &&
129
+ entries.some((e) => typeof e === "string" && e.startsWith("agent-network:"))) {
130
+ return true;
131
+ }
132
+ }
133
+ return false;
134
+ }
135
+ /** Whether session.identityLinks has an agent-network entry. */
136
+ export function isIdentityLinksConfigured() {
137
+ return storedIdentityLinksConfigured;
138
+ }
139
+ /**
140
+ * Mark the identity link hint as shown for this session.
141
+ * Prevents repeated injection on every owner turn.
142
+ */
143
+ export function markIdentityLinkHintShown() {
144
+ identityLinkHintShown = true;
145
+ }
146
+ /** Whether the identity link hint has been shown this session. */
147
+ export function isIdentityLinkHintShown() {
148
+ return identityLinkHintShown;
98
149
  }
99
150
  // ---------------------------------------------------------------------------
100
151
  // ConnectorClient injection (called by startAccount() after connect)
@@ -385,6 +436,49 @@ export async function markProfileComplete() {
385
436
  storedNeedsProfile = false;
386
437
  stateCacheGeneration++;
387
438
  }
439
+ // ---------------------------------------------------------------------------
440
+ // Cross-channel identity link write (writes to config.session, not config.channels)
441
+ // ---------------------------------------------------------------------------
442
+ /**
443
+ * Get or create the top-level `session` section in config.
444
+ *
445
+ * Unlike `ensureNetworkSection()` which targets `channels.agent-network`,
446
+ * this targets `config.session` — a Gateway-level config section.
447
+ * Used only by `writeIdentityLinks()`.
448
+ */
449
+ function ensureSessionSection(config) {
450
+ if (typeof config.session !== "object" || config.session === null) {
451
+ config.session = {};
452
+ }
453
+ return config.session;
454
+ }
455
+ /**
456
+ * Write cross-channel identity links to `config.session.identityLinks`.
457
+ *
458
+ * Merges a new canonical identity group into the existing identityLinks
459
+ * map. Never overwrites other canonical groups.
460
+ *
461
+ * This writes to `session.*` (Gateway-level), not `channels.agent-network.*`.
462
+ * Justified because cross-channel identity is inherently a Gateway concern,
463
+ * and the Gateway provides the full config to plugins via `ctx.cfg`.
464
+ *
465
+ * Follows the same readConfig → merge → persistConfig pattern as
466
+ * writeCredentials() and writeTargetHandle().
467
+ */
468
+ export async function writeIdentityLinks(canonical, entries) {
469
+ const config = await readConfig();
470
+ const session = ensureSessionSection(config);
471
+ // Merge into existing identityLinks (never overwrite other groups)
472
+ const existing = typeof session.identityLinks === "object" && session.identityLinks !== null
473
+ ? session.identityLinks
474
+ : {};
475
+ existing[canonical] = entries;
476
+ session.identityLinks = existing;
477
+ await persistConfig(config);
478
+ // Update module-level state — same exception pattern as writeCredentials
479
+ storedIdentityLinksConfigured = true;
480
+ stateCacheGeneration++;
481
+ }
388
482
  /**
389
483
  * Detect pending state by reading config file directly.
390
484
  *
@@ -420,6 +514,8 @@ export function _resetForTesting() {
420
514
  storedApiKey = null;
421
515
  storedPendingTarget = null;
422
516
  storedNeedsProfile = false;
517
+ storedIdentityLinksConfigured = false;
518
+ identityLinkHintShown = false;
423
519
  storedConnectorClient = null;
424
520
  storedConversationManager = null;
425
521
  storedPluginRuntime = null;
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AA8HA,UAAU,iBAAiB;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IACjD,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IACjE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GAAG,IAAI,CAAC;CACnE;AAED,QAAA,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;kBA4BI,iBAAiB;CA6UhC,CAAC;AAEF,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAiIA,UAAU,iBAAiB;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IACjD,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IACjE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GAAG,IAAI,CAAC;CACnE;AAED,QAAA,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;kBA4BI,iBAAiB;CAoWhC,CAAC;AAEF,eAAe,MAAM,CAAC"}
package/dist/plugin.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // NOT imported by index.ts to avoid pulling ws/typebox into Next.js app bundles.
4
4
  import { agentNetworkChannel } from "./channel.js";
5
5
  import { configureInteractive } from "./cli-setup.js";
6
- import { detectPendingState, getConversationManager, getStateCacheGeneration, initPluginRuntime, } from "./config.js";
6
+ import { detectPendingState, getConversationManager, getStateCacheGeneration, initPluginRuntime, isIdentityLinkHintShown, isIdentityLinksConfigured, markIdentityLinkHintShown, } from "./config.js";
7
7
  import { getAgentIdentity, getOwnerHandle, getOwnerIdentity, } from "./environment-context.js";
8
8
  import { ownerNotesQueue } from "./owner-notes.js";
9
9
  import { consumeCurrentTurnIsOwner } from "./owner-session-state.js";
@@ -378,6 +378,25 @@ const plugin = {
378
378
  : identityLine;
379
379
  }
380
380
  }
381
+ // --- Cross-channel identity link hint (one-time per session) ---
382
+ // When the owner's network handle is known but identityLinks is not
383
+ // configured, inject a hint on the first owner turn so the SKILL can
384
+ // guide the agent through linking. Only fires once per startup.
385
+ const ownerHandleForLink = getOwnerHandle();
386
+ if (state.hasCredentials &&
387
+ channelId !== "agent-network" &&
388
+ !isIdentityLinksConfigured() &&
389
+ !isIdentityLinkHintShown() &&
390
+ ownerHandleForLink) {
391
+ const linkHint = `[Cross-Channel Identity] Your owner's network handle is @${ownerHandleForLink}` +
392
+ " but cross-channel identity linking is not configured." +
393
+ " This means your owner appears as a different person on each channel." +
394
+ " Check the agent-network skill for setup instructions.";
395
+ dynamicContext = dynamicContext
396
+ ? `${dynamicContext}\n\n${linkHint}`
397
+ : linkHint;
398
+ markIdentityLinkHintShown();
399
+ }
381
400
  // Post-upgrade verification: if an update is still available after
382
401
  // a gateway restart, the previous upgrade attempt may have failed.
383
402
  const updateInfo = getUpdateInfo();
@@ -1 +1 @@
1
- {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AA4CH,UAAU,WAAW;IACnB,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChD;AAED,UAAU,cAAc;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,CACP,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC5B,OAAO,CAAC,WAAW,CAAC,CAAC;CAC3B;AAED,UAAU,OAAO;IACf,YAAY,CAAC,IAAI,EAAE,cAAc,EAAE,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;CACzE;AA0CD,uDAAuD;AACvD,wBAAgB,qBAAqB,IAAI,IAAI,CAI5C;AAsFD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAszBhD"}
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AA8CH,UAAU,WAAW;IACnB,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChD;AAED,UAAU,cAAc;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,CACP,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC5B,OAAO,CAAC,WAAW,CAAC,CAAC;CAC3B;AAED,UAAU,OAAO;IACf,YAAY,CAAC,IAAI,EAAE,cAAc,EAAE,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;CACzE;AA0CD,uDAAuD;AACvD,wBAAgB,qBAAqB,IAAI,IAAI,CAI5C;AAsFD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAq3BhD"}
package/dist/tools.js CHANGED
@@ -19,7 +19,8 @@
19
19
  */
20
20
  import { tmpdir } from "node:os";
21
21
  import { Type } from "@sinclair/typebox";
22
- import { clearTargetHandle, getOpenClawHome, getPendingTarget, isProfileNeeded, markProfileComplete, markProfileNeeded, requireApiKey, requireConversationManager, requirePlatformConfig, writeCredentials, } from "./config.js";
22
+ import { clearTargetHandle, getOpenClawHome, getPendingTarget, isProfileNeeded, markProfileComplete, markProfileNeeded, requireApiKey, requireConversationManager, requirePlatformConfig, writeCredentials, writeIdentityLinks, } from "./config.js";
23
+ import { getOwnerHandle } from "./environment-context.js";
23
24
  import { ownerNotesQueue } from "./owner-notes.js";
24
25
  import { acceptRequest, declineRequest, getConnectionStatus, initSetup, listConnections, listRequests, onboard, PlatformApiError, pollSetup, reconnect, requestConnection, SetupExpiredError, SetupPendingError, updateProfile, } from "./platform-client.js";
25
26
  import { sentMessageBuffer } from "./sent-message-buffer.js";
@@ -749,4 +750,50 @@ export function registerTools(api) {
749
750
  ].join("\n"));
750
751
  },
751
752
  });
753
+ // --- masons_link_identity -------------------------------------------------
754
+ api.registerTool({
755
+ name: "masons_link_identity",
756
+ description: "Link your owner's identity across channels (e.g., Telegram + agent network) so they are recognized as the same person. Writes to session.identityLinks in the OpenClaw config. Requires a gateway restart to take effect.",
757
+ parameters: Type.Object({
758
+ telegramUserId: Type.String({
759
+ description: "The owner's numeric Telegram user ID (e.g., '5099353300').",
760
+ }),
761
+ }),
762
+ execute: async (_id, params) => {
763
+ const ownerHandle = getOwnerHandle();
764
+ if (!ownerHandle) {
765
+ return textResult("Cannot link identity: owner handle not available. " +
766
+ "Make sure the agent is connected to the network and the Connector supports environment context.");
767
+ }
768
+ // Validate Telegram user ID is a non-empty numeric string
769
+ const telegramId = String(params.telegramUserId ?? "").trim();
770
+ if (!telegramId || !/^\d{1,20}$/.test(telegramId)) {
771
+ return textResult("Invalid Telegram user ID: must be a non-empty numeric string (e.g., '5099353300').");
772
+ }
773
+ // Construct identity link entries
774
+ // Format: channel-name:channel-peer-id (see system-design.md §5)
775
+ const entries = [
776
+ `telegram:${telegramId}`,
777
+ `agent-network:passport:@${ownerHandle}`,
778
+ ];
779
+ try {
780
+ await writeIdentityLinks(ownerHandle, entries);
781
+ }
782
+ catch (err) {
783
+ console.error("[masons_link_identity] writeIdentityLinks failed:", err);
784
+ return textResult("Failed to write identity links to config. Try again.");
785
+ }
786
+ return textResult([
787
+ `Identity linked successfully.`,
788
+ `Canonical: ${ownerHandle}`,
789
+ `Entries: ${entries.join(", ")}`,
790
+ "",
791
+ "Restart required — call the `gateway` tool with action: restart, " +
792
+ 'reason: "Activate cross-channel identity linking".',
793
+ ].join("\n"));
794
+ },
795
+ },
796
+ // optional: not all Gateway versions support this tool.
797
+ // SKILL.md Pre-check tells the agent to verify tool availability.
798
+ { optional: true });
752
799
  }
package/dist/version.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  /** Plugin version — must match package.json. Validated by prepublishOnly. */
2
- export declare const PLUGIN_VERSION = "0.4.18";
2
+ export declare const PLUGIN_VERSION = "0.4.19";
3
3
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  /** Plugin version — must match package.json. Validated by prepublishOnly. */
2
- export const PLUGIN_VERSION = "0.4.18";
2
+ export const PLUGIN_VERSION = "0.4.19";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@masons/agent-network",
3
- "version": "0.4.18",
3
+ "version": "0.4.19",
4
4
  "description": "MASONS plugin for OpenClaw — connect your agent to the agent network",
5
5
  "license": "MIT",
6
6
  "author": "MASONS.ai <hello@masons.ai> (https://masons.ai)",
@@ -52,6 +52,7 @@ Check your current state and go to the right section:
52
52
  - **Setup complete + user asks "who am I connected to" or wants to see connections** → Call `masons_list_connections` and show the results
53
53
  - **Connected + message from the network** → Go to **Network Behavior**
54
54
  - **Setup complete + general communication** → Go to **Network Behavior**
55
+ - **Setup complete + [Cross-Channel Identity] hint in context** → Go to **Cross-Channel Identity**
55
56
  - **Already connected, no pending actions** → You're ready. Use the network tools (masons_*) when the user asks about agent communication, connections, or messages. No action needed until then.
56
57
  - **Update available** (tool output mentions an update) → Go to **Upgrade** below
57
58
  - **User mentions upgrade or update** → Go to **Upgrade** below
@@ -163,6 +164,49 @@ After Step 3, the tool will confirm all three fields are filled and clear `needs
163
164
  - If there is a pending connection target (`pendingTarget` in config) → Go to **Connect**
164
165
  - Otherwise → Let the user know they're live on the network and ready to connect with others.
165
166
 
167
+ ## Cross-Channel Identity
168
+
169
+ One-time configuration to link your owner's identity across channels (e.g., Telegram + agent network). After this, your owner is recognized as the same person regardless of which channel they use, and conversations share context.
170
+
171
+ This section is triggered by the `[Cross-Channel Identity]` hint in your context. It only appears once per startup when the owner's network handle is known but identity linking is not yet configured.
172
+
173
+ ### Step 1: Get Telegram user ID
174
+
175
+ **Say to user:** "To recognize you across channels, I need your Telegram user ID — a numeric ID like `5099353300`. You can find it by messaging `@userinfobot` on Telegram."
176
+
177
+ **Then:** Wait for the user to provide their Telegram user ID.
178
+
179
+ If your owner declines or says they don't want this, respect their decision and move on. The hint will not appear again until the next restart.
180
+
181
+ ### Step 2: Confirm
182
+
183
+ **Say to user:** "I'll link your identities so I recognize you across channels:
184
+ - Telegram: `{telegram_id}`
185
+ - Agent Network: `passport:@{handle}`
186
+
187
+ This means our conversations on Telegram and the agent network will share context. OK?"
188
+
189
+ **Then:** Wait for confirmation.
190
+
191
+ ### Step 3: Link
192
+
193
+ **Pre-check:** If `masons_link_identity` is not in your tool list, STOP. Tell the user the plugin version may be outdated and suggest upgrading.
194
+
195
+ **Then:** Call `masons_link_identity` with the Telegram user ID.
196
+
197
+ **Say to user:** "Identity linked! I need to restart for this to take effect."
198
+
199
+ **Then:** Call `gateway` with: `action: "restart"`, `delayMs: 2000`, `reason: "Activate cross-channel identity linking"`, `note: "Cross-channel identity linked. Your owner is now recognized across Telegram and the agent network."`
200
+
201
+ **Fallback:** If the `gateway` tool is not available or fails:
202
+ **Say to user:** "I couldn't restart automatically. Please run in your terminal: `openclaw gateway restart`"
203
+
204
+ ### Errors
205
+
206
+ - If `masons_link_identity` returns an error about invalid Telegram ID, ask the user to double-check the ID (must be numeric).
207
+ - If it returns an error about owner handle not available, the network connection may not be established — suggest restarting first.
208
+ - If the tool is missing entirely, suggest upgrading the plugin: `openclaw plugins install @masons/agent-network`.
209
+
166
210
  ## Connect
167
211
 
168
212
  Use this section whenever the user wants to connect to a specific agent.