reploid 0.0.0-stage → 0.1.1

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 (233) hide show
  1. package/apps/poolday/config/chat-files.json +27 -0
  2. package/apps/poolday/config/partition-generation.js +21 -0
  3. package/apps/poolday/config/partition-policy.json +74 -0
  4. package/apps/poolday/config/partition-releases.json +3 -0
  5. package/apps/poolday/config/work-profile.json +122 -0
  6. package/apps/poolday/host/chat-view.js +47 -0
  7. package/apps/poolday/host/earning/client.js +199 -0
  8. package/apps/poolday/host/earning/contribution.js +168 -0
  9. package/apps/poolday/host/partition-release.js +33 -0
  10. package/apps/poolday/host/work-partition-artifact-source.js +37 -0
  11. package/apps/poolday/host/work-partition-capsule.js +39 -0
  12. package/apps/poolday/host/work-partition-plan.js +167 -0
  13. package/apps/poolday/host/work-partition-tokenizer-guard.js +21 -0
  14. package/apps/poolday/infrastructure/model-storage-lock.js +22 -0
  15. package/apps/poolday/infrastructure/pack-release-storage.js +52 -0
  16. package/apps/poolday/pool/pack-operation.js +161 -0
  17. package/apps/poolday/pool/pack-release-policy.js +44 -0
  18. package/apps/poolday/pool/peer-pack-data-channel.js +217 -0
  19. package/apps/poolday/providers/work-adapter.js +67 -0
  20. package/apps/poolday/providers/work-device.js +33 -0
  21. package/apps/poolday/providers/work-generation-completion.js +55 -0
  22. package/apps/poolday/providers/work-provider.js +209 -0
  23. package/apps/poolday/providers/work-resident-provider.js +113 -0
  24. package/deploy/artifacts/doppler-gpu-0.7.1.tgz +0 -0
  25. package/docs/fleet-service.md +214 -0
  26. package/docs/native-participant.md +542 -0
  27. package/native-delivery.json +1174 -0
  28. package/package.json +29 -4
  29. package/packages/reploid/src/artifacts/binary.js +25 -0
  30. package/packages/reploid/src/artifacts/canonical-json.js +23 -0
  31. package/packages/reploid/src/artifacts/custody/exchange.js +402 -0
  32. package/packages/reploid/src/artifacts/custody/piece-acquisition.js +70 -0
  33. package/packages/reploid/src/artifacts/custody/runtime.js +404 -0
  34. package/packages/reploid/src/artifacts/custody/supply-budget.js +19 -0
  35. package/packages/reploid/src/artifacts/custody-certificate.js +123 -0
  36. package/packages/reploid/src/artifacts/delivery-attestation.js +64 -0
  37. package/packages/reploid/src/artifacts/generation-terminal.js +36 -0
  38. package/packages/reploid/src/artifacts/identity.js +91 -0
  39. package/packages/reploid/src/artifacts/participant-proofs.js +159 -0
  40. package/packages/reploid/src/artifacts/receipt.js +131 -0
  41. package/packages/reploid/src/artifacts/signatures.js +94 -0
  42. package/packages/reploid/src/artifacts/whole-model-receipt.js +42 -0
  43. package/packages/reploid/src/cancellation.js +44 -0
  44. package/packages/reploid/src/config/defaults.json +110 -0
  45. package/packages/reploid/src/config/index.js +209 -0
  46. package/packages/reploid/src/config/request-overrides.json +9 -0
  47. package/packages/reploid/src/config/transport-defaults.json +7 -0
  48. package/packages/reploid/src/hashing.js +30 -0
  49. package/packages/reploid/src/measurement/capacity-utilization.js +321 -0
  50. package/packages/reploid/src/measurement/index.js +5 -0
  51. package/packages/reploid/src/measurement/readiness-records.js +310 -0
  52. package/packages/reploid/src/mesh/computer-identity.js +50 -0
  53. package/packages/reploid/src/mesh/computer-identity.policy.json +8 -0
  54. package/packages/reploid/src/mesh/contribution.js +141 -0
  55. package/packages/reploid/src/mesh/generation-recovery.js +58 -0
  56. package/packages/reploid/src/mesh/gpu-signature-shader.js +27 -0
  57. package/packages/reploid/src/mesh/gpu-signature.js +136 -0
  58. package/packages/reploid/src/mesh/gpu-signature.policy.json +11 -0
  59. package/packages/reploid/src/mesh/index.js +66 -0
  60. package/packages/reploid/src/mesh/partitions/automatic-ordered-partitions.js +540 -0
  61. package/packages/reploid/src/mesh/partitions/automatic-partitions.js +298 -0
  62. package/packages/reploid/src/mesh/partitions/partition-attempt-evidence.js +282 -0
  63. package/packages/reploid/src/mesh/partitions/partition-attempt-queue-policy.json +6 -0
  64. package/packages/reploid/src/mesh/partitions/partition-attempt-queue.js +112 -0
  65. package/packages/reploid/src/mesh/partitions/partition-canonical-contract.js +167 -0
  66. package/packages/reploid/src/mesh/partitions/partition-canonical-execution.js +168 -0
  67. package/packages/reploid/src/mesh/partitions/partition-chat-canonical.js +49 -0
  68. package/packages/reploid/src/mesh/partitions/partition-chat.js +125 -0
  69. package/packages/reploid/src/mesh/partitions/partition-contract.js +192 -0
  70. package/packages/reploid/src/mesh/partitions/partition-device-admission.js +96 -0
  71. package/packages/reploid/src/mesh/partitions/partition-discovery.js +96 -0
  72. package/packages/reploid/src/mesh/partitions/partition-entry-publication.js +183 -0
  73. package/packages/reploid/src/mesh/partitions/partition-entry.js +434 -0
  74. package/packages/reploid/src/mesh/partitions/partition-generation-request.js +33 -0
  75. package/packages/reploid/src/mesh/partitions/partition-grants.js +277 -0
  76. package/packages/reploid/src/mesh/partitions/partition-link.js +103 -0
  77. package/packages/reploid/src/mesh/partitions/partition-network.js +109 -0
  78. package/packages/reploid/src/mesh/partitions/partition-ordered-chat.js +290 -0
  79. package/packages/reploid/src/mesh/partitions/partition-ordered-peer.js +415 -0
  80. package/packages/reploid/src/mesh/partitions/partition-ordered-publication.js +100 -0
  81. package/packages/reploid/src/mesh/partitions/partition-peer.js +314 -0
  82. package/packages/reploid/src/mesh/partitions/partition-placement.js +143 -0
  83. package/packages/reploid/src/mesh/partitions/partition-preparation-progress.js +25 -0
  84. package/packages/reploid/src/mesh/partitions/partition-receiver-policy.json +7 -0
  85. package/packages/reploid/src/mesh/partitions/partition-reservations.js +75 -0
  86. package/packages/reploid/src/mesh/partitions/partition-route-envelope-policy.json +16 -0
  87. package/packages/reploid/src/mesh/partitions/partition-route-envelope.js +74 -0
  88. package/packages/reploid/src/mesh/partitions/partition-route-execution.js +409 -0
  89. package/packages/reploid/src/mesh/partitions/partition-route-network.js +179 -0
  90. package/packages/reploid/src/mesh/partitions/partition-route-ranking.js +268 -0
  91. package/packages/reploid/src/mesh/partitions/partition-runner.js +319 -0
  92. package/packages/reploid/src/mesh/partitions/partition-stage-assignment.js +109 -0
  93. package/packages/reploid/src/mesh/partitions/partition-stage-commit.js +103 -0
  94. package/packages/reploid/src/mesh/partitions/partition-step-receiver.js +291 -0
  95. package/packages/reploid/src/mesh/partitions/partition-summary.js +122 -0
  96. package/packages/reploid/src/mesh/partitions/preparation-owner.js +40 -0
  97. package/packages/reploid/src/mesh/partitions/resident-error-codes.json +10 -0
  98. package/packages/reploid/src/mesh/partitions/resident-partition.js +333 -0
  99. package/packages/reploid/src/mesh/partitions/resident-route.js +46 -0
  100. package/packages/reploid/src/mesh/partitions/signed-resident-factory.js +59 -0
  101. package/packages/reploid/src/mesh/peer-generation.js +896 -0
  102. package/packages/reploid/src/mesh/peer-identity.js +87 -0
  103. package/packages/reploid/src/mesh/placement-beliefs.js +107 -0
  104. package/packages/reploid/src/mesh/preparation-progress.js +46 -0
  105. package/packages/reploid/src/mesh/provider-hardware.js +11 -0
  106. package/packages/reploid/src/mesh/remote-generation-requests.js +53 -0
  107. package/packages/reploid/src/mesh/swarm-coordination.js +140 -0
  108. package/packages/reploid/src/mesh/web-access-network.js +112 -0
  109. package/packages/reploid/src/mesh/web-access-policy.json +17 -0
  110. package/packages/reploid/src/retrieval/citations.js +156 -0
  111. package/packages/reploid/src/retrieval/claim-support.js +113 -0
  112. package/packages/reploid/src/retrieval/costs.js +101 -0
  113. package/packages/reploid/src/retrieval/fixed-provider.js +34 -0
  114. package/packages/reploid/src/retrieval/index.js +20 -0
  115. package/packages/reploid/src/retrieval/lexical-support.js +27 -0
  116. package/packages/reploid/src/retrieval/model-reviewer.js +67 -0
  117. package/packages/reploid/src/retrieval/page-fetch.json +10 -0
  118. package/packages/reploid/src/retrieval/page-text.js +182 -0
  119. package/packages/reploid/src/retrieval/passage.js +37 -0
  120. package/packages/reploid/src/retrieval/policy.json +14 -0
  121. package/packages/reploid/src/retrieval/retrieval.js +23 -0
  122. package/packages/reploid/src/retrieval/review-queue.js +76 -0
  123. package/packages/reploid/src/retrieval/sources.js +263 -0
  124. package/packages/reploid/src/retrieval/support-review.js +155 -0
  125. package/packages/reploid/src/retrieval/text.js +21 -0
  126. package/packages/reploid/src/rules/contribution.rules.json +8 -0
  127. package/packages/reploid/src/rules/routing.rules.json +24 -0
  128. package/packages/reploid/src/transport/assignment.js +571 -0
  129. package/packages/reploid/src/transport/bounded-channel-writer.js +46 -0
  130. package/packages/reploid/src/transport/index.js +11 -0
  131. package/packages/reploid/src/transport/introduction-admission.js +24 -0
  132. package/packages/reploid/src/transport/introduction-bootstrap.js +112 -0
  133. package/packages/reploid/src/transport/introduction-policy.json +12 -0
  134. package/packages/reploid/src/transport/introduction-records.js +90 -0
  135. package/packages/reploid/src/transport/introductions.js +209 -0
  136. package/packages/reploid/src/transport/partition-data-channel.js +421 -0
  137. package/packages/reploid/src/transport/partition-errors.json +16 -0
  138. package/packages/reploid/src/transport/retry-policy.js +36 -0
  139. package/packages/reploid/src/transport/room.js +502 -0
  140. package/packages/reploid/src/transport/sdp-fingerprint.js +5 -0
  141. package/packages/reploid/src/transport/signaling.js +571 -0
  142. package/packages/reploid/src/transport/swarm.js +1247 -0
  143. package/packages/reploid/src/transport/tool-offer-channel.js +137 -0
  144. package/server/browser-roots.js +42 -0
  145. package/server/browser-web-worker.js +94 -0
  146. package/server/chat-completions.js +45 -0
  147. package/server/fleet/browser-bridge.js +145 -0
  148. package/server/fleet/contract.js +42 -0
  149. package/server/fleet/credit-evidence.js +103 -0
  150. package/server/fleet/credit-recovery.js +175 -0
  151. package/server/fleet/credits.js +178 -0
  152. package/server/fleet/execution-admission.js +32 -0
  153. package/server/fleet/native-host.js +817 -0
  154. package/server/fleet/placement.js +132 -0
  155. package/server/fleet/requester.js +346 -0
  156. package/server/fleet/service.js +311 -0
  157. package/server/fleet/terminal-policy.js +83 -0
  158. package/server/fleet/text-api.js +94 -0
  159. package/server/hashing.js +35 -0
  160. package/server/http-request-owner.js +49 -0
  161. package/server/messages.js +57 -0
  162. package/server/native-canonical-epochs.js +90 -0
  163. package/server/native-change-log.js +40 -0
  164. package/server/native-earning.js +203 -0
  165. package/server/native-generation-journal.js +46 -0
  166. package/server/native-model-config.js +57 -0
  167. package/server/native-model-files.js +382 -0
  168. package/server/native-model-origin.js +54 -0
  169. package/server/native-model-origins.json +12 -0
  170. package/server/native-node.js +85 -0
  171. package/server/native-owner/controls.js +162 -0
  172. package/server/native-owner/monitor.js +251 -0
  173. package/server/native-owner/policy.js +273 -0
  174. package/server/native-owner/rate.js +92 -0
  175. package/server/native-participant.js +866 -0
  176. package/server/native-readiness-log.js +30 -0
  177. package/server/native-release-storage.js +64 -0
  178. package/server/native-shader-cache.js +369 -0
  179. package/server/native-supply-budget.js +66 -0
  180. package/server/native-whole-earning.js +67 -0
  181. package/server/native-whole-model-fill.js +182 -0
  182. package/server/native-whole-model.js +130 -0
  183. package/server/public-web-worker.js +66 -0
  184. package/server/responses.js +92 -0
  185. package/server/search/errors.js +47 -0
  186. package/server/search/page-fetch.js +185 -0
  187. package/server/text-api.js +83 -0
  188. package/server/text-recovery.js +45 -0
  189. package/server/text-request-options.js +23 -0
  190. package/server/text-requester.js +231 -0
  191. package/server/token-auth.js +9 -0
  192. package/server/whole-model-requester.js +99 -0
  193. package/shared/config/chat-models.json +4685 -0
  194. package/shared/config/doppler-execution-contracts.js +32 -0
  195. package/shared/config/doppler-execution-contracts.json +43 -0
  196. package/shared/config/doppler-generation-contract.js +223 -0
  197. package/shared/config/doppler-local-models.js +79 -0
  198. package/shared/config/doppler-package.json +7 -0
  199. package/shared/config/model-manifests/a0dc69e917133a82780823d17fc771c0f6b882d7c86c571deeaef45be2ff108b.json +6434 -0
  200. package/shared/config/model-manifests/e985e3cdad60d0cb57d84b436161e66ab5b3f6589a168de6f00b4610e5f1fb59.json +16534 -0
  201. package/shared/config/model-manifests/fa6eb7bbc3ba63571f8cede780b877d9272bde948697af93dd3d33837cb46137.json +7175 -0
  202. package/shared/config/model-pieces/qwen-0-8b-pieces.json +1506 -0
  203. package/shared/config/model-pieces/qwen-2b-pieces.json +4800 -0
  204. package/shared/config/model-pieces/qwen35b-q4_0-pieces.json +28880 -0
  205. package/shared/config/reploid-library.json +49 -0
  206. package/shared/config/swarm-bootstrap.json +21 -0
  207. package/shared/infrastructure/doppler-runtime-service.js +261 -0
  208. package/shared/pool/executable-pack.js +87 -0
  209. package/shared/pool/pack-operation-adapters.js +124 -0
  210. package/shared/pool/pack-operation-policy.js +75 -0
  211. package/shared/pool/pool-config.json +2280 -0
  212. package/shared/vendor/reploid/adapters/doppler-session.js +372 -0
  213. package/shared/vendor/reploid/artifacts/binary.js +25 -0
  214. package/shared/vendor/reploid/artifacts/canonical-json.js +23 -0
  215. package/shared/vendor/reploid/artifacts/delivery-attestation.js +64 -0
  216. package/shared/vendor/reploid/artifacts/identity.js +91 -0
  217. package/shared/vendor/reploid/artifacts/manifest-identity.js +17 -0
  218. package/shared/vendor/reploid/artifacts/participant-proofs.js +159 -0
  219. package/shared/vendor/reploid/artifacts/signatures.js +94 -0
  220. package/shared/vendor/reploid/config/defaults.json +110 -0
  221. package/shared/vendor/reploid/config/index.js +209 -0
  222. package/shared/vendor/reploid/config/request-overrides.json +9 -0
  223. package/shared/vendor/reploid/hashing.js +30 -0
  224. package/shared/vendor/reploid/mesh/generation-context-cache.js +97 -0
  225. package/shared/vendor/reploid/mesh/partitions/partition-attempt-evidence.js +282 -0
  226. package/shared/vendor/reploid/mesh/partitions/partition-contract.js +192 -0
  227. package/shared/vendor/reploid/mesh/partitions/partition-receiver-policy.json +7 -0
  228. package/shared/vendor/reploid/mesh/partitions/partition-route-ranking.js +268 -0
  229. package/shared/vendor/reploid/mesh/preparation-progress.js +46 -0
  230. package/shared/vendor/reploid/mesh/provider-hardware.js +11 -0
  231. package/shared/vendor/reploid/rules/routing.rules.json +24 -0
  232. package/shared/vendor/reploid/transport/partition-errors.json +16 -0
  233. package/README.md +0 -3
