@claude-flow/cli 3.66.1 → 3.67.0
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/.claude/helpers/helpers.manifest.json +2 -2
- package/catalog-manifest.json +2 -2
- package/dist/src/init/executor.js +1 -1
- package/dist/src/mcp-tools/neural-tools.js +3 -1
- package/dist/src/mcp-tools/terminal-tools.js +3 -2
- package/dist/src/services/agentic-flow-bridge.d.ts +1 -1
- package/dist/src/update/validator.js +1 -1
- package/node_modules/@claude-flow/codex/dist/cli.js +0 -0
- package/node_modules/@claude-flow/mcp/dist/transport/guard.d.ts +10 -0
- package/node_modules/@claude-flow/mcp/dist/transport/guard.d.ts.map +1 -1
- package/node_modules/@claude-flow/mcp/dist/transport/guard.js +17 -0
- package/node_modules/@claude-flow/mcp/dist/transport/guard.js.map +1 -1
- package/node_modules/@claude-flow/mcp/dist/transport/http.d.ts.map +1 -1
- package/node_modules/@claude-flow/mcp/dist/transport/http.js +4 -8
- package/node_modules/@claude-flow/mcp/dist/transport/http.js.map +1 -1
- package/node_modules/@claude-flow/mcp/dist/transport/websocket.d.ts.map +1 -1
- package/node_modules/@claude-flow/mcp/dist/transport/websocket.js +2 -3
- package/node_modules/@claude-flow/mcp/dist/transport/websocket.js.map +1 -1
- package/node_modules/@claude-flow/mcp/package.json +1 -1
- package/node_modules/@claude-flow/plugin-agent-federation/dist/a2a/agent-card.d.ts +130 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/a2a/consume.d.ts +34 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/a2a/planner-descriptor.d.ts +40 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/a2a/well-known.d.ts +46 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/application/claim-checker.d.ts +27 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/application/federation-breaker-service.d.ts +192 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/application/federation-coordinator.d.ts +211 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/application/inbound-dispatcher.d.ts +113 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/application/policy-engine.d.ts +41 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/application/spend-reporter.d.ts +150 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/application/trust-evaluator.d.ts +74 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/bin.d.ts +13 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/bin.js +0 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/cli-commands.d.ts +7 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/entities/federation-envelope.d.ts +45 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/entities/federation-node.d.ts +104 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/entities/federation-session.d.ts +55 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/entities/trust-level.d.ts +17 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/audit-service.d.ts +69 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/discovery-service.d.ts +76 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/handshake-service.d.ts +62 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/pii-pipeline-service.d.ts +65 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/routing-service.d.ts +54 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/wg-firewall-service.d.ts +71 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/wg-mesh-service.d.ts +156 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/wg-witness-service.d.ts +98 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/value-objects/federation-budget.d.ts +89 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/value-objects/federation-node-state.d.ts +92 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/value-objects/wg-config.d.ts +70 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/index.d.ts +24 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/mcp-tools.d.ts +10 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/plugin.d.ts +19 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/transport/midstream-aware-loader.d.ts +72 -0
- package/node_modules/@claude-flow/plugin-agent-federation/dist/version.d.ts +3 -0
- package/node_modules/@claude-flow/security/dist/input-validator.d.ts.map +1 -1
- package/node_modules/@claude-flow/security/dist/input-validator.js +10 -5
- package/node_modules/@claude-flow/security/dist/input-validator.js.map +1 -1
- package/node_modules/@claude-flow/security/dist/token-generator.d.ts.map +1 -1
- package/node_modules/@claude-flow/security/dist/token-generator.js +4 -3
- package/node_modules/@claude-flow/security/dist/token-generator.js.map +1 -1
- package/node_modules/@claude-flow/security/package.json +1 -1
- package/package.json +8 -8
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { FederationNode } from '../entities/federation-node.js';
|
|
2
|
+
import { FederationSession } from '../entities/federation-session.js';
|
|
3
|
+
export interface HandshakeChallenge {
|
|
4
|
+
readonly challengeId: string;
|
|
5
|
+
readonly nonce: string;
|
|
6
|
+
readonly timestamp: string;
|
|
7
|
+
readonly sourceNodeId: string;
|
|
8
|
+
readonly targetNodeId: string;
|
|
9
|
+
}
|
|
10
|
+
export interface HandshakeChallengeResponse {
|
|
11
|
+
readonly challengeId: string;
|
|
12
|
+
readonly signedNonce: string;
|
|
13
|
+
readonly publicKey: string;
|
|
14
|
+
readonly capabilities: readonly string[];
|
|
15
|
+
}
|
|
16
|
+
export interface HandshakeResult {
|
|
17
|
+
readonly success: boolean;
|
|
18
|
+
readonly session?: FederationSession;
|
|
19
|
+
readonly error?: string;
|
|
20
|
+
/** The peer answered with the key pinned for its node id. False means the key was only claimed. */
|
|
21
|
+
readonly pinned?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface HandshakeServiceDeps {
|
|
24
|
+
generateSessionId: () => string;
|
|
25
|
+
generateSessionToken: () => string;
|
|
26
|
+
generateNonce: () => string;
|
|
27
|
+
signChallenge: (nonce: string) => Promise<string>;
|
|
28
|
+
verifySignature: (nonce: string, signature: string, publicKey: string) => Promise<boolean>;
|
|
29
|
+
/** The Ed25519 key (hex) the operator pinned for a node id. Without a pin, a handshake proves nothing about who answered. */
|
|
30
|
+
pinnedKeyFor?: (nodeId: string) => string | undefined;
|
|
31
|
+
getLocalNodeId: () => string;
|
|
32
|
+
getLocalPublicKey: () => string;
|
|
33
|
+
getLocalCapabilities: () => readonly string[];
|
|
34
|
+
}
|
|
35
|
+
export interface HandshakeConfig {
|
|
36
|
+
readonly sessionTtlMs: number;
|
|
37
|
+
readonly maxSessionTtlMs: number;
|
|
38
|
+
readonly heartbeatIntervalMs: number;
|
|
39
|
+
readonly challengeTimeoutMs: number;
|
|
40
|
+
}
|
|
41
|
+
export declare class HandshakeService {
|
|
42
|
+
private readonly deps;
|
|
43
|
+
private readonly config;
|
|
44
|
+
private readonly pendingChallenges;
|
|
45
|
+
constructor(deps: HandshakeServiceDeps, config?: Partial<HandshakeConfig>);
|
|
46
|
+
initiateHandshake(remoteNode: FederationNode): Promise<HandshakeChallenge>;
|
|
47
|
+
respondToHandshake(challenge: HandshakeChallenge): Promise<HandshakeChallengeResponse>;
|
|
48
|
+
verifyChallenge(response: HandshakeChallengeResponse, remoteNode: FederationNode): Promise<HandshakeResult>;
|
|
49
|
+
/**
|
|
50
|
+
* Establish a capability-limited session from discovery evidence.
|
|
51
|
+
*
|
|
52
|
+
* A signed manifest proves that the advertised key bound the protocol list;
|
|
53
|
+
* it does not prove live challenge response, so this path never elevates
|
|
54
|
+
* beyond VERIFIED. Endpoint-only peers remain UNTRUSTED with no negotiated
|
|
55
|
+
* optional capabilities. A future wire handshake may elevate either session
|
|
56
|
+
* after authenticating a response received from the remote process.
|
|
57
|
+
*/
|
|
58
|
+
establishDiscoverySession(remoteNode: FederationNode, verifiedManifest: boolean): FederationSession;
|
|
59
|
+
renewSession(session: FederationSession): FederationSession;
|
|
60
|
+
private cleanExpiredChallenges;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=handshake-service.d.ts.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { TrustLevel } from '../entities/trust-level.js';
|
|
2
|
+
export type PIIType = 'email' | 'ssn' | 'credit_card' | 'api_key' | 'password' | 'name' | 'address' | 'phone' | 'ip_address' | 'jwt' | 'aws_key' | 'private_key' | 'database_url' | 'github_token';
|
|
3
|
+
export type PIIAction = 'block' | 'redact' | 'hash' | 'pass';
|
|
4
|
+
export interface PIIDetection {
|
|
5
|
+
readonly type: PIIType;
|
|
6
|
+
readonly value: string;
|
|
7
|
+
readonly confidence: number;
|
|
8
|
+
readonly offset: number;
|
|
9
|
+
readonly context: string;
|
|
10
|
+
}
|
|
11
|
+
export interface PIIPolicyConfig {
|
|
12
|
+
defaultAction: PIIAction;
|
|
13
|
+
overrides: Partial<Record<PIIType, {
|
|
14
|
+
action: PIIAction;
|
|
15
|
+
trustLevelOverride?: Partial<Record<TrustLevel, PIIAction>>;
|
|
16
|
+
}>>;
|
|
17
|
+
hashAlgorithm: 'sha256' | 'blake3';
|
|
18
|
+
hashSalt: string;
|
|
19
|
+
redactionPlaceholder: string;
|
|
20
|
+
}
|
|
21
|
+
export interface PIICalibration {
|
|
22
|
+
type: PIIType;
|
|
23
|
+
falsePositiveRate: number;
|
|
24
|
+
falseNegativeRate: number;
|
|
25
|
+
adjustedThreshold: number;
|
|
26
|
+
totalOverrides: number;
|
|
27
|
+
lastCalibrated: string;
|
|
28
|
+
}
|
|
29
|
+
export interface PIITransformResult {
|
|
30
|
+
readonly originalText: string;
|
|
31
|
+
readonly transformedText: string;
|
|
32
|
+
readonly detections: readonly PIIDetection[];
|
|
33
|
+
readonly actionsApplied: readonly {
|
|
34
|
+
type: PIIType;
|
|
35
|
+
action: PIIAction;
|
|
36
|
+
}[];
|
|
37
|
+
readonly blocked: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface PIIConfidenceThresholds {
|
|
40
|
+
autoBlock: number;
|
|
41
|
+
autoRedact: number;
|
|
42
|
+
flagForReview: number;
|
|
43
|
+
ignore: number;
|
|
44
|
+
}
|
|
45
|
+
export interface PIIPipelineServiceDeps {
|
|
46
|
+
hashFunction: (value: string, salt: string) => string;
|
|
47
|
+
}
|
|
48
|
+
export declare class PIIPipelineService {
|
|
49
|
+
private readonly deps;
|
|
50
|
+
private readonly policy;
|
|
51
|
+
private readonly calibrations;
|
|
52
|
+
private readonly confidenceThresholds;
|
|
53
|
+
constructor(deps: PIIPipelineServiceDeps, policy?: Partial<PIIPolicyConfig>, confidenceThresholds?: Partial<PIIConfidenceThresholds>);
|
|
54
|
+
detect(text: string): PIIDetection[];
|
|
55
|
+
classify(detections: PIIDetection[]): Map<PIIType, PIIDetection[]>;
|
|
56
|
+
evaluate(detection: PIIDetection, trustLevel: TrustLevel): PIIAction;
|
|
57
|
+
transform(text: string, trustLevel: TrustLevel): PIITransformResult;
|
|
58
|
+
updateCalibration(type: PIIType, calibration: PIICalibration): void;
|
|
59
|
+
getCalibration(type: PIIType): PIICalibration | undefined;
|
|
60
|
+
private computeConfidence;
|
|
61
|
+
private getEffectiveThreshold;
|
|
62
|
+
static defaultPolicy(): PIIPolicyConfig;
|
|
63
|
+
static defaultPolicyMatrix(): Record<PIIType, Record<TrustLevel, PIIAction>>;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=pii-pipeline-service.d.ts.map
|
package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/routing-service.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { FederationEnvelope, type FederationEnvelopeProps, type FederationMessageType } from '../entities/federation-envelope.js';
|
|
2
|
+
import { FederationSession } from '../entities/federation-session.js';
|
|
3
|
+
import { TrustLevel } from '../entities/trust-level.js';
|
|
4
|
+
export type RoutingMode = 'direct' | 'broadcast' | 'consensus';
|
|
5
|
+
export interface RoutingResult {
|
|
6
|
+
readonly success: boolean;
|
|
7
|
+
readonly mode: RoutingMode;
|
|
8
|
+
readonly envelopeId: string;
|
|
9
|
+
readonly targetNodeIds: readonly string[];
|
|
10
|
+
readonly error?: string;
|
|
11
|
+
readonly latencyMs?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface ConsensusProposal {
|
|
14
|
+
readonly proposalId: string;
|
|
15
|
+
readonly proposerNodeId: string;
|
|
16
|
+
readonly messageType: FederationMessageType;
|
|
17
|
+
readonly payload: unknown;
|
|
18
|
+
readonly quorumRequired: number;
|
|
19
|
+
readonly votes: Map<string, boolean>;
|
|
20
|
+
readonly createdAt: Date;
|
|
21
|
+
readonly expiresAt: Date;
|
|
22
|
+
}
|
|
23
|
+
export interface RoutingServiceDeps {
|
|
24
|
+
generateEnvelopeId: () => string;
|
|
25
|
+
generateNonce: () => string;
|
|
26
|
+
signEnvelope: (payload: string, sessionToken: string) => string;
|
|
27
|
+
verifyEnvelope: (payload: string, signature: string, sessionToken: string) => boolean;
|
|
28
|
+
scanPii: (text: string, trustLevel: number) => {
|
|
29
|
+
transformedText: string;
|
|
30
|
+
scanResult: FederationEnvelopeProps['piiScanResult'];
|
|
31
|
+
};
|
|
32
|
+
sendToNode: (nodeId: string, envelope: FederationEnvelope) => Promise<void>;
|
|
33
|
+
getActiveSessions: () => FederationSession[];
|
|
34
|
+
getLocalNodeId: () => string;
|
|
35
|
+
/** Current peer authority; absent peers/resolvers receive the untrusted PII policy. */
|
|
36
|
+
getPeerTrustLevel?: (nodeId: string) => TrustLevel | undefined;
|
|
37
|
+
}
|
|
38
|
+
export declare class RoutingService {
|
|
39
|
+
private readonly deps;
|
|
40
|
+
private readonly pendingProposals;
|
|
41
|
+
constructor(deps: RoutingServiceDeps);
|
|
42
|
+
selectMode(messageType: FederationMessageType): RoutingMode;
|
|
43
|
+
send<T>(session: FederationSession, messageType: FederationMessageType, payload: T): Promise<RoutingResult>;
|
|
44
|
+
broadcast<T>(messageType: FederationMessageType, payload: T): Promise<RoutingResult[]>;
|
|
45
|
+
propose<T>(messageType: FederationMessageType, payload: T, quorumFraction?: number): Promise<ConsensusProposal>;
|
|
46
|
+
recordVote(proposalId: string, nodeId: string, vote: boolean): boolean;
|
|
47
|
+
isConsensusReached(proposalId: string): {
|
|
48
|
+
reached: boolean;
|
|
49
|
+
approved: boolean;
|
|
50
|
+
};
|
|
51
|
+
verifyInboundEnvelope(envelope: FederationEnvelope, sessionToken: string): boolean;
|
|
52
|
+
cleanExpiredProposals(): void;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=routing-service.d.ts.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ADR-111 Phase 4 — Trust-graded firewall projection.
|
|
3
|
+
*
|
|
4
|
+
* Projects the WG_NETWORK_GATES table (defined in wg-mesh-service.ts) into
|
|
5
|
+
* concrete kernel-firewall rules. Two backends:
|
|
6
|
+
*
|
|
7
|
+
* - `nftables` for Linux — atomic `nft -f <file>` loader, family `inet`,
|
|
8
|
+
* hook `input` (interface-scoped to the WG iface).
|
|
9
|
+
* - `pf` for macOS — `pfctl -a ruflo-fed -f <file>`, anchor-scoped so
|
|
10
|
+
* ruflo's rules don't collide with the operator's main pf ruleset.
|
|
11
|
+
*
|
|
12
|
+
* Like Phase 2's WgMeshService this is a **pure-projection** service: it
|
|
13
|
+
* returns rule strings + the shell command the operator runs. It never
|
|
14
|
+
* shells out or modifies kernel state itself. Operator review is mandatory
|
|
15
|
+
* because `pf` / `nft` reloads atomically replace the active ruleset for
|
|
16
|
+
* the targeted scope — a typo here can drop ssh.
|
|
17
|
+
*
|
|
18
|
+
* v1 scope: the four trust levels VERIFIED/ATTESTED/TRUSTED/PRIVILEGED.
|
|
19
|
+
* UNTRUSTED peers are never in the mesh (excluded by WgMeshService) so
|
|
20
|
+
* they don't need a firewall rule either — implicit drop policy.
|
|
21
|
+
*/
|
|
22
|
+
import { FederationNode } from '../entities/federation-node.js';
|
|
23
|
+
export type WgFirewallPlatform = 'linux-nftables' | 'darwin-pf';
|
|
24
|
+
export interface WgFirewallServiceConfig {
|
|
25
|
+
/** Target platform. Default: auto-detect from process.platform. */
|
|
26
|
+
readonly platform?: WgFirewallPlatform;
|
|
27
|
+
/** WG interface name to scope rules to. Defaults to `ruflo-fed`. */
|
|
28
|
+
readonly interfaceName?: string;
|
|
29
|
+
/** Where the operator should write the rule file. Used for the load-command string. */
|
|
30
|
+
readonly rulePath?: string;
|
|
31
|
+
/** pf anchor (macOS only). Defaults to `ruflo-fed`. */
|
|
32
|
+
readonly pfAnchor?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface WgFirewallRuleSet {
|
|
35
|
+
/** The full rule-file content the operator writes to disk. */
|
|
36
|
+
readonly content: string;
|
|
37
|
+
/** The shell command the operator runs to load it. */
|
|
38
|
+
readonly loadCmd: string;
|
|
39
|
+
/** Recommended file path (informational — the operator decides). */
|
|
40
|
+
readonly rulePath: string;
|
|
41
|
+
/** Per-peer rule projections for audit/inspection. */
|
|
42
|
+
readonly peerProjections: ReadonlyArray<{
|
|
43
|
+
readonly nodeId: string;
|
|
44
|
+
readonly trustLabel: string;
|
|
45
|
+
readonly meshIP: string;
|
|
46
|
+
readonly rules: readonly string[];
|
|
47
|
+
}>;
|
|
48
|
+
}
|
|
49
|
+
export declare class WgFirewallService {
|
|
50
|
+
private readonly platform;
|
|
51
|
+
private readonly interfaceName;
|
|
52
|
+
private readonly rulePath;
|
|
53
|
+
private readonly pfAnchor;
|
|
54
|
+
constructor(config?: WgFirewallServiceConfig);
|
|
55
|
+
getPlatform(): WgFirewallPlatform;
|
|
56
|
+
/**
|
|
57
|
+
* Project the current peer set into a complete rule file (nftables or pf)
|
|
58
|
+
* scoped to the WG interface.
|
|
59
|
+
*
|
|
60
|
+
* Peers below WG_MIN_MESH_TRUST (UNTRUSTED) are dropped — they have no
|
|
61
|
+
* mesh IP and shouldn't appear in firewall allow rules anyway. Peers
|
|
62
|
+
* without `metadata.wgMeshIP` are skipped (a stale manifest with no WG
|
|
63
|
+
* block; the mesh layer already excludes them).
|
|
64
|
+
*/
|
|
65
|
+
projectRules(peers: readonly FederationNode[]): WgFirewallRuleSet;
|
|
66
|
+
private renderNftables;
|
|
67
|
+
private renderPf;
|
|
68
|
+
private defaultRulePath;
|
|
69
|
+
private trustLabel;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=wg-firewall-service.d.ts.map
|
package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/wg-mesh-service.d.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ADR-111 Phase 2 — WgMeshService.
|
|
3
|
+
*
|
|
4
|
+
* Pure-projection service: takes the federation peer registry + local
|
|
5
|
+
* WG identity and produces (a) a `wg-quick`-compatible config string,
|
|
6
|
+
* (b) per-peer `wg set` commands the operator runs to converge an
|
|
7
|
+
* already-running interface, and (c) the AllowedIPs slice that maps to
|
|
8
|
+
* each peer's trust level.
|
|
9
|
+
*
|
|
10
|
+
* Deliberately does NOT shell out. Bringing up a network interface
|
|
11
|
+
* requires root and modifies system state — per CLAUDE.md's
|
|
12
|
+
* destructive-actions guidance the service emits the commands; the
|
|
13
|
+
* operator (or a thin shell wrapper they audit) runs them.
|
|
14
|
+
*
|
|
15
|
+
* Phase 3 (breaker integration) consumes this service: peer state
|
|
16
|
+
* transitions invoke removeAllowedIPs/removePeer/restoreAllowedIPs,
|
|
17
|
+
* which produce commands without side effects.
|
|
18
|
+
*/
|
|
19
|
+
import { TrustLevel } from '../entities/trust-level.js';
|
|
20
|
+
import { FederationNode } from '../entities/federation-node.js';
|
|
21
|
+
import type { WgLocalKey } from '../value-objects/wg-config.js';
|
|
22
|
+
export interface WgPortRule {
|
|
23
|
+
readonly proto: 'tcp' | 'udp' | 'all';
|
|
24
|
+
readonly port?: number;
|
|
25
|
+
readonly portRange?: readonly [number, number];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Trust-level → reachability. ADR-111's `WG_NETWORK_GATES`.
|
|
29
|
+
*
|
|
30
|
+
* Note: WireGuard's `AllowedIPs` is L3 routing, not L4 ACL — these port
|
|
31
|
+
* rules describe what the L4 firewall (Phase 4: nftables/pf) should
|
|
32
|
+
* enforce. v1 (this phase) only produces the rules; Phase 4 projects
|
|
33
|
+
* them into kernel firewall syntax. Until then, callers using v1
|
|
34
|
+
* fall back to the simpler "AllowedIPs = peer's mesh IP" model (option
|
|
35
|
+
* (b) in the ADR — app-layer auth carries the access decision).
|
|
36
|
+
*/
|
|
37
|
+
export declare const WG_NETWORK_GATES: Record<TrustLevel, readonly WgPortRule[]>;
|
|
38
|
+
/**
|
|
39
|
+
* Minimum trust level whose peers get a `[Peer]` block in the WG config.
|
|
40
|
+
* UNTRUSTED stays out of the mesh entirely — it's the explicit drop bucket.
|
|
41
|
+
*/
|
|
42
|
+
export declare const WG_MIN_MESH_TRUST: TrustLevel;
|
|
43
|
+
export interface WgPeerFields {
|
|
44
|
+
readonly wgPublicKey: string;
|
|
45
|
+
readonly wgMeshIP: string;
|
|
46
|
+
readonly wgEndpoint: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Return the validated peer wg fields, or null if any is malformed or
|
|
50
|
+
* out-of-range. Callers treat null as "peer not eligible for mesh" — the
|
|
51
|
+
* peer stays in the federation discovery registry but is excluded from
|
|
52
|
+
* the wg config and any wg commands.
|
|
53
|
+
*/
|
|
54
|
+
export declare function readSafePeerWgFields(peer: FederationNode): WgPeerFields | null;
|
|
55
|
+
export interface WgMeshServiceConfig {
|
|
56
|
+
/** Local interface name. Defaults to `ruflo-fed`. */
|
|
57
|
+
readonly interfaceName?: string;
|
|
58
|
+
/** Local UDP listen port. WireGuard's standard is 51820. */
|
|
59
|
+
readonly listenPort?: number;
|
|
60
|
+
/** Mesh subnet for AllowedIPs filtering. Defaults to DEFAULT_MESH_SUBNET. */
|
|
61
|
+
readonly meshSubnet?: string;
|
|
62
|
+
}
|
|
63
|
+
export interface WgPeerSummary {
|
|
64
|
+
readonly nodeId: string;
|
|
65
|
+
readonly trustLevel: TrustLevel;
|
|
66
|
+
readonly trustLabel: string;
|
|
67
|
+
readonly meshIP: string;
|
|
68
|
+
readonly endpoint: string;
|
|
69
|
+
readonly publicKey: string;
|
|
70
|
+
readonly state: 'active' | 'suspended' | 'evicted';
|
|
71
|
+
readonly allowedIPs: readonly string[];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* A planned `wg(8)` mutation. Service consumers either execute these or
|
|
75
|
+
* surface them to the operator. Strings are validated for shell metachars
|
|
76
|
+
* before being formatted into a command — callers should still review.
|
|
77
|
+
*/
|
|
78
|
+
export interface WgCommand {
|
|
79
|
+
readonly verb: 'set-allowed-ips' | 'remove-allowed-ips' | 'remove-peer' | 'add-peer';
|
|
80
|
+
/** Public key of the peer this command targets. */
|
|
81
|
+
readonly peerPublicKey: string;
|
|
82
|
+
/** Render to a `wg set <iface> peer <pk> ...` shell-ready string. */
|
|
83
|
+
readonly cmd: string;
|
|
84
|
+
/** Human-readable rationale for audit logs. */
|
|
85
|
+
readonly rationale: string;
|
|
86
|
+
}
|
|
87
|
+
export declare class WgMeshService {
|
|
88
|
+
private readonly interfaceName;
|
|
89
|
+
private readonly listenPort;
|
|
90
|
+
private readonly meshSubnet;
|
|
91
|
+
private localKey;
|
|
92
|
+
private localMeshIP;
|
|
93
|
+
/** Per-peer AllowedIPs after the last applyTrustLevelToAllowedIPs() call. Drives restore from breaker. */
|
|
94
|
+
private readonly lastAppliedAllowedIPs;
|
|
95
|
+
/** Peer-pubkey → suspended flag for breaker integration. */
|
|
96
|
+
private readonly suspended;
|
|
97
|
+
/** Peer-pubkey → evicted flag. */
|
|
98
|
+
private readonly evicted;
|
|
99
|
+
constructor(config?: WgMeshServiceConfig);
|
|
100
|
+
/** Bind the local WG identity. Required before buildInterfaceConfig(). */
|
|
101
|
+
setLocalIdentity(key: WgLocalKey, meshIP: string): void;
|
|
102
|
+
getInterfaceName(): string;
|
|
103
|
+
getMeshSubnet(): string;
|
|
104
|
+
/**
|
|
105
|
+
* Build a `wg-quick`-compatible config string from current peers.
|
|
106
|
+
*
|
|
107
|
+
* Peers below WG_MIN_MESH_TRUST (UNTRUSTED) are excluded entirely.
|
|
108
|
+
* Suspended peers stay in the config but with `AllowedIPs =` empty
|
|
109
|
+
* (soft-block). Evicted peers are dropped completely.
|
|
110
|
+
*
|
|
111
|
+
* Operator writes this to `/etc/wireguard/<interface>.conf` and runs
|
|
112
|
+
* `wg-quick up <interface>`.
|
|
113
|
+
*/
|
|
114
|
+
buildInterfaceConfig(peers: readonly FederationNode[]): string;
|
|
115
|
+
/**
|
|
116
|
+
* Compute the AllowedIPs slice for a peer at its current trust level.
|
|
117
|
+
* v1: each peer gets its own /32 mesh IP. Phase 4 will narrow this
|
|
118
|
+
* further via firewall rules; v1 keeps L3 broad and relies on the app
|
|
119
|
+
* layer + trust gates for access decisions.
|
|
120
|
+
*/
|
|
121
|
+
computeAllowedIPs(peer: FederationNode, meshIP: string): readonly string[];
|
|
122
|
+
/**
|
|
123
|
+
* Apply trust level → AllowedIPs as a `wg set` command for an
|
|
124
|
+
* already-running interface. Used when a peer joins or its trust level
|
|
125
|
+
* changes without needing a full config rewrite.
|
|
126
|
+
*/
|
|
127
|
+
applyTrustLevelToAllowedIPs(peer: FederationNode, meshIP: string, pubkey: string): WgCommand;
|
|
128
|
+
/**
|
|
129
|
+
* Phase 3 hook — peer SUSPENDED. Clear AllowedIPs (soft-block: keeps
|
|
130
|
+
* the peer's public key registered with the interface but blocks all
|
|
131
|
+
* routing to/from it).
|
|
132
|
+
*/
|
|
133
|
+
removeAllowedIPs(peer: FederationNode, pubkey: string, reason?: string): WgCommand;
|
|
134
|
+
/**
|
|
135
|
+
* Phase 3 hook — peer reactivated. Restore the AllowedIPs slice that
|
|
136
|
+
* was active before suspension. Returns null if the peer was never
|
|
137
|
+
* suspended (idempotent).
|
|
138
|
+
*/
|
|
139
|
+
restoreAllowedIPs(peer: FederationNode, meshIP: string, pubkey: string): WgCommand | null;
|
|
140
|
+
/**
|
|
141
|
+
* Phase 3 hook — peer EVICTED. Terminal removal from the mesh; the
|
|
142
|
+
* peer's `[Peer]` block is dropped on next config rebuild and an
|
|
143
|
+
* immediate `wg set <iface> peer <pk> remove` is emitted to flush
|
|
144
|
+
* runtime state without a config reload.
|
|
145
|
+
*/
|
|
146
|
+
removePeer(peer: FederationNode, pubkey: string, reason?: string): WgCommand;
|
|
147
|
+
/** Summarize the mesh state for `federation_wg_status` (Phase 6) and audit. */
|
|
148
|
+
summarize(peers: readonly FederationNode[]): readonly WgPeerSummary[];
|
|
149
|
+
/**
|
|
150
|
+
* Defense-in-depth: validate that all bits we splice into a shell
|
|
151
|
+
* command are alphanumeric / base64 / WG-allowed chars. Refuses the
|
|
152
|
+
* command rather than ship a substring that might escape its slot.
|
|
153
|
+
*/
|
|
154
|
+
private formatCmd;
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=wg-mesh-service.d.ts.map
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ADR-111 Phase 5 — Witness attestation chain for WG mesh mutations.
|
|
3
|
+
*
|
|
4
|
+
* Every coordination change (peer added/suspended/evicted/reactivated,
|
|
5
|
+
* keypair rotated) appends a signed entry to an append-only log
|
|
6
|
+
* `.claude-flow/federation/wg-changes.log`. The signature is over a
|
|
7
|
+
* canonical JSON encoding of the entry's content fields, using the
|
|
8
|
+
* operator's federation Ed25519 key — the same identity that signs
|
|
9
|
+
* federation manifests, so anyone who already trusts the manifest chain
|
|
10
|
+
* automatically trusts the WG change chain.
|
|
11
|
+
*
|
|
12
|
+
* Append-only via O_APPEND open + entries chained by prevHash (sha256 of
|
|
13
|
+
* the previous entry's canonical bytes). Tampering with history requires
|
|
14
|
+
* forging a chain of signatures with the operator's key.
|
|
15
|
+
*
|
|
16
|
+
* The periodic ruflo witness regen (plugins/ruflo-core/scripts/witness/)
|
|
17
|
+
* includes wg-changes.log as one of its watched artifacts (operator wires
|
|
18
|
+
* this via witness-fixes.json).
|
|
19
|
+
*
|
|
20
|
+
* Pure service: emits the canonical bytes and the signature to write.
|
|
21
|
+
* Caller does the I/O so this stays unit-testable without fs mocks.
|
|
22
|
+
*/
|
|
23
|
+
import type { WgCommand } from './wg-mesh-service.js';
|
|
24
|
+
export type WgWitnessEventType = 'peer-added' | 'peer-removed-suspended' | 'peer-restored' | 'peer-evicted' | 'key-rotated' | 'interface-config-applied';
|
|
25
|
+
/**
|
|
26
|
+
* Canonical fields of a witness entry. The hash + signature are computed
|
|
27
|
+
* over these in a stable JSON encoding (sorted keys, no whitespace).
|
|
28
|
+
*/
|
|
29
|
+
export interface WgWitnessContent {
|
|
30
|
+
readonly version: '1';
|
|
31
|
+
readonly type: WgWitnessEventType;
|
|
32
|
+
readonly timestamp: string;
|
|
33
|
+
readonly nodeId: string;
|
|
34
|
+
/** Public key of the affected peer, if any. */
|
|
35
|
+
readonly peerPublicKey?: string;
|
|
36
|
+
/** Mesh IP affected, if any. */
|
|
37
|
+
readonly meshIP?: string;
|
|
38
|
+
/** wg command that was emitted, if any. */
|
|
39
|
+
readonly wgCommand?: string;
|
|
40
|
+
/** Human-readable rationale for the audit log. */
|
|
41
|
+
readonly rationale: string;
|
|
42
|
+
/** Hash of the previous entry in the chain (sha256 hex), or empty for the genesis entry. */
|
|
43
|
+
readonly prevHash: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Full witness entry as it appears on disk — content + the operator's
|
|
47
|
+
* Ed25519 signature over the canonical encoding of content.
|
|
48
|
+
*/
|
|
49
|
+
export interface WgWitnessEntry {
|
|
50
|
+
readonly content: WgWitnessContent;
|
|
51
|
+
readonly hash: string;
|
|
52
|
+
readonly signature: string;
|
|
53
|
+
}
|
|
54
|
+
export interface WgWitnessSigner {
|
|
55
|
+
/** Returns an Ed25519 signature (base64) over the given canonical bytes. */
|
|
56
|
+
sign(bytes: Buffer): Promise<string>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Stable JSON serialization for hashing/signing. Keys are sorted; no
|
|
60
|
+
* whitespace; undefined fields omitted. Same shape on every host so
|
|
61
|
+
* cross-host verifiers produce identical hashes.
|
|
62
|
+
*/
|
|
63
|
+
export declare function canonicalizeContent(content: WgWitnessContent): Buffer;
|
|
64
|
+
export declare function hashContent(content: WgWitnessContent): string;
|
|
65
|
+
export declare class WgWitnessService {
|
|
66
|
+
private readonly nodeId;
|
|
67
|
+
private readonly signer;
|
|
68
|
+
private lastHash;
|
|
69
|
+
constructor(nodeId: string, signer: WgWitnessSigner);
|
|
70
|
+
/**
|
|
71
|
+
* Override the previous-hash pointer (used when resuming from an existing
|
|
72
|
+
* log on disk). Caller reads the last entry from `wg-changes.log` and
|
|
73
|
+
* passes its `hash` here before appending more.
|
|
74
|
+
*/
|
|
75
|
+
setLastHash(hash: string): void;
|
|
76
|
+
/** Build + sign an entry. Caller is responsible for the actual append-write. */
|
|
77
|
+
build(type: WgWitnessEventType, fields: Omit<WgWitnessContent, 'version' | 'type' | 'timestamp' | 'nodeId' | 'prevHash'>): Promise<WgWitnessEntry>;
|
|
78
|
+
/**
|
|
79
|
+
* Convenience: take a WgCommand emitted by WgMeshService Phase 2/3 and
|
|
80
|
+
* produce a witness entry of the right type. Maps verb → eventType.
|
|
81
|
+
*/
|
|
82
|
+
attestWgCommand(cmd: WgCommand, meshIP?: string): Promise<WgWitnessEntry>;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Verify a single entry's signature + hash. Caller verifies the chain by
|
|
86
|
+
* iterating entries and confirming each entry's `prevHash` equals the
|
|
87
|
+
* preceding entry's `hash`.
|
|
88
|
+
*/
|
|
89
|
+
export declare function verifyWitnessEntry(entry: WgWitnessEntry, verify: (bytes: Buffer, signature: string) => Promise<boolean>): Promise<boolean>;
|
|
90
|
+
/**
|
|
91
|
+
* Verify a full chain — every entry valid + chain link unbroken.
|
|
92
|
+
*/
|
|
93
|
+
export declare function verifyWitnessChain(entries: readonly WgWitnessEntry[], verify: (bytes: Buffer, signature: string) => Promise<boolean>): Promise<{
|
|
94
|
+
ok: boolean;
|
|
95
|
+
failedAt?: number;
|
|
96
|
+
reason?: string;
|
|
97
|
+
}>;
|
|
98
|
+
//# sourceMappingURL=wg-witness-service.d.ts.map
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Federation budget + hop counter (ADR-097 Phase 1).
|
|
3
|
+
*
|
|
4
|
+
* Carried in {@link FederationEnvelope} alongside the existing
|
|
5
|
+
* sourceNodeId/targetNodeId/payload. Sender supplies the original limits;
|
|
6
|
+
* each outbound hop increments hopCount and decrements remaining budget.
|
|
7
|
+
*
|
|
8
|
+
* Phase 1 enforces at the *send* side because there is no inbound
|
|
9
|
+
* dispatcher today (sendToNode is a stub — see researcher report).
|
|
10
|
+
* Phase 2 will move the decrement to receive once the inbound path lands.
|
|
11
|
+
*
|
|
12
|
+
* Security invariants pinned by the reviewer (audit_1776853149979 follow-up):
|
|
13
|
+
*
|
|
14
|
+
* 1. validateBudget rejects NaN, ±Infinity, negative numbers, and
|
|
15
|
+
* non-integer hop counts. Returns a discriminated result so callers
|
|
16
|
+
* cannot accidentally use a bad budget unchecked.
|
|
17
|
+
* 2. enforceBudget runs check-then-decrement in a single synchronous
|
|
18
|
+
* function with no awaits inside — two concurrent send calls cannot
|
|
19
|
+
* both pass the pre-check.
|
|
20
|
+
* 3. Errors return constant strings ("HOP_LIMIT_EXCEEDED" /
|
|
21
|
+
* "BUDGET_EXCEEDED") with no remaining-budget echo so a caller can't
|
|
22
|
+
* use the error response as an oracle for the threshold.
|
|
23
|
+
*/
|
|
24
|
+
/** Maximum hops a federation message may travel before the breaker opens. */
|
|
25
|
+
export declare const DEFAULT_MAX_HOPS = 8;
|
|
26
|
+
/**
|
|
27
|
+
* Caller-supplied budget. All fields are optional; omitted fields are
|
|
28
|
+
* treated as Infinity for the corresponding axis. Created via validateBudget;
|
|
29
|
+
* never construct directly.
|
|
30
|
+
*/
|
|
31
|
+
export interface Budget {
|
|
32
|
+
readonly maxHops: number;
|
|
33
|
+
readonly maxTokens: number;
|
|
34
|
+
readonly maxUsd: number;
|
|
35
|
+
}
|
|
36
|
+
/** Discriminated result of validating raw user input into a Budget. */
|
|
37
|
+
export type BudgetValidationResult = {
|
|
38
|
+
ok: true;
|
|
39
|
+
budget: Budget;
|
|
40
|
+
} | {
|
|
41
|
+
ok: false;
|
|
42
|
+
error: string;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Validate a raw budget object. Pure, no side effects. Caller obtains either
|
|
46
|
+
* a guaranteed-safe Budget or a structured error suitable for logging.
|
|
47
|
+
*
|
|
48
|
+
* Accepts undefined/null and returns a default unbounded budget (maxHops =
|
|
49
|
+
* DEFAULT_MAX_HOPS, tokens/usd = Infinity). This preserves backward
|
|
50
|
+
* compatibility for callers that don't pass a budget at all.
|
|
51
|
+
*/
|
|
52
|
+
export declare function validateBudget(raw: unknown, overrideMaxHops?: unknown): BudgetValidationResult;
|
|
53
|
+
/**
|
|
54
|
+
* Enforcement decision returned by enforceBudget. Discriminated so the
|
|
55
|
+
* caller can map directly to a constant-string error — no remaining-budget
|
|
56
|
+
* echo on the failure side (anti-oracle).
|
|
57
|
+
*/
|
|
58
|
+
export type BudgetEnforcement = {
|
|
59
|
+
ok: true;
|
|
60
|
+
nextHopCount: number;
|
|
61
|
+
remaining: Budget;
|
|
62
|
+
} | {
|
|
63
|
+
ok: false;
|
|
64
|
+
reason: 'HOP_LIMIT_EXCEEDED' | 'BUDGET_EXCEEDED';
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Atomic (single synchronous function, no internal awaits) hop check.
|
|
68
|
+
*
|
|
69
|
+
* Returns the hopCount value the OUTBOUND envelope should carry plus the
|
|
70
|
+
* remaining budget that downstream peers will see. Callers must use the
|
|
71
|
+
* returned values; mutating the input Budget is forbidden (it's readonly).
|
|
72
|
+
*
|
|
73
|
+
* Contract:
|
|
74
|
+
* - hopCount represents how many hops the message has already taken.
|
|
75
|
+
* - The next outbound hop increments it: nextHopCount = hopCount + 1.
|
|
76
|
+
* - The check fires AFTER increment: nextHopCount must be <= maxHops.
|
|
77
|
+
* - This means maxHops=0 refuses to forward at all, which matches the
|
|
78
|
+
* ADR's "no remote delegation allowed" semantic.
|
|
79
|
+
*
|
|
80
|
+
* tokensSpent / usdSpent are caller-reported actuals from the immediately
|
|
81
|
+
* preceding leg (or 0 on the originator). The check fires on the
|
|
82
|
+
* *post-spend* totals so a leg that overshoots is caught before the next
|
|
83
|
+
* outbound dispatch.
|
|
84
|
+
*/
|
|
85
|
+
export declare function enforceBudget(budget: Budget, hopCount: number, spent?: {
|
|
86
|
+
tokens: number;
|
|
87
|
+
usd: number;
|
|
88
|
+
}): BudgetEnforcement;
|
|
89
|
+
//# sourceMappingURL=federation-budget.d.ts.map
|