instar 1.3.841 → 1.3.843

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.
@@ -125,7 +125,7 @@ import { buildAutoloopGoal } from '../scheduler/MentorAutonomousGuardian.js';
125
125
  import { STAGE_A_ALLOWED_TOOLS, buildConversationSurface, parseMenteeReplies, parseMentorSent, } from '../monitoring/MentorStageA.js';
126
126
  import { analyzeForensics } from '../scheduler/MentorStageBForensics.js';
127
127
  import { TelegramAdapter as MentorTelegramAdapter } from '../messaging/TelegramAdapter.js';
128
- import { sendAgentMessage, A2A_VERSION } from '../messaging/AgentTelegramComms.js';
128
+ import { A2A_VERSION } from '../messaging/AgentTelegramComms.js';
129
129
  import { AgentTelegramLedger, defaultLedgerPaths as defaultA2aLedgerPaths } from '../messaging/AgentTelegramLedger.js';
130
130
  import { DEFAULT_MENTEE_CONFIG } from '../messaging/MenteeReceiverConfig.js';
131
131
  import { ProcessedIdStore } from '../messaging/ProcessedIdStore.js';
@@ -188,6 +188,7 @@ export class AgentServer {
188
188
  poolLink;
189
189
  poolPollCache;
190
190
  meshSelfId;
191
+ deliverA2aToMachine;
191
192
  routeContext = null;
192
193
  deliverySentinel = null;
193
194
  deliveryStore = null;
@@ -343,6 +344,7 @@ export class AgentServer {
343
344
  this.poolLink = options.poolLink ?? undefined;
344
345
  this.poolPollCache = options.poolPollCache ?? undefined;
345
346
  this.meshSelfId = options.meshSelfId ?? undefined;
347
+ this.deliverA2aToMachine = options.deliverA2aToMachine;
346
348
  this.state = options.state;
347
349
  this.hookEventReceiver = options.hookEventReceiver ?? undefined;
348
350
  this.toneGate = options.messagingToneGate ?? null;
@@ -2904,7 +2906,7 @@ export class AgentServer {
2904
2906
  * the session is killed and an empty reply is logged — no partial
2905
2907
  * transcript is sent.
2906
2908
  * 3. Captures the tmux pane transcript as the reply.
2907
- * 4. Sends the reply back via `sendAgentMessage` with
2909
+ * 4. Sends the reply back through the canonical A2A delivery seam with
2908
2910
  * `role='mentor-reply'` and `corr=msg.corr || msg.id` so the
2909
2911
  * mentor's `OutstandingPromptTracker` can clear by correlation.
2910
2912
  *
@@ -3016,6 +3018,7 @@ export class AgentServer {
3016
3018
  // (knownAgents[instar-codey].botId === senderBotId) passes.
3017
3019
  fromBotId: self.ownPrimaryBotId(),
3018
3020
  toBotId: menteeCfg.knownMentors[msg.from]?.botId,
3021
+ targetMachineId: menteeCfg.knownMentors[msg.from]?.machineId,
3019
3022
  });
3020
3023
  };
3021
3024
  roleHandlers.set('mentor', mentorMessageHandler);
@@ -3152,37 +3155,42 @@ export class AgentServer {
3152
3155
  catch (err) {
3153
3156
  console.warn(`[a2a] local-inbox delivery attempt failed (to=${opts.toAgent}): ${err instanceof Error ? err.message : String(err)}`);
3154
3157
  }
3155
- // ── Cross-machine Telegram fallback (mentor→mentee only; currently
3156
- // unreachable due to bot-to-bot block — tracked follow-up). ──
3157
- if (opts.telegramBot && opts.telegramTopicId !== undefined && opts.toBotId && opts.botToken) {
3158
- try {
3159
- const result = await sendAgentMessage({
3160
- fromAgent: opts.fromAgent, toAgent: opts.toAgent, role: opts.role,
3161
- toTopicId: opts.telegramTopicId, message: opts.body, id, correlationId: opts.corr,
3162
- }, {
3163
- send: async (topicId, text) => {
3164
- try {
3165
- const res = await opts.telegramBot.sendToTopic(topicId, text);
3166
- return { ok: true, messageId: String(res.messageId) };
3167
- }
3168
- catch (e) {
3169
- return { ok: false, error: e };
3170
- }
3171
- },
3172
- appendAudit: (row) => ledger.appendSent(row),
3173
- now: () => Date.now(),
3174
- mintId: () => id,
3175
- allowedRoles: opts.allowedRoles,
3176
- botToken: opts.botToken,
3177
- fromBotId: opts.botToken.split(':')[0],
3178
- toBotId: opts.toBotId,
3179
- });
3180
- return result.ok;
3181
- }
3182
- catch (err) {
3183
- console.warn(`[a2a] telegram fallback failed (to=${opts.toAgent}): ${err instanceof Error ? err.message : String(err)}`);
3158
+ // ── Cross-machine: signed MeshRpc → recipient's EXISTING inbox hook ──
3159
+ // Telegram remains a visible mirror only. It can never make this branch
3160
+ // successful because Telegram bots do not receive other bots' messages.
3161
+ if (opts.targetMachineId && this.deliverA2aToMachine && opts.telegramTopicId !== undefined) {
3162
+ const tsNow = Date.now();
3163
+ const marker = `[a2a:from=${opts.fromAgent} to=${opts.toAgent} role=${opts.role} id=${id} corr=${opts.corr} ts=${tsNow} v=${A2A_VERSION}]`;
3164
+ const result = await this.deliverA2aToMachine({
3165
+ machineId: opts.targetMachineId,
3166
+ targetAgent: opts.toAgent,
3167
+ text: `${marker}\n\n${opts.body}`,
3168
+ topicId: opts.telegramTopicId,
3169
+ senderAgent: opts.fromAgent,
3170
+ senderBotId: opts.fromBotId ?? `${opts.fromAgent}-mesh`,
3171
+ }).catch((err) => ({ ok: false, reason: err instanceof Error ? err.message : String(err) }));
3172
+ if (result.ok && result.agentMessage === true) {
3173
+ try {
3174
+ ledger.appendSent({
3175
+ ts: tsNow, from: opts.fromAgent, to: opts.toAgent, role: opts.role,
3176
+ id, corr: opts.corr, result: 'sent', transport: 'a2a-inbox-mesh',
3177
+ });
3178
+ }
3179
+ catch { /* best-effort */ }
3180
+ console.log(`[a2a] delivered → ${opts.toAgent} via signed mesh inbox (machine=${opts.targetMachineId}, role=${opts.role}, corr=${opts.corr})`);
3181
+ if (opts.visibleEcho) {
3182
+ void sendMentorVisibleEcho(opts.body, opts.visibleEcho).catch((err) => {
3183
+ console.warn(`[mentor-echo] unexpected failure after mesh delivery: ${err instanceof Error ? err.message : String(err)}`);
3184
+ });
3185
+ }
3186
+ return true;
3184
3187
  }
3188
+ console.warn(`[a2a] signed mesh inbox refused (machine=${opts.targetMachineId}, to=${opts.toAgent}, role=${opts.role}, reason=${result.reason ?? 'not-routed'})`);
3189
+ return false;
3185
3190
  }
3191
+ // Telegram bot-to-bot sends are never a delivery authority: bots do not
3192
+ // receive other bots' messages. A visible mirror is emitted only above,
3193
+ // after the local or signed-mesh inbox explicitly accepts the envelope.
3186
3194
  return false;
3187
3195
  }
3188
3196
  /** Snapshot of mentee config for the receiver-wiring installer. */
@@ -3545,6 +3553,7 @@ export class AgentServer {
3545
3553
  // session) and the Telegram fallback, so the whole exchange moves
3546
3554
  // together. Falls back to menteeTopicId (backward-compatible).
3547
3555
  telegramTopicId: resolveMentorDeliveryTopic(cfg),
3556
+ targetMachineId: cfg.menteeMachineId,
3548
3557
  // fromBotId = echo's mentor-bot id, so the mentee's allowlist
3549
3558
  // (knownMentors[echo].botId === senderBotId) passes.
3550
3559
  fromBotId: cfg.botToken ? cfg.botToken.split(':')[0] : undefined,