🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
fix(federation): authorize outbound sends with current peer trust
Rudy Mizrahi Celekli1646757c5aa6
diff --git a/v3/@claude-flow/plugin-agent-federation/__tests__/unit/current-peer-trust-3561.test.ts b/v3/@claude-flow/plugin-agent-federation/__tests__/unit/current-peer-trust-3561.test.tsnew file mode 100644index 0000000000..d771bb4c1a--- /dev/null+++ b/v3/@claude-flow/plugin-agent-federation/__tests__/unit/current-peer-trust-3561.test.ts@@ -0,0 +1,117 @@+import { afterEach, describe, expect, it } from 'vitest';+import { FederationCoordinator } from '../../src/application/federation-coordinator.js';+import { PolicyEngine } from '../../src/application/policy-engine.js';+import { TrustEvaluator } from '../../src/application/trust-evaluator.js';+import { DiscoveryService, type FederationManifest } from '../../src/domain/services/discovery-service.js';+import { HandshakeService } from '../../src/domain/services/handshake-service.js';+import { RoutingService } from '../../src/domain/services/routing-service.js';+import { AuditService } from '../../src/domain/services/audit-service.js';+import { PIIPipelineService } from '../../src/domain/services/pii-pipeline-service.js';+import { TrustLevel } from '../../src/domain/entities/trust-level.js';+import type { FederationEnvelope, FederationMessageType } from '../../src/domain/entities/federation-envelope.js';++const coordinators: FederationCoordinator[] = [];+afterEach(async () => { for (const coordinator of coordinators.splice(0)) await coordinator.shutdown(); });++function manifest(nodeId: string): FederationManifest {+ return { nodeId, publicKey: `${nodeId}-key`, endpoint: `ws://${nodeId}.example:9100`,+ capabilities: { agentTypes: [], maxConcurrentSessions: 4, supportedProtocols: ['websocket'], complianceModes: [] },+ version: '1.0.0', signature: 'fixture-signature', timestamp: new Date().toISOString() };+}++async function fixture(resolveTrust = true) {+ let counter = 0;+ // Deterministic signing adapters isolate trust authorization from cryptography and transport.+ const discovery = new DiscoveryService({ signManifest: async () => 'fixture-signature', verifyManifest: async () => true });+ const handshake = new HandshakeService({ generateSessionId: () => `session-${++counter}`,+ generateSessionToken: () => `token-${++counter}`, generateNonce: () => `nonce-${++counter}`,+ signChallenge: async () => 'signature', verifySignature: async () => true,+ getLocalNodeId: () => 'local', getLocalPublicKey: () => 'local-key', getLocalCapabilities: () => ['send'] });+ const pii = new PIIPipelineService({ hashFunction: () => 'fixture-hash' });+ const scans: number[] = [];+ const sent: FederationEnvelope[] = [];+ let coordinator: FederationCoordinator;+ const routing = new RoutingService({ generateEnvelopeId: () => `envelope-${++counter}`, generateNonce: () => `nonce-${++counter}`,+ signEnvelope: () => 'fixture-hmac', verifyEnvelope: () => true,+ getLocalNodeId: () => 'local', getActiveSessions: () => coordinator.getActiveSessions(),+ getPeerTrustLevel: resolveTrust ? nodeId => discovery.getPeer(nodeId)?.trustLevel : undefined,+ scanPii: (text, trustLevel) => {+ scans.push(trustLevel);+ const result = pii.transform(text, trustLevel);+ return { transformedText: result.transformedText, scanResult: { scanned: true, piiFound: result.detections.length > 0,+ detections: result.detections.map(d => ({ type: d.type, confidence: d.confidence,+ action: result.actionsApplied.find(a => a.type === d.type)?.action ?? 'pass' })),+ actionsApplied: result.actionsApplied.map(a => a.action), scanDurationMs: 0 } };+ }, sendToNode: async (_nodeId, envelope) => { sent.push(envelope); } });+ const audit = new AuditService({ generateEventId: () => `audit-${++counter}`, getLocalNodeId: () => 'local',+ persistEvent: async () => {}, queryEvents: async () => [] });+ coordinator = new FederationCoordinator({ nodeId: 'local', publicKey: 'local-key', endpoint: manifest('local').endpoint, capabilities: [] },+ discovery, handshake, routing, audit, pii, new TrustEvaluator(), new PolicyEngine({ checkClaim: () => true }));+ await coordinator.initialize(manifest('local'));+ coordinators.push(coordinator);+ const peerManifest = manifest('remote');+ const session = await coordinator.joinPeer(peerManifest.endpoint, peerManifest);+ return { coordinator, discovery, routing, scans, sent, session, peerManifest };+}++describe('outbound current peer trust (#3561)', () => {+ it.each(['task-assignment', 'memory-query', 'context-share'] as FederationMessageType[])(+ 'uses bootstrap elevation for %s while preserving the handshake snapshot', async messageType => {+ const f = await fixture();+ expect(f.session.trustLevel).toBe(TrustLevel.VERIFIED);+ await f.coordinator.bootstrapElevatePeer('remote', TrustLevel.TRUSTED, 'test operator approval');+ expect((await f.coordinator.sendMessage('remote', messageType, { task: 'fixture' })).success).toBe(true);+ expect(f.scans).toEqual([TrustLevel.TRUSTED]);+ expect(f.sent).toHaveLength(1);+ expect(f.session.trustLevel).toBe(TrustLevel.VERIFIED);+ });++ it('uses current trust for the real PII transformation, including later downgrades', async () => {+ const f = await fixture();+ await f.coordinator.bootstrapElevatePeer('remote', TrustLevel.ATTESTED, 'test operator approval');+ expect((await f.coordinator.sendMessage('remote', 'task-assignment', { email: '[email protected]' })).success).toBe(true);+ expect(f.sent[0].payload).toEqual({ email: '[REDACTED:email]' });+ f.discovery.getPeer('remote')!.updateTrustLevel(TrustLevel.VERIFIED);+ expect((await f.routing.send(f.session, 'status-broadcast', { email: '[email protected]' })).success).toBe(false);+ expect(f.scans).toEqual([TrustLevel.ATTESTED, TrustLevel.VERIFIED]);+ expect(f.sent).toHaveLength(1);+ });++ it('rejects an untrusted peer after threat downgrade and a verified-manifest rejoin', async () => {+ const f = await fixture();+ f.coordinator.handleThreatDetection('remote'); f.coordinator.handleThreatDetection('remote');+ expect(f.session.active).toBe(false);+ expect(f.discovery.getPeer('remote')!.trustLevel).toBe(TrustLevel.UNTRUSTED);+ const reopened = await f.coordinator.joinPeer(f.peerManifest.endpoint, f.peerManifest);+ expect(reopened.trustLevel).toBe(TrustLevel.VERIFIED);+ const result = await f.coordinator.sendMessage('remote', 'status-broadcast', { status: 'ready' });+ expect(result.success).toBe(false);+ expect(result.error).toContain('Trust level 0');+ expect(f.sent).toHaveLength(0); expect(f.scans).toHaveLength(0);+ });++ it('uses untrusted PII policy when a custom routing adapter has no peer resolver', async () => {+ const f = await fixture(false);+ await f.coordinator.bootstrapElevatePeer('remote', TrustLevel.PRIVILEGED, 'test operator approval');+ expect((await f.routing.send(f.session, 'status-broadcast', { email: '[email protected]' })).success).toBe(false);+ expect(f.scans).toEqual([TrustLevel.UNTRUSTED]);+ expect(f.sent).toHaveLength(0);+ });++ it('uses current trust for broadcast recipients through the shared send path', async () => {+ const f = await fixture();+ await f.coordinator.bootstrapElevatePeer('remote', TrustLevel.PRIVILEGED, 'test operator approval');+ expect((await f.routing.broadcast('status-broadcast', { email: '[email protected]' }))[0].success).toBe(true);+ expect(f.scans).toEqual([TrustLevel.PRIVILEGED]);+ expect(f.sent[0].payload).toEqual({ email: '[email protected]' });+ });++ it('fails closed if an active session has no current discovery peer', async () => {+ const f = await fixture();+ f.discovery.removePeer('remote');+ expect((await f.coordinator.sendMessage('remote', 'status-broadcast', { status: 'ready' })).success).toBe(false);+ expect(f.sent).toHaveLength(0);+ expect((await f.routing.send(f.session, 'status-broadcast', { email: '[email protected]' })).success).toBe(false);+ expect(f.scans).toEqual([TrustLevel.UNTRUSTED]);+ });+});diff --git a/v3/@claude-flow/plugin-agent-federation/src/application/federation-coordinator.ts b/v3/@claude-flow/plugin-agent-federation/src/application/federation-coordinator.tsindex 08a5d1b90e..0f5ce1a1b3 100644--- a/v3/@claude-flow/plugin-agent-federation/src/application/federation-coordinator.ts+++ b/v3/@claude-flow/plugin-agent-federation/src/application/federation-coordinator.ts@@ -281,7 +281,7 @@ export class FederationCoordinator {const policyResult = this.policyEngine.evaluateMessage(messageType,- session.trustLevel,+ peer?.trustLevel ?? TrustLevel.UNTRUSTED,JSON.stringify(payload).length,this.config.nodeId,);diff --git a/v3/@claude-flow/plugin-agent-federation/src/domain/services/routing-service.ts b/v3/@claude-flow/plugin-agent-federation/src/domain/services/routing-service.tsindex ac19acf975..328966fab2 100644--- a/v3/@claude-flow/plugin-agent-federation/src/domain/services/routing-service.ts+++ b/v3/@claude-flow/plugin-agent-federation/src/domain/services/routing-service.ts@@ -5,6 +5,7 @@ import {CONSENSUS_REQUIRED_TYPES,} from '../entities/federation-envelope.js';import { FederationSession } from '../entities/federation-session.js';+import { TrustLevel } from '../entities/trust-level.js';export type RoutingMode = 'direct' | 'broadcast' | 'consensus';@@ -37,6 +38,8 @@ export interface RoutingServiceDeps {sendToNode: (nodeId: string, envelope: FederationEnvelope) => Promise<void>;getActiveSessions: () => FederationSession[];getLocalNodeId: () => string;+ /** Current peer authority; absent peers/resolvers receive the untrusted PII policy. */+ getPeerTrustLevel?: (nodeId: string) => TrustLevel | undefined;}export class RoutingService {@@ -74,7 +77,9 @@ export class RoutingService {}const payloadStr = JSON.stringify(payload);- const { transformedText, scanResult } = this.deps.scanPii(payloadStr, session.trustLevel);+ // Session trust records handshake admission; peer trust can change after it opens.+ const trustLevel = this.deps.getPeerTrustLevel?.(session.remoteNodeId) ?? TrustLevel.UNTRUSTED;+ const { transformedText, scanResult } = this.deps.scanPii(payloadStr, trustLevel);if (scanResult.piiFound && scanResult.actionsApplied.includes('block')) {return { success: false, mode: 'direct', envelopeId: '', targetNodeIds: [session.remoteNodeId], error: 'Message blocked by PII policy' };}diff --git a/v3/@claude-flow/plugin-agent-federation/src/plugin.ts b/v3/@claude-flow/plugin-agent-federation/src/plugin.tsindex a70a4635e4..a1ad04f837 100644--- a/v3/@claude-flow/plugin-agent-federation/src/plugin.ts+++ b/v3/@claude-flow/plugin-agent-federation/src/plugin.ts@@ -403,6 +403,7 @@ export class AgentFederationPlugin implements ClaudeFlowPlugin {`Federation send → ${address} (envelope=${envelope.envelopeId}, type=${envelope.messageType}, signed)`,);},+ getPeerTrustLevel: (targetNodeId) => discovery.getPeer(targetNodeId)?.trustLevel,getActiveSessions: () => Array.from(sessions.values()).filter(s => s.active),getLocalNodeId: () => nodeId,});