@claude-flow/plugin-agent-federation 1.0.0-alpha.14 → 1.0.0-alpha.16

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.
Files changed (29) hide show
  1. package/README.md +4 -0
  2. package/dist/application/federation-coordinator.d.ts +8 -1
  3. package/dist/application/federation-coordinator.d.ts.map +1 -1
  4. package/dist/application/federation-coordinator.js +9 -0
  5. package/dist/application/federation-coordinator.js.map +1 -1
  6. package/dist/domain/services/wg-firewall-service.d.ts +71 -0
  7. package/dist/domain/services/wg-firewall-service.d.ts.map +1 -0
  8. package/dist/domain/services/wg-firewall-service.js +194 -0
  9. package/dist/domain/services/wg-firewall-service.js.map +1 -0
  10. package/dist/domain/services/wg-mesh-service.d.ts +12 -0
  11. package/dist/domain/services/wg-mesh-service.d.ts.map +1 -1
  12. package/dist/domain/services/wg-mesh-service.js +63 -15
  13. package/dist/domain/services/wg-mesh-service.js.map +1 -1
  14. package/dist/domain/services/wg-witness-service.d.ts +98 -0
  15. package/dist/domain/services/wg-witness-service.d.ts.map +1 -0
  16. package/dist/domain/services/wg-witness-service.js +122 -0
  17. package/dist/domain/services/wg-witness-service.js.map +1 -0
  18. package/dist/mcp-tools.d.ts +3 -1
  19. package/dist/mcp-tools.d.ts.map +1 -1
  20. package/dist/mcp-tools.js +91 -1
  21. package/dist/mcp-tools.js.map +1 -1
  22. package/dist/plugin.d.ts.map +1 -1
  23. package/dist/plugin.js +19 -7
  24. package/dist/plugin.js.map +1 -1
  25. package/dist/transport/midstream-aware-loader.d.ts +53 -0
  26. package/dist/transport/midstream-aware-loader.d.ts.map +1 -0
  27. package/dist/transport/midstream-aware-loader.js +167 -0
  28. package/dist/transport/midstream-aware-loader.js.map +1 -0
  29. package/package.json +15 -3
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Midstream-aware federation transport loader (ADR-120, Step 2).
3
+ *
4
+ * Extends the agentic-flow `loadQuicTransport` loader pattern with a
5
+ * preferred branch that probes `midstreamer` first. When `midstreamer`
6
+ * ships real QUIC (currently the WASM build is a counter-tracking
7
+ * stub per ADR-119), this loader picks it up automatically without
8
+ * any change to consumer plugins.
9
+ *
10
+ * Resolution order:
11
+ *
12
+ * 1. If `MIDSTREAMER_QUIC_NATIVE=1` AND the `midstreamer` module
13
+ * exposes a real `QuicMultistream`-derived `AgentTransport`,
14
+ * use it. (Today: probes fail closed and we fall through.)
15
+ *
16
+ * 2. Otherwise: defer to agentic-flow's existing loader, which
17
+ * itself respects `AGENTIC_FLOW_QUIC_NATIVE=1` (ADR-108) and
18
+ * falls back to WebSocket (ADR-104) otherwise.
19
+ *
20
+ * The loader is opt-in: callers must explicitly invoke
21
+ * `loadFederationTransport()` instead of `loadQuicTransport()`.
22
+ * Behavior is identical to `loadQuicTransport()` until upstream
23
+ * `midstreamer` ships its real QUIC build AND the operator sets the
24
+ * env flag — so this change is safe to land before any of that
25
+ * happens.
26
+ *
27
+ * Re-exports the `AgentTransport` / `AgentMessage` / `QuicTransportConfig`
28
+ * surface from agentic-flow so consumers only import from one place.
29
+ */
30
+ /**
31
+ * Lazy loader for agentic-flow's `loadQuicTransport`. Returns `null`
32
+ * when `agentic-flow` is not installed — callers must then fall back
33
+ * to the midstream-first path or surface a clear error.
34
+ *
35
+ * Per ADR-120 + issue #1949, `agentic-flow` is now an **optional**
36
+ * peer dependency. Operators who only want the midstream-native
37
+ * transport (via `MIDSTREAMER_QUIC_NATIVE=1`) can omit it to avoid
38
+ * the deep `koa-router` → `cookies@0.9.1` transitive chain that
39
+ * hardened npm registries reject.
40
+ */
41
+ async function loadAgenticFlowQuicTransport(config) {
42
+ // Direct dynamic `import()` (not the `new Function` trick) so
43
+ // test frameworks like vitest can intercept via `vi.mock`. The
44
+ // try/catch makes the module-not-found case a clean `null` so the
45
+ // caller falls back gracefully — agentic-flow is now an optional
46
+ // peer dependency.
47
+ let mod;
48
+ try {
49
+ mod = (await import('agentic-flow/transport/loader'));
50
+ }
51
+ catch {
52
+ return null;
53
+ }
54
+ const fn = typeof mod.loadQuicTransport === 'function'
55
+ ? mod.loadQuicTransport
56
+ : mod.default?.loadQuicTransport;
57
+ if (typeof fn !== 'function') {
58
+ return null;
59
+ }
60
+ try {
61
+ return await fn(config);
62
+ }
63
+ catch {
64
+ return null;
65
+ }
66
+ }
67
+ /**
68
+ * Probe the `midstreamer` npm package for a real QUIC transport.
69
+ * Returns `null` when the env flag is off, when the package isn't
70
+ * installed, when the import surface doesn't match expectations, or
71
+ * when the loaded module is detectably the WASM stub (per ADR-119
72
+ * the current shipped build is a counter-tracking stub — `isNative()`
73
+ * or `isStub()` probes are checked when available).
74
+ *
75
+ * The function never throws — any failure becomes `null` so the
76
+ * outer `loadFederationTransport` can transparently fall back.
77
+ */
78
+ async function probeMidstreamerTransport(config) {
79
+ if (process.env.MIDSTREAMER_QUIC_NATIVE !== '1') {
80
+ return null;
81
+ }
82
+ let mod;
83
+ try {
84
+ // Lazy + indirect so bundlers don't try to resolve at compile time.
85
+ // Prefer the `midstreamer/quic` sub-path (added in midstreamer@0.3.1
86
+ // per upstream ruvnet/midstream#81) which exposes
87
+ // `loadQuicTransport` directly without WASM init. Fall back to the
88
+ // root `midstreamer` package for older versions that put the QUIC
89
+ // surface on the default export.
90
+ const dynamicImport = new Function('s', 'return import(s)');
91
+ try {
92
+ mod = await dynamicImport('midstreamer/quic');
93
+ }
94
+ catch {
95
+ mod = await dynamicImport('midstreamer');
96
+ }
97
+ }
98
+ catch {
99
+ return null;
100
+ }
101
+ const candidate = mod;
102
+ // CommonJS sub-path exposes its API via `module.exports = {...};
103
+ // module.exports.default = module.exports;` — so we also accept the
104
+ // `.default` form. ESM imports flatten the named exports directly.
105
+ const surface = (typeof candidate.loadQuicTransport === 'function'
106
+ ? candidate
107
+ : candidate.default);
108
+ if (!surface) {
109
+ return null;
110
+ }
111
+ // Refuse to use the WASM stub. ADR-119 documented the previous
112
+ // QuicMultistream as a counter-tracking stub with no real UDP, TLS,
113
+ // or protocol — using it would silently downgrade the federation
114
+ // path. midstreamer@0.3.1+ ships a real QUIC transport via
115
+ // `midstreamer/quic` (ADR-120, Step 1 — upstream PR ruvnet/midstream#81)
116
+ // and reports `isNative() === true`. Older versions either expose
117
+ // `isStub()` returning true or omit both probes.
118
+ if (typeof surface.isStub === 'function' && surface.isStub()) {
119
+ return { transport: null, reason: 'midstreamer module reports isStub() === true; refusing to bind a stub QUIC backend (ADR-119)' };
120
+ }
121
+ if (typeof surface.loadQuicTransport !== 'function') {
122
+ return null;
123
+ }
124
+ if (typeof surface.isNative === 'function' && !surface.isNative()) {
125
+ return null;
126
+ }
127
+ try {
128
+ const transport = await surface.loadQuicTransport(config);
129
+ return { transport };
130
+ }
131
+ catch (err) {
132
+ return {
133
+ transport: null,
134
+ reason: `midstreamer.loadQuicTransport failed: ${err instanceof Error ? err.message : String(err)}`,
135
+ };
136
+ }
137
+ }
138
+ /**
139
+ * Top-level loader for federation transport. Identical signature to
140
+ * agentic-flow's `loadQuicTransport`, but with the midstreamer-first
141
+ * preference. Use this from `plugins/ruflo-federation` in place of
142
+ * the bare `loadQuicTransport`.
143
+ *
144
+ * Failure mode: if midstreamer is requested but rejects (stub, init
145
+ * error, missing package), this function falls through to the
146
+ * agentic-flow loader silently — the federation peer always gets a
147
+ * transport (WebSocket fallback in the worst case, per ADR-104).
148
+ */
149
+ export async function loadFederationTransport(config) {
150
+ const probe = await probeMidstreamerTransport(config);
151
+ if (probe && probe.transport) {
152
+ return { transport: probe.transport, source: 'midstreamer-native' };
153
+ }
154
+ const transport = await loadAgenticFlowQuicTransport(config);
155
+ if (!transport) {
156
+ throw new Error('No federation transport available. Install `agentic-flow` ' +
157
+ '(default) or `midstreamer` and set `MIDSTREAMER_QUIC_NATIVE=1` ' +
158
+ '(per ADR-120). Both are now optional peer dependencies — at ' +
159
+ 'least one must be present at runtime.');
160
+ }
161
+ return {
162
+ transport,
163
+ source: 'agentic-flow-loader',
164
+ fallbackReason: probe?.reason,
165
+ };
166
+ }
167
+ //# sourceMappingURL=midstream-aware-loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"midstream-aware-loader.js","sourceRoot":"","sources":["../../src/transport/midstream-aware-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAgBH;;;;;;;;;;GAUG;AACH,KAAK,UAAU,4BAA4B,CACzC,MAA4B;IAE5B,8DAA8D;IAC9D,+DAA+D;IAC/D,kEAAkE;IAClE,iEAAiE;IACjE,mBAAmB;IACnB,IAAI,GAKH,CAAC;IACF,IAAI,CAAC;QACH,GAAG,GAAG,CAAC,MAAM,MAAM,CAAC,+BAA+B,CAAC,CAAe,CAAC;IACtE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,EAAE,GACN,OAAO,GAAG,CAAC,iBAAiB,KAAK,UAAU;QACzC,CAAC,CAAC,GAAG,CAAC,iBAAiB;QACvB,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,iBAAiB,CAAC;IACrC,IAAI,OAAO,EAAE,KAAK,UAAU,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAYD;;;;;;;;;;GAUG;AACH,KAAK,UAAU,yBAAyB,CACtC,MAA4B;IAE5B,IAAI,OAAO,CAAC,GAAG,CAAC,uBAAuB,KAAK,GAAG,EAAE,CAAC;QAChD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,GAAY,CAAC;IACjB,IAAI,CAAC;QACH,oEAAoE;QACpE,qEAAqE;QACrE,kDAAkD;QAClD,mEAAmE;QACnE,kEAAkE;QAClE,iCAAiC;QACjC,MAAM,aAAa,GAAoC,IAAI,QAAQ,CACjE,GAAG,EACH,kBAAkB,CACgB,CA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AiC;YAC5C,MAAM,EAAE,yCAAyC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;SACpG,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,MAA4B;IAE5B,MAAM,KAAK,GAAG,MAAM,yBAAyB,CAAC,MAAM,CAAC,CAAC;IACtD,IAAI,KAAK,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;QAC7B,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,oBAAoB,EAAE,CAAC;IACtE,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,4BAA4B,CAAC,MAAM,CAAC,CAAC;IAC7D,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,4DAA4D;YAC1D,iEAAiE;YACjE,8DAA8D;YAC9D,uCAAuC,CAC1C,CAAC;IACJ,CAAC;IACD,OAAO;QACL,SAAS;QACT,MAAM,EAAE,qBAAqB;QAC7B,cAAc,EAAE,KAAK,EAAE,MAAM;KAC9B,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claude-flow/plugin-agent-federation",
3
- "version": "1.0.0-alpha.14",
3
+ "version": "1.0.0-alpha.16",
4
4
  "description": "Cross-installation agent federation with zero-trust security, PII-gated data flow, and compliance-grade audit trails.",
5
5
  "homepage": "https://github.com/ruvnet/ruflo",
6
6
  "type": "module",
@@ -21,12 +21,24 @@
21
21
  "clean": "rm -rf dist"
22
22
  },
23
23
  "dependencies": {
24
- "@noble/ed25519": "^2.0.0",
25
- "agentic-flow": "2.0.12-fix.8"
24
+ "@noble/ed25519": "^2.0.0"
25
+ },
26
+ "peerDependencies": {
27
+ "agentic-flow": ">=2.0.12-fix.8",
28
+ "midstreamer": ">=0.3.1"
29
+ },
30
+ "peerDependenciesMeta": {
31
+ "agentic-flow": {
32
+ "optional": true
33
+ },
34
+ "midstreamer": {
35
+ "optional": true
36
+ }
26
37
  },
27
38
  "devDependencies": {
28
39
  "@claude-flow/shared": "workspace:*",
29
40
  "@claude-flow/security": "workspace:*",
41
+ "agentic-flow": "2.0.12-fix.8",
30
42
  "typescript": "^5.4.0",
31
43
  "vitest": "^4.0.16"
32
44
  },