@@ -0,0 +1,136 @@
1
+ import policy from './gpu-signature.policy.json' with { type: 'json' };
2
+ import { gpuSignatureShader } from './gpu-signature-shader.js';
3
+ import { publicProviderHardware } from './provider-hardware.js';
4
+
5
+ const active = new WeakSet();
6
+ const permutation = row => Array.isArray(row) && row.length === policy.workgroups
7
+ && row.every(value => Number.isInteger(value) && value >= 0 && value < policy.workgroups)
8
+ && new Set(row).size === policy.workgroups;
9
+
10
+ function summarize(signature) {
11
+ if (!signature || signature.schema !== policy.schema || signature.profile !== policy.profile
12
+ || signature.status !== 'measured' || signature.workgroups !== policy.workgroups
13
+ || signature.trials !== policy.trials || !Array.isArray(signature.samples)
14
+ || signature.samples.length !== policy.seeds.length) throw new TypeError('Invalid GPU signature');
15
+ const means = [], deviations = [];
16
+ for (const [index, sample] of signature.samples.entries()) {
17
+ if (sample.seed !== policy.seeds[index] || sample.workload !== index
18
+ || !Array.isArray(sample.orders) || sample.orders.length !== policy.trials
19
+ || !sample.orders.every(permutation)) throw new TypeError('Invalid GPU signature samples');
20
+ for (let group = 0; group < policy.workgroups; group++) {
21
+ const values = sample.orders.map(row => row[group] / (policy.workgroups - 1));
22
+ const mean = values.reduce((a, b) => a + b, 0) / values.length;
23
+ means.push(mean);
24
+ deviations.push(Math.sqrt(values.reduce((sum, value) => sum + (value - mean) ** 2, 0) / values.length));
25
+ }
26
+ }
27
+ return { means, deviations };
28
+ }
29
+
30
+ /** Measures the LOCAL GPU only. No identifier, storage write, or network upload.
31
+ * The caller must opt in. Cancellation stops new dispatches; submitted work is bounded,
32
+ * not forcibly preempted. A borrowed device is never destroyed.
33
+ */
34
+ export async function captureGpuSignature(device = null, { consent = false, signal,
35
+ gpu = globalThis.navigator?.gpu } = {}) {
36
+ if (consent !== true) throw new Error('GPU signature collection requires explicit consent');
37
+ signal?.throwIfAborted();
38
+ if (!device && !gpu?.requestAdapter) return { status: 'unavailable', reason: 'webgpu-unavailable' };
39
+ if (device && active.has(device)) throw new Error('GPU signature measurement is already running on this device');
40
+ const started = performance.now(), buffers = [];
41
+ const owned = !device;
42
+ let timer, cancel, finished = false, hardware = null;
43
+ const interrupted = new Promise((_, reject) => {
44
+ timer = setTimeout(() => reject(new Error('GPU signature measurement timed out')), policy.timeoutMs);
45
+ cancel = () => reject(signal.reason || new Error('GPU signature measurement cancelled'));
46
+ signal?.addEventListener('abort', cancel, { once: true });
47
+ });
48
+ // Attach a rejection handler even if setup fails before the first await.
49
+ interrupted.catch(() => {});
50
+ let lost;
51
+ const wait = promise => Promise.race([promise, interrupted, ...(lost ? [lost] : [])]);
52
+ try {
53
+ if (!device) {
54
+ const adapter = await wait(gpu.requestAdapter());
55
+ if (!adapter) return { status: 'unavailable', reason: 'adapter-unavailable' };
56
+ if (adapter.info?.isFallbackAdapter) return { status: 'unavailable', reason: 'software-adapter' };
57
+ hardware = publicProviderHardware(adapter.info);
58
+ device = await wait(adapter.requestDevice().then(created => {
59
+ if (finished) { created.destroy(); throw new Error('GPU signature acquisition expired'); }
60
+ return created;
61
+ }));
62
+ } else hardware = publicProviderHardware(device.adapterInfo);
63
+ active.add(device);
64
+ lost = device.lost.then(info => { throw new Error('GPU device lost: ' + info.reason); });
65
+ lost.catch(() => {});
66
+ const makeBuffer = (size, usage) => {
67
+ const buffer = device.createBuffer({ size, usage }); buffers.push(buffer); return buffer;
68
+ };
69
+ const outputBytes = (1 + 2 * policy.workgroups) * 4;
70
+ const params = makeBuffer(16, GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST);
71
+ const input = makeBuffer(policy.dataWords * 4, GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST);
72
+ const result = makeBuffer(outputBytes, GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST);
73
+ const readback = makeBuffer(outputBytes, GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST);
74
+ const data = Uint32Array.from({ length: policy.dataWords }, (_, i) => Math.imul(i + 1, 2654435761) >>> 0);
75
+ device.queue.writeBuffer(input, 0, data);
76
+ const module = device.createShaderModule({ code: gpuSignatureShader });
77
+ const pipeline = await wait(device.createComputePipelineAsync({ layout: 'auto', compute: { module, entryPoint: 'main' } }));
78
+ const bindings = device.createBindGroup({ layout: pipeline.getBindGroupLayout(0),
79
+ entries: [params, input, result].map((buffer, binding) => ({ binding, resource: { buffer } })) });
80
+ const samples = [];
81
+ for (let workload = 0; workload < policy.seeds.length; workload++) {
82
+ const seed = policy.seeds[workload], orders = [], checksums = [];
83
+ // Discard one dispatch per workload for compilation/initial scheduling effects.
84
+ for (let trial = -1; trial < policy.trials; trial++) {
85
+ signal?.throwIfAborted();
86
+ device.queue.writeBuffer(params, 0, new Uint32Array([seed, workload, 0, 0]));
87
+ device.queue.writeBuffer(result, 0, new Uint32Array(outputBytes / 4));
88
+ const encoder = device.createCommandEncoder(), pass = encoder.beginComputePass();
89
+ pass.setPipeline(pipeline); pass.setBindGroup(0, bindings); pass.dispatchWorkgroups(policy.workgroups); pass.end();
90
+ encoder.copyBufferToBuffer(result, 0, readback, 0, outputBytes);
91
+ device.queue.submit([encoder.finish()]);
92
+ await wait(readback.mapAsync(GPUMapMode.READ));
93
+ const words = new Uint32Array(readback.getMappedRange()).slice();
94
+ readback.unmap();
95
+ const order = Array.from(words.slice(1, 1 + policy.workgroups));
96
+ if (words[0] !== policy.workgroups || !permutation(order)) throw new Error('GPU signature dispatch returned incomplete results');
97
+ if (trial >= 0) { orders.push(order); checksums.push(Array.from(words.slice(1 + policy.workgroups))); }
98
+ }
99
+ samples.push({ workload, seed, orders, checksums });
100
+ }
101
+ signal?.throwIfAborted();
102
+ const signature = { schema: policy.schema, profile: policy.profile, status: 'measured',
103
+ source: 'local-webgpu', hardware, workgroups: policy.workgroups, trials: policy.trials,
104
+ collectedAt: new Date().toISOString(), elapsedMs: performance.now() - started,
105
+ allocationBytes: buffers.reduce((sum, buffer) => sum + buffer.size, 0), samples };
106
+ return { ...signature, statistics: summarize(signature) };
107
+ } finally {
108
+ finished = true;
109
+ clearTimeout(timer); signal?.removeEventListener('abort', cancel);
110
+ for (const buffer of buffers) buffer.destroy();
111
+ if (device) { active.delete(device); if (owned) device.destroy(); }
112
+ }
113
+ }
114
+
115
+ /** Distance is descriptive. Thresholds must be supplied with a calibration reference;
116
+ * no default threshold claims that a signature identifies a physical GPU.
117
+ */
118
+ export function compareGpuSignatures(baseline, candidate, thresholds = null) {
119
+ if (!baseline || !candidate || baseline.status !== 'measured' || candidate.status !== 'measured') {
120
+ return { status: 'unmeasured', distance: null, reason: 'missing-measurement' };
121
+ }
122
+ if (baseline.profile !== candidate.profile || baseline.schema !== candidate.schema) {
123
+ return { status: 'uncertain', distance: null, reason: 'incompatible-profiles' };
124
+ }
125
+ const a = summarize(baseline), b = summarize(candidate);
126
+ const distance = Math.sqrt(a.means.reduce((sum, mean, i) => sum + (mean - b.means[i]) ** 2, 0) / a.means.length);
127
+ const variability = Math.sqrt([...a.deviations, ...b.deviations].reduce((sum, value) => sum + value ** 2, 0) / (a.means.length * 2));
128
+ if (!thresholds) return { status: 'uncertain', distance, variability, reason: 'calibration-required' };
129
+ const { calibrationId, consistentMax, changedMin } = thresholds;
130
+ if (typeof calibrationId !== 'string' || !calibrationId.trim() || !Number.isFinite(consistentMax)
131
+ || !Number.isFinite(changedMin) || consistentMax < 0 || changedMin <= consistentMax || changedMin > 1) {
132
+ throw new TypeError('GPU comparison needs calibrated distance thresholds and a calibrationId');
133
+ }
134
+ const status = distance <= consistentMax ? 'consistent' : distance >= changedMin ? 'changed' : 'uncertain';
135
+ return { status, distance, variability, calibrationId, consistentMax, changedMin, reason: 'signature-distance-only' };
136
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "schema": "reploid.gpu-order-signature/v1",
3
+ "profile": "atomic-finish-order-v1",
4
+ "workgroups": 64,
5
+ "lanes": 32,
6
+ "iterations": 128,
7
+ "trials": 16,
8
+ "seeds": [305419896, 2654435769],
9
+ "dataWords": 4096,
10
+ "timeoutMs": 5000
11
+ }
@@ -0,0 +1,66 @@
1
+ export { createPeerGenerationMesh } from './peer-generation.js';
2
+ export { identifyComputer, participantLabel } from './computer-identity.js';
3
+ export { captureGpuSignature, compareGpuSignatures } from './gpu-signature.js';
4
+ export { projectPlacementBeliefs, resolvePlacementBeliefPolicy } from './placement-beliefs.js';
5
+ export * from './swarm-coordination.js';
6
+ export * from './partitions/partition-runner.js';
7
+ export * from './partitions/partition-step-receiver.js';
8
+ export * from './contribution.js';
9
+ export { default as contributionPolicy } from './contribution.js';
10
+ export { default as swarmCoordination } from './swarm-coordination.js';
11
+ import routing from '../rules/routing.rules.json' with { type: 'json' };
12
+ import { requireResolvedConfig, snapshotJson } from '../config/index.js';
13
+
14
+ export function createIntelligenceMesh({ config, ports }) {
15
+ const policy = requireResolvedConfig(config);
16
+ if (typeof ports?.authorize !== 'function') throw new TypeError('Mesh host authorization is required');
17
+ const order = routing.rules.find(rule => rule.id === policy.mesh.routing).order;
18
+ let closed = false;
19
+ return Object.freeze({
20
+ async connect() {
21
+ if (closed || !policy.mesh.enabled) throw new Error('Mesh connection is disabled');
22
+ if (await ports.authorize({ action: 'mesh.connect', roomId: policy.mesh.roomId }) !== true) throw new Error('Host denied mesh connection');
23
+ if (!ports.remote?.connect) throw new Error('A configured protocol adapter is required');
24
+ return ports.remote.connect();
25
+ },
26
+ async generate(messages, onUpdate, { signal } = {}) {
27
+ if (closed) throw new Error('Mesh is closed');
28
+ signal?.throwIfAborted();
29
+ for (const placement of order) {
30
+ const provider = ports[placement];
31
+ if (!provider) continue;
32
+ if (placement === 'remote' && (!policy.mesh.enabled || !provider.hasAvailableProvider?.())) continue;
33
+ if (await ports.authorize({ action: 'mesh.place', placement, contract: policy.models.contract }) !== true) continue;
34
+ // Placement is chosen before execution. Execution failure never silently
35
+ // retries private data on another provider.
36
+ return provider.generate(snapshotJson(messages), onUpdate, { signal });
37
+ }
38
+ throw new Error('No authorized compatible execution placement');
39
+ },
40
+ describe() {
41
+ return snapshotJson({ schema: 'reploid.mesh-state/v1', enabled: policy.mesh.enabled,
42
+ permissions: { executeJobs: policy.mesh.executeJobs, supplyArtifacts: policy.mesh.supplyArtifacts, shareCandidates: policy.mesh.shareCandidates },
43
+ local: !!ports.local, remote: ports.remote?.getSwarmSnapshot?.() || null, modelContract: policy.models.contract,
44
+ publicQualification: null });
45
+ },
46
+ async close() { closed = true; }
47
+ });
48
+ }
49
+
50
+ export * from './partitions/resident-partition.js';
51
+ export * from './partitions/partition-grants.js';
52
+ export * from './partitions/partition-stage-commit.js';
53
+ export * from './partitions/partition-peer.js';
54
+ export * from './partitions/partition-network.js';
55
+ export * from './partitions/partition-chat.js';
56
+ export { partitionFingerprint, PARTITION_ROUTE_SCHEMA, ROUTE_ATTEMPT_SCHEMA, validatePartitionRoute,
57
+ canonicalRouteAttemptBinding, sameRouteAttemptIdentity } from './partitions/partition-contract.js';
58
+ export { selectPartitionRoute, validateOrderedPartitionCapability } from './partitions/partition-placement.js';
59
+
60
+ export * from './partitions/partition-entry.js';
61
+ export * from './partitions/partition-attempt-evidence.js';
62
+ export * from './partitions/partition-link.js';
63
+
64
+ export * from './partitions/automatic-partitions.js';
65
+ export * from './partitions/signed-resident-factory.js';
66
+ export * from './partitions/partition-preparation-progress.js';