@ruvector/ruvllm 4.0.1 → 4.1.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/README.md +447 -160
- package/bin/cli.js +1066 -0
- package/bin/gpu-delegate.js +67 -0
- package/bin/ruvllm-adapters.js +5 -0
- package/bin/ruvllm-gpu-loop.js +5 -0
- package/bin/serve.js +265 -0
- package/dist/cjs/benchmarks/embedding-benchmark.d.ts +102 -0
- package/dist/cjs/benchmarks/embedding-benchmark.d.ts.map +1 -0
- package/dist/cjs/benchmarks/embedding-benchmark.js +436 -0
- package/dist/cjs/benchmarks/index.d.ts +34 -0
- package/dist/cjs/benchmarks/index.d.ts.map +1 -0
- package/dist/cjs/benchmarks/index.js +132 -0
- package/dist/cjs/benchmarks/model-comparison.d.ts +71 -0
- package/dist/cjs/benchmarks/model-comparison.d.ts.map +1 -0
- package/dist/cjs/benchmarks/model-comparison.js +476 -0
- package/dist/cjs/benchmarks/routing-benchmark.d.ts +70 -0
- package/dist/cjs/benchmarks/routing-benchmark.d.ts.map +1 -0
- package/dist/cjs/benchmarks/routing-benchmark.js +289 -0
- package/dist/cjs/contrastive.d.ts +229 -0
- package/dist/cjs/contrastive.d.ts.map +1 -0
- package/dist/cjs/contrastive.js +589 -0
- package/dist/cjs/engine.d.ts +160 -0
- package/dist/cjs/engine.d.ts.map +1 -0
- package/dist/cjs/engine.js +552 -0
- package/dist/cjs/export.d.ts +182 -0
- package/dist/cjs/export.d.ts.map +1 -0
- package/dist/cjs/export.js +422 -0
- package/dist/cjs/federated.d.ts +233 -0
- package/dist/cjs/federated.d.ts.map +1 -0
- package/dist/cjs/federated.js +525 -0
- package/dist/cjs/index.d.ts +68 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +104 -0
- package/dist/cjs/intelligence.d.ts +136 -0
- package/dist/cjs/intelligence.d.ts.map +1 -0
- package/dist/cjs/intelligence.js +226 -0
- package/dist/cjs/lora.d.ts +251 -0
- package/dist/cjs/lora.d.ts.map +1 -0
- package/dist/cjs/lora.js +509 -0
- package/dist/cjs/models.d.ts +129 -0
- package/dist/cjs/models.d.ts.map +1 -0
- package/dist/cjs/models.js +323 -0
- package/dist/cjs/native.d.ts +140 -0
- package/dist/cjs/native.d.ts.map +1 -0
- package/dist/cjs/native.js +98 -0
- package/dist/cjs/session.d.ts +80 -0
- package/dist/cjs/session.d.ts.map +1 -0
- package/dist/cjs/session.js +203 -0
- package/dist/cjs/simd.d.ts +90 -0
- package/dist/cjs/simd.d.ts.map +1 -0
- package/dist/cjs/simd.js +209 -0
- package/dist/cjs/sona.d.ts +223 -0
- package/dist/cjs/sona.d.ts.map +1 -0
- package/dist/cjs/sona.js +562 -0
- package/dist/cjs/streaming.d.ts +55 -0
- package/dist/cjs/streaming.d.ts.map +1 -0
- package/dist/cjs/streaming.js +131 -0
- package/dist/cjs/training.d.ts +312 -0
- package/dist/cjs/training.d.ts.map +1 -0
- package/dist/cjs/training.js +610 -0
- package/dist/cjs/types.d.ts +696 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +6 -0
- package/dist/esm/benchmarks/embedding-benchmark.d.ts +102 -0
- package/dist/esm/benchmarks/embedding-benchmark.d.ts.map +1 -0
- package/dist/esm/benchmarks/embedding-benchmark.js +427 -0
- package/dist/esm/benchmarks/index.d.ts +34 -0
- package/dist/esm/benchmarks/index.d.ts.map +1 -0
- package/dist/esm/benchmarks/index.js +110 -0
- package/dist/esm/benchmarks/model-comparison.d.ts +71 -0
- package/dist/esm/benchmarks/model-comparison.d.ts.map +1 -0
- package/dist/esm/benchmarks/model-comparison.js +434 -0
- package/dist/esm/benchmarks/routing-benchmark.d.ts +70 -0
- package/dist/esm/benchmarks/routing-benchmark.d.ts.map +1 -0
- package/dist/esm/benchmarks/routing-benchmark.js +283 -0
- package/dist/esm/contrastive.d.ts +229 -0
- package/dist/esm/contrastive.d.ts.map +1 -0
- package/dist/esm/contrastive.js +578 -0
- package/dist/esm/engine.d.ts +160 -0
- package/dist/esm/engine.d.ts.map +1 -0
- package/dist/esm/engine.js +548 -0
- package/dist/esm/export.d.ts +182 -0
- package/dist/esm/export.d.ts.map +1 -0
- package/dist/esm/export.js +414 -0
- package/dist/esm/federated.d.ts +233 -0
- package/dist/esm/federated.d.ts.map +1 -0
- package/dist/esm/federated.js +520 -0
- package/dist/esm/index.d.ts +68 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +84 -0
- package/dist/esm/intelligence.d.ts +136 -0
- package/dist/esm/intelligence.d.ts.map +1 -0
- package/dist/esm/intelligence.js +188 -0
- package/dist/esm/lora.d.ts +251 -0
- package/dist/esm/lora.d.ts.map +1 -0
- package/dist/esm/lora.js +504 -0
- package/dist/esm/models.d.ts +129 -0
- package/dist/esm/models.d.ts.map +1 -0
- package/dist/esm/models.js +282 -0
- package/dist/esm/native.d.ts +140 -0
- package/dist/esm/native.d.ts.map +1 -0
- package/dist/esm/native.js +100 -0
- package/dist/esm/session.d.ts +80 -0
- package/dist/esm/session.d.ts.map +1 -0
- package/dist/esm/session.js +199 -0
- package/dist/esm/simd.d.ts +90 -0
- package/dist/esm/simd.d.ts.map +1 -0
- package/dist/esm/simd.js +205 -0
- package/dist/esm/sona.d.ts +223 -0
- package/dist/esm/sona.d.ts.map +1 -0
- package/dist/esm/sona.js +556 -0
- package/dist/esm/streaming.d.ts +55 -0
- package/dist/esm/streaming.d.ts.map +1 -0
- package/dist/esm/streaming.js +126 -0
- package/dist/esm/training.d.ts +312 -0
- package/dist/esm/training.d.ts.map +1 -0
- package/dist/esm/training.js +603 -0
- package/dist/esm/types.d.ts +696 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +5 -0
- package/gpu/_load.cjs +38 -0
- package/gpu/_load.mjs +33 -0
- package/gpu/adapters.cjs +3 -0
- package/gpu/adapters.mjs +5 -0
- package/gpu/engine.cjs +3 -0
- package/gpu/engine.mjs +5 -0
- package/gpu/fixture.cjs +3 -0
- package/gpu/fixture.mjs +5 -0
- package/gpu/gpu-host.cjs +3 -0
- package/gpu/gpu-host.mjs +5 -0
- package/gpu/gpu-loop.cjs +3 -0
- package/gpu/gpu-loop.mjs +5 -0
- package/gpu/gpu-spool-adapter.cjs +3 -0
- package/gpu/gpu-spool-adapter.mjs +5 -0
- package/gpu/vast-host-adapter.cjs +3 -0
- package/gpu/vast-host-adapter.mjs +5 -0
- package/package.json +159 -49
- package/scripts/ensemble-model-compare.js +287 -0
- package/scripts/fix-esm-extensions.mjs +220 -0
- package/scripts/huggingface/README.md +537 -0
- package/scripts/huggingface/publish.sh +112 -0
- package/scripts/hybrid-model-compare.js +373 -0
- package/scripts/improved-model-compare.js +288 -0
- package/scripts/optimized-model-compare.js +364 -0
- package/scripts/real-model-compare.js +280 -0
- package/scripts/smoke-esm.mjs +82 -0
- package/scripts/training/agentic-flow-capabilities.json +329 -0
- package/scripts/training/claude-code-synth.js +505 -0
- package/scripts/training/claude-flow-capabilities.json +1322 -0
- package/scripts/training/claude-hard-negatives.js +222 -0
- package/scripts/training/contrastive-finetune.js +517 -0
- package/scripts/training/ecosystem-triplets.jsonl +1467 -0
- package/scripts/training/generate-ecosystem-triplets.js +1324 -0
- package/scripts/training/routing-dataset.js +634 -0
- package/scripts/training/ruvector-capabilities.json +798 -0
- package/scripts/training/validate-ecosystem.js +381 -0
- package/scripts/training/validation-results.json +23 -0
- package/GPU-LOOP.md +0 -229
- package/LICENSE +0 -201
- package/NOTICE +0 -9
- package/examples/gpu-loop.example.json +0 -26
- package/src/adapters-cli.mjs +0 -23
- package/src/adapters.mjs +0 -91
- package/src/cli.mjs +0 -30
- package/src/engine.mjs +0 -238
- package/src/fixture.mjs +0 -38
- package/src/gpu-host.mjs +0 -47
- package/src/gpu-loop-cli.mjs +0 -67
- package/src/gpu-loop.mjs +0 -184
- package/src/gpu-spool-adapter.mjs +0 -80
- package/src/vast-host-adapter.mjs +0 -274
package/LICENSE
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright 2026 Alibaba Cloud
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
package/NOTICE
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
RuFlo Code Model
|
|
2
|
-
Copyright 2026 rUv and contributors
|
|
3
|
-
|
|
4
|
-
Original experiment code and synthetic tool traces are licensed under Apache 2.0.
|
|
5
|
-
Base model: Qwen/Qwen3.5-4B, Apache 2.0, owned by the Qwen team.
|
|
6
|
-
HumanEval data in data/external is MIT licensed; see HumanEval.LICENSE.
|
|
7
|
-
MLX LM, Transformers, PEFT, and Claude Code Router retain their respective licenses.
|
|
8
|
-
Claude Code is a separate proprietary client. No Claude model weights or private
|
|
9
|
-
Claude training data are included. This project is not endorsed by Anthropic.
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"schema": "ruvllm-gpu-loop/v1",
|
|
3
|
-
"stateRoot": "/absolute/private/gpu-loop-state",
|
|
4
|
-
"intervalSeconds": 60,
|
|
5
|
-
"maxAttempts": 2,
|
|
6
|
-
"budgetUsd": 0,
|
|
7
|
-
"jobs": [
|
|
8
|
-
{
|
|
9
|
-
"id": "qwen35-4b-paired-evaluation",
|
|
10
|
-
"provider": "vast.ai",
|
|
11
|
-
"model": {
|
|
12
|
-
"repo": "Qwen/Qwen3.5-4B",
|
|
13
|
-
"revision": "851bf6e806efd8d0a36b00ddf55e13ccb7b8cd0a"
|
|
14
|
-
},
|
|
15
|
-
"task": "evaluate",
|
|
16
|
-
"secretRef": "ruos.vast.primary",
|
|
17
|
-
"resource": { "instanceId": "REPLACE_WITH_EXISTING_INSTANCE_ID" },
|
|
18
|
-
"maxCostUsd": 1,
|
|
19
|
-
"timeoutSeconds": 1800,
|
|
20
|
-
"experiment": {
|
|
21
|
-
"configPath": "/absolute/private/operator-profile/runtime.json",
|
|
22
|
-
"planPath": "/absolute/experiment-inputs/plan.json"
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
]
|
|
26
|
-
}
|
package/src/adapters-cli.mjs
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { exportArchive, trainingPlan, selectDevelopmentCandidate } from './adapters.mjs';
|
|
3
|
-
|
|
4
|
-
const operations = { export: exportArchive, 'training-plan': trainingPlan, select: selectDevelopmentCandidate };
|
|
5
|
-
if (process.argv.length !== 3 || !Object.hasOwn(operations, process.argv[2])) {
|
|
6
|
-
process.stderr.write('Usage: node src/adapters-cli.mjs export|training-plan|select < input.json\nJSON data only; no training, inference or activation is executed.\n');
|
|
7
|
-
process.exitCode = process.argv[2] === '--help' ? 0 : 2;
|
|
8
|
-
} else {
|
|
9
|
-
try {
|
|
10
|
-
const chunks = [];
|
|
11
|
-
let bytes = 0;
|
|
12
|
-
for await (const chunk of process.stdin) {
|
|
13
|
-
bytes += chunk.length;
|
|
14
|
-
if (bytes > 16 * 1024 * 1024) throw new Error('Input exceeds 16 MiB');
|
|
15
|
-
chunks.push(chunk);
|
|
16
|
-
}
|
|
17
|
-
const input = JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
18
|
-
process.stdout.write(JSON.stringify(await operations[process.argv[2]](input), null, 2) + '\n');
|
|
19
|
-
} catch (error) {
|
|
20
|
-
process.stderr.write(JSON.stringify({ ok: false, error: error.message }) + '\n');
|
|
21
|
-
process.exitCode = 1;
|
|
22
|
-
}
|
|
23
|
-
}
|
package/src/adapters.mjs
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
// MetaHarness adapters are data-only: no provider requests, trainer launch or activation.
|
|
2
|
-
import { createHash } from 'node:crypto';
|
|
3
|
-
import { exportTrainingData, twoStagePlan } from '@metaharness/weight-eft';
|
|
4
|
-
import { runContrastive, digestDocument } from '@metaharness/darwin/contrastive';
|
|
5
|
-
|
|
6
|
-
const hash = value => createHash('sha256').update(JSON.stringify(value)).digest('hex');
|
|
7
|
-
const require = (condition, message) => { if (!condition) throw new Error(message); };
|
|
8
|
-
const identifier = value => typeof value === 'string' && /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$/.test(value);
|
|
9
|
-
|
|
10
|
-
/** Export reviewed caller-asserted trajectories; held-out instance IDs are always excluded. */
|
|
11
|
-
export function exportArchive({ archive, evalHoldout, maxTokens = 12000 }) {
|
|
12
|
-
require(Array.isArray(archive) && archive.length <= 10000, 'Archive limit is 10000 trajectories');
|
|
13
|
-
require(Array.isArray(evalHoldout) && evalHoldout.every(identifier), 'Explicit eval holdout IDs required');
|
|
14
|
-
require(Number.isInteger(maxTokens) && maxTokens >= 1 && maxTokens <= 32768, 'Invalid token budget');
|
|
15
|
-
require(Buffer.byteLength(JSON.stringify(archive)) <= 16 * 1024 * 1024, 'Archive exceeds 16 MiB');
|
|
16
|
-
for (const row of archive) {
|
|
17
|
-
require(row && identifier(row.instance_id) && typeof row.model === 'string' && row.model.length > 0,
|
|
18
|
-
'Invalid trajectory identity');
|
|
19
|
-
require(['cheap', 'frontier'].includes(row.tier) && typeof row.resolved === 'boolean', 'Invalid trajectory outcome');
|
|
20
|
-
require(typeof row.model_patch === 'string' && Array.isArray(row.messages) && row.messages.length <= 4096,
|
|
21
|
-
'Invalid trajectory content');
|
|
22
|
-
for (const message of row.messages) {
|
|
23
|
-
require(message && ['system', 'user', 'assistant', 'tool'].includes(message.role)
|
|
24
|
-
&& (typeof message.content === 'string' || message.content === null), 'Invalid message');
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
const result = exportTrainingData(archive, {
|
|
28
|
-
evalHoldout, maxTokens, truncateOverLength: false, dropRewardHacked: true,
|
|
29
|
-
});
|
|
30
|
-
return {
|
|
31
|
-
schema: 'ruvllm-training-export/v1', ...result,
|
|
32
|
-
archiveSha256: hash(archive), holdoutSha256: hash(evalHoldout),
|
|
33
|
-
evidenceOrigin: 'caller-asserted-trajectories', trainingExecuted: false,
|
|
34
|
-
productionActivation: false,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** Upstream command is informational; this checkout has no `ruvllm microlora` CLI. */
|
|
39
|
-
export function trainingPlan({ base, sftPath, dpoPath, adapterPrefix }) {
|
|
40
|
-
require(base && typeof base.id === 'string' && Number.isFinite(base.paramsB), 'Invalid model');
|
|
41
|
-
for (const path of [sftPath, dpoPath, adapterPrefix]) require(typeof path === 'string' && path.length > 0, 'Path required');
|
|
42
|
-
return {
|
|
43
|
-
schema: 'ruvllm-training-plan/v1',
|
|
44
|
-
plans: twoStagePlan(base, sftPath, dpoPath, adapterPrefix),
|
|
45
|
-
executionStatus: 'not_executed',
|
|
46
|
-
runnerCompatibility: 'adapter-required',
|
|
47
|
-
reason: 'The upstream ruvllm microlora command is not implemented by this standalone checkout. Use a separately validated trainer; DPO requires an additional trainer implementation.',
|
|
48
|
-
productionActivation: false,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** Replay bounded measured scores through Darwin. This ranks development evidence only. */
|
|
53
|
-
export async function selectDevelopmentCandidate({ baseline, candidates, envelope }) {
|
|
54
|
-
require(envelope && typeof envelope === 'object' && !Array.isArray(envelope), 'Immutable experiment envelope required');
|
|
55
|
-
require(Array.isArray(candidates) && candidates.length > 0 && candidates.length <= 32, 'Expected 1..32 candidates');
|
|
56
|
-
const all = [baseline, ...candidates];
|
|
57
|
-
for (const candidate of all) {
|
|
58
|
-
require(candidate && identifier(candidate.id) && Number.isFinite(candidate.score)
|
|
59
|
-
&& candidate.score >= 0 && candidate.score <= 1
|
|
60
|
-
&& /^[a-f0-9]{64}$/.test(candidate.evidenceSha256), 'Invalid measured candidate');
|
|
61
|
-
}
|
|
62
|
-
require(new Set(all.map(row => row.id)).size === all.length, 'Duplicate candidate ID');
|
|
63
|
-
const byId = new Map(all.map(row => [row.id, { ...row }]));
|
|
64
|
-
const best = candidates.reduce((a, b) => b.score > a.score ? b : a);
|
|
65
|
-
const document = { components: [{ id: 'weight-candidate', scope: 'domain', content: { id: baseline.id } }] };
|
|
66
|
-
const result = await runContrastive({
|
|
67
|
-
tenantId: 'local', projectId: 'ruvllm', task: { purpose: 'development-candidate-selection' },
|
|
68
|
-
environment: { mode: 'evidence-replay' },
|
|
69
|
-
library: { tenantId: 'local', projectId: 'ruvllm', entries: [] },
|
|
70
|
-
envelope, baseline: document,
|
|
71
|
-
budget: { maxUsd: 0, maxCalls: 5, timeoutMs: 5000, probeUsd: 0, proposeUsd: 0, composeUsd: 0 },
|
|
72
|
-
evaluator: {
|
|
73
|
-
surfaceAware: true,
|
|
74
|
-
async probe({ candidate }) {
|
|
75
|
-
const row = byId.get(candidate.components[0].content.id);
|
|
76
|
-
require(row, 'Unmeasured candidate');
|
|
77
|
-
return { appliedDigest: digestDocument(candidate), score: row.score, costUsd: 0,
|
|
78
|
-
observations: [{ id: 'measured-failure', componentId: 'weight-candidate', message: `Bound evidence ${row.evidenceSha256}` }] };
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
proposer: {
|
|
82
|
-
async propose({ scope }) {
|
|
83
|
-
return { edits: scope === 'domain' ? [{ componentId: 'weight-candidate', content: { id: best.id },
|
|
84
|
-
citations: ['measured-failure'] }] : [], costUsd: 0 };
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
return { schema: 'ruvllm-development-selection/v1', selectedId: result.candidate.components[0].content.id,
|
|
89
|
-
envelopeSha256: hash(envelope), evidenceSha256: hash(all), evidenceMode: 'score-replay',
|
|
90
|
-
result, independentConfirmation: false, productionActivation: false };
|
|
91
|
-
}
|
package/src/cli.mjs
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { runExperiment } from './engine.mjs';
|
|
3
|
-
import { createFixture } from './fixture.mjs';
|
|
4
|
-
|
|
5
|
-
const [command, ...args] = process.argv.slice(2);
|
|
6
|
-
function options(allowed) {
|
|
7
|
-
const result = {};
|
|
8
|
-
for (let i = 0; i < args.length; i += 2) {
|
|
9
|
-
if (!allowed.includes(args[i]) || !args[i + 1] || Object.hasOwn(result, args[i])) throw new Error('Unknown, duplicate or missing argument');
|
|
10
|
-
result[args[i]] = args[i + 1];
|
|
11
|
-
}
|
|
12
|
-
return result;
|
|
13
|
-
}
|
|
14
|
-
try {
|
|
15
|
-
let result;
|
|
16
|
-
if (command === 'run') {
|
|
17
|
-
const flags = options(['--config', '--plan']);
|
|
18
|
-
result = await runExperiment({ configPath: flags['--config'], planPath: flags['--plan'] });
|
|
19
|
-
} else if (command === 'fixture') {
|
|
20
|
-
const flags = options(['--dir', '--binary']);
|
|
21
|
-
if (!flags['--dir'] || !flags['--binary']) throw new Error('fixture requires --dir and --binary');
|
|
22
|
-
result = await runExperiment(await createFixture({ directory: flags['--dir'], binaryPath: flags['--binary'] }));
|
|
23
|
-
} else if (command === '--help' || command === 'help') {
|
|
24
|
-
console.log('Usage: ruvllm-experiment run --config ABS --plan ABS\n ruvllm-experiment fixture --dir NEW_ABS --binary ABS');
|
|
25
|
-
process.exit(0);
|
|
26
|
-
} else throw new Error('Expected run, fixture or --help');
|
|
27
|
-
console.log(JSON.stringify(result, null, 2));
|
|
28
|
-
} catch (error) {
|
|
29
|
-
console.error(JSON.stringify({ ok: false, error: error.message, productionActivation: false })); process.exitCode = 1;
|
|
30
|
-
}
|
package/src/engine.mjs
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
-
import { spawn } from 'node:child_process';
|
|
3
|
-
import { constants } from 'node:fs';
|
|
4
|
-
import { open, lstat, realpath, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
5
|
-
import { resolve, dirname, join, relative, isAbsolute, parse } from 'node:path';
|
|
6
|
-
import { meetsPromotionRule, gateFingerprint } from '@metaharness/flywheel';
|
|
7
|
-
import { selectDevelopmentCandidate } from './adapters.mjs';
|
|
8
|
-
|
|
9
|
-
const MAX_JSON = 1024 * 1024;
|
|
10
|
-
const HASH = /^[a-f0-9]{64}$/;
|
|
11
|
-
const inside = (root, path) => path === root || (!relative(root, path).startsWith('..') && !isAbsolute(relative(root, path)));
|
|
12
|
-
const assert = (condition, message) => { if (!condition) throw new Error(message); };
|
|
13
|
-
export const sha256 = bytes => createHash('sha256').update(bytes).digest('hex');
|
|
14
|
-
|
|
15
|
-
function keys(value, required, optional = []) {
|
|
16
|
-
assert(value && typeof value === 'object' && !Array.isArray(value), 'Expected JSON object');
|
|
17
|
-
assert(required.every(k => Object.hasOwn(value, k)), `Missing fields: ${required.join(', ')}`);
|
|
18
|
-
assert(Object.keys(value).every(k => [...required, ...optional].includes(k)), 'Unknown object fields');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Reject duplicate object keys and non-finite numbers before applying schemas.
|
|
22
|
-
export function parseJson(bytes) {
|
|
23
|
-
const text = bytes.toString('utf8'); let index = 0;
|
|
24
|
-
const ws = () => { while (/[ \t\r\n]/.test(text[index] ?? '') && index < text.length) index++; };
|
|
25
|
-
function string() {
|
|
26
|
-
const start = index++; let escaped = false;
|
|
27
|
-
while (index < text.length) {
|
|
28
|
-
const c = text[index++];
|
|
29
|
-
if (c === '"' && !escaped) return JSON.parse(text.slice(start, index));
|
|
30
|
-
if (c === '\\' && !escaped) escaped = true; else escaped = false;
|
|
31
|
-
}
|
|
32
|
-
throw new Error('Unterminated JSON string');
|
|
33
|
-
}
|
|
34
|
-
function value(depth = 0) {
|
|
35
|
-
assert(depth < 64, 'JSON nesting limit'); ws();
|
|
36
|
-
if (text[index] === '"') return string();
|
|
37
|
-
if (text[index] === '{') {
|
|
38
|
-
index++; ws(); const result = Object.create(null); const seen = new Set();
|
|
39
|
-
if (text[index] === '}') { index++; return result; }
|
|
40
|
-
while (true) {
|
|
41
|
-
ws(); assert(text[index] === '"', 'Invalid JSON key'); const key = string();
|
|
42
|
-
assert(!seen.has(key), 'Duplicate JSON key'); seen.add(key); ws();
|
|
43
|
-
assert(text[index++] === ':', 'Invalid JSON separator'); result[key] = value(depth + 1); ws();
|
|
44
|
-
const end = text[index++]; if (end === '}') return result; assert(end === ',', 'Invalid JSON object');
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (text[index] === '[') {
|
|
48
|
-
index++; ws(); const result = []; if (text[index] === ']') { index++; return result; }
|
|
49
|
-
while (true) { result.push(value(depth + 1)); ws(); const end = text[index++]; if (end === ']') return result; assert(end === ',', 'Invalid JSON array'); }
|
|
50
|
-
}
|
|
51
|
-
const token = /^(?:true|false|null|-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?)/.exec(text.slice(index));
|
|
52
|
-
assert(token, 'Invalid JSON value'); index += token[0].length; const result = JSON.parse(token[0]);
|
|
53
|
-
assert(typeof result !== 'number' || Number.isFinite(result), 'Non-finite JSON number'); return result;
|
|
54
|
-
}
|
|
55
|
-
const result = value(); ws(); assert(index === text.length, 'Trailing JSON data'); return result;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export async function checkedPath(path, { directory = false, roots } = {}) {
|
|
59
|
-
assert(typeof path === 'string' && isAbsolute(path) && !path.includes('\0'), 'Expected absolute path');
|
|
60
|
-
assert(path === resolve(path), 'Path must be canonical without traversal');
|
|
61
|
-
let cursor = parse(path).root;
|
|
62
|
-
for (const part of path.slice(cursor.length).split('/').filter(Boolean)) {
|
|
63
|
-
cursor = join(cursor, part); const stat = await lstat(cursor); assert(!stat.isSymbolicLink(), 'Symlinks are forbidden');
|
|
64
|
-
}
|
|
65
|
-
const canonical = await realpath(path); const stat = await lstat(canonical);
|
|
66
|
-
assert(directory ? stat.isDirectory() : stat.isFile(), directory ? 'Expected directory' : 'Expected regular file');
|
|
67
|
-
if (roots) assert(roots.some(root => inside(root, canonical)), 'Path outside configured read roots');
|
|
68
|
-
return canonical;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async function boundedRead(path, limit = MAX_JSON) {
|
|
72
|
-
const file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
73
|
-
try {
|
|
74
|
-
const stat = await file.stat(); assert(stat.isFile() && stat.size <= limit, 'Control file too large or not regular');
|
|
75
|
-
const bytes = Buffer.alloc(stat.size); const { bytesRead } = await file.read(bytes, 0, bytes.length, 0);
|
|
76
|
-
assert(bytesRead === bytes.length, 'Control file changed during read'); return bytes;
|
|
77
|
-
} finally { await file.close(); }
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export async function fileDigest(path) {
|
|
81
|
-
const file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
82
|
-
try {
|
|
83
|
-
assert((await file.stat()).isFile(), 'Expected regular file');
|
|
84
|
-
const hash = createHash('sha256'); const bytes = Buffer.alloc(1024 * 1024); let position = 0;
|
|
85
|
-
while (true) { const { bytesRead } = await file.read(bytes, 0, bytes.length, position); if (!bytesRead) break; hash.update(bytes.subarray(0, bytesRead)); position += bytesRead; }
|
|
86
|
-
return hash.digest('hex');
|
|
87
|
-
} finally { await file.close(); }
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
async function identicalFiles(a, b) {
|
|
91
|
-
const first = await open(a, constants.O_RDONLY | constants.O_NOFOLLOW), second = await open(b, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
92
|
-
try {
|
|
93
|
-
const size = (await first.stat()).size; if (size !== (await second.stat()).size) return false;
|
|
94
|
-
const x = Buffer.alloc(Math.min(size, 1024 * 1024)), y = Buffer.alloc(x.length);
|
|
95
|
-
for (let position = 0; position < size; position += x.length) {
|
|
96
|
-
const length = Math.min(x.length, size - position);
|
|
97
|
-
const [rx, ry] = await Promise.all([first.read(x, 0, length, position), second.read(y, 0, length, position)]);
|
|
98
|
-
if (rx.bytesRead !== length || ry.bytesRead !== length || !x.subarray(0, length).equals(y.subarray(0, length))) return false;
|
|
99
|
-
}
|
|
100
|
-
return true;
|
|
101
|
-
} finally { await first.close(); await second.close(); }
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
async function save(path, value) { await writeFile(path, JSON.stringify(value, null, 2) + '\n', { flag: 'wx', mode: 0o600 }); }
|
|
105
|
-
|
|
106
|
-
async function runtime(configPath) {
|
|
107
|
-
configPath = await checkedPath(configPath); const bytes = await boundedRead(configPath); const config = parseJson(bytes);
|
|
108
|
-
keys(config, ['schema', 'binaryPath', 'binarySha256', 'readRoots', 'writeRoot', 'policySha256s', 'maxCandidates', 'timeoutMs']);
|
|
109
|
-
assert(config.schema === 'ruvllm-experiment-runtime/v1', 'Unsupported runtime schema');
|
|
110
|
-
assert(HASH.test(config.binarySha256), 'Invalid binary digest');
|
|
111
|
-
assert(Array.isArray(config.readRoots) && config.readRoots.length > 0 && config.readRoots.length <= 32, 'Invalid read roots');
|
|
112
|
-
assert(Array.isArray(config.policySha256s) && config.policySha256s.length > 0 && config.policySha256s.length <= 128 && config.policySha256s.every(x => HASH.test(x)), 'Invalid approved policy digests');
|
|
113
|
-
assert(Number.isInteger(config.maxCandidates) && config.maxCandidates >= 1 && config.maxCandidates <= 16, 'Candidate limit must be 1..16');
|
|
114
|
-
assert(Number.isInteger(config.timeoutMs) && config.timeoutMs >= 100 && config.timeoutMs <= 300000, 'Invalid timeout');
|
|
115
|
-
config.readRoots = await Promise.all(config.readRoots.map(path => checkedPath(path, { directory: true })));
|
|
116
|
-
config.writeRoot = await checkedPath(config.writeRoot, { directory: true });
|
|
117
|
-
config.binaryPath = await checkedPath(config.binaryPath);
|
|
118
|
-
assert(!inside(config.writeRoot, configPath) && !inside(config.writeRoot, config.binaryPath), 'Runtime config and binary must be outside write root');
|
|
119
|
-
const stat = await lstat(configPath); assert((stat.mode & 0o077) === 0, 'Runtime config must be owner-only');
|
|
120
|
-
assert(((await lstat(config.writeRoot)).mode & 0o077) === 0, 'Write root must be private');
|
|
121
|
-
assert(await fileDigest(config.binaryPath) === config.binarySha256, 'Binary digest mismatch');
|
|
122
|
-
return { ...config, configSha256: sha256(bytes) };
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async function native(config, request) {
|
|
126
|
-
assert(await fileDigest(config.binaryPath) === config.binarySha256, 'Binary digest mismatch');
|
|
127
|
-
const input = JSON.stringify(request); assert(Buffer.byteLength(input) <= 64 * 1024, 'Native request limit');
|
|
128
|
-
return new Promise((accept, reject) => {
|
|
129
|
-
const environment = Object.fromEntries(['PATH', 'HOME', 'TMPDIR', 'LANG', 'LC_ALL'].filter(k => process.env[k]).map(k => [k, process.env[k]]));
|
|
130
|
-
const child = spawn(config.binaryPath, [], { stdio: ['pipe', 'pipe', 'pipe'], env: environment, shell: false });
|
|
131
|
-
let stdout = [], stderr = [], outSize = 0, errSize = 0, failure;
|
|
132
|
-
const fail = message => { failure ??= new Error(message); child.kill('SIGKILL'); };
|
|
133
|
-
const timer = setTimeout(() => fail('Native operation timed out'), config.timeoutMs);
|
|
134
|
-
child.stdout.on('data', bytes => { outSize += bytes.length; if (outSize > MAX_JSON) fail('Native stdout limit'); else stdout.push(bytes); });
|
|
135
|
-
child.stderr.on('data', bytes => { errSize += bytes.length; if (errSize > 64 * 1024) fail('Native stderr limit'); else stderr.push(bytes); });
|
|
136
|
-
child.on('error', error => { clearTimeout(timer); reject(error); });
|
|
137
|
-
child.stdin.on('error', () => {});
|
|
138
|
-
child.on('close', code => {
|
|
139
|
-
clearTimeout(timer); if (failure) return reject(failure);
|
|
140
|
-
if (code !== 0) return reject(new Error(`Native ${request.op} rejected: ${Buffer.concat(stderr).toString('utf8').slice(0, 2048)}`));
|
|
141
|
-
try { accept(parseJson(Buffer.concat(stdout))); } catch (error) { reject(error); }
|
|
142
|
-
});
|
|
143
|
-
child.stdin.end(input);
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export async function runExperiment({ configPath, planPath }) {
|
|
148
|
-
const config = await runtime(configPath); planPath = await checkedPath(planPath, { roots: config.readRoots });
|
|
149
|
-
const planBytes = await boundedRead(planPath), plan = parseJson(planBytes);
|
|
150
|
-
keys(plan, ['schema', 'evidenceMode', 'source', 'policy', 'candidates']);
|
|
151
|
-
assert(plan.schema === 'ruvllm-experiment-plan/v1', 'Unsupported plan schema');
|
|
152
|
-
assert(['fixture', 'external'].includes(plan.evidenceMode), 'Explicit fixture or external evidence mode required');
|
|
153
|
-
assert(Array.isArray(plan.candidates) && plan.candidates.length >= 1 && plan.candidates.length <= config.maxCandidates, 'Candidate limit exceeded');
|
|
154
|
-
const source = await checkedPath(plan.source, { roots: config.readRoots });
|
|
155
|
-
const policyPath = await checkedPath(plan.policy, { roots: config.readRoots });
|
|
156
|
-
const policyBytes = await boundedRead(policyPath), policy = parseJson(policyBytes), policySha256 = sha256(policyBytes);
|
|
157
|
-
assert(config.policySha256s.includes(policySha256), 'Policy is not approved');
|
|
158
|
-
assert(Array.isArray(policy.allowed_tensors) && policy.allowed_tensors.length > 0 && policy.allowed_tensors.length <= 256, 'Invalid tensor selection');
|
|
159
|
-
const ids = new Set(), candidates = [];
|
|
160
|
-
for (const candidate of plan.candidates) {
|
|
161
|
-
keys(candidate, ['id', 'patch'], ['evaluation']);
|
|
162
|
-
assert(typeof candidate.id === 'string' && /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/.test(candidate.id) && !ids.has(candidate.id), 'Invalid or duplicate candidate id'); ids.add(candidate.id);
|
|
163
|
-
const patchPath = await checkedPath(candidate.patch, { roots: config.readRoots }), patchBytes = await boundedRead(patchPath);
|
|
164
|
-
const entry = { ...candidate, patchBytes, patch: parseJson(patchBytes) };
|
|
165
|
-
if (candidate.evaluation) { const path = await checkedPath(candidate.evaluation, { roots: config.readRoots }); entry.evaluationBytes = await boundedRead(path); entry.evaluationValue = parseJson(entry.evaluationBytes); }
|
|
166
|
-
candidates.push(entry);
|
|
167
|
-
}
|
|
168
|
-
const runDirectory = join(config.writeRoot, `run-${randomUUID()}`); await mkdir(runDirectory, { mode: 0o700 });
|
|
169
|
-
await writeFile(join(runDirectory, 'plan.json'), planBytes, { flag: 'wx', mode: 0o600 });
|
|
170
|
-
const copiedPolicy = join(runDirectory, 'policy.json'); await writeFile(copiedPolicy, policyBytes, { flag: 'wx', mode: 0o600 });
|
|
171
|
-
const inspection = await native(config, { op: 'inspect', source, tensors: policy.allowed_tensors });
|
|
172
|
-
const reportPath = join(runDirectory, 'report.json');
|
|
173
|
-
const report = { schema: 'ruvllm-experiment-report/v1', evidenceMode: plan.evidenceMode, sourceSha256: inspection.source_sha256,
|
|
174
|
-
policySha256, planSha256: sha256(planBytes), binarySha256: config.binarySha256, configSha256: config.configSha256,
|
|
175
|
-
gateSha256: gateFingerprint(meetsPromotionRule), runDirectory, reportPath, productionActivation: false, activationAuthorized: false,
|
|
176
|
-
inferencePerformed: false, independentConfirmation: false, evaluationTrust: 'caller-supplied; not independent attestation', costMetered: false, candidates: [], selectedCandidateId: null };
|
|
177
|
-
let sharedEvaluation, baselineScore;
|
|
178
|
-
for (const candidate of candidates) {
|
|
179
|
-
const output = join(runDirectory, candidate.id); await mkdir(output, { mode: 0o700 });
|
|
180
|
-
const patch = join(output, 'patch.json'), checkpoint = join(output, 'candidate.safetensors'), receiptPath = join(output, 'receipt.json');
|
|
181
|
-
await writeFile(patch, candidate.patchBytes, { flag: 'wx', mode: 0o600 });
|
|
182
|
-
const result = { id: candidate.id, status: 'rejected', patchSha256: sha256(candidate.patchBytes), rollbackExact: false, rollbackVerified: false, rvfVerified: false, productionActivation: false };
|
|
183
|
-
let receipt;
|
|
184
|
-
try {
|
|
185
|
-
assert(candidate.patch.source_sha256 === report.sourceSha256, 'Patch source mismatch');
|
|
186
|
-
receipt = await native(config, { op: 'patch', source, output: checkpoint, patch, policy: copiedPolicy });
|
|
187
|
-
assert(receipt.source_sha256 === report.sourceSha256 && receipt.policy_sha256 === policySha256 && receipt.patch_sha256 === result.patchSha256 && receipt.activation_authorized === false, 'Native receipt binding mismatch');
|
|
188
|
-
await save(receiptPath, receipt); result.candidateSha256 = receipt.candidate_sha256; result.status = 'unqualified';
|
|
189
|
-
let evaluationPath;
|
|
190
|
-
if (candidate.evaluationBytes) {
|
|
191
|
-
evaluationPath = join(output, 'evaluation.json'); await writeFile(evaluationPath, candidate.evaluationBytes, { flag: 'wx', mode: 0o600 });
|
|
192
|
-
const value = candidate.evaluationValue;
|
|
193
|
-
result.evaluationSha256 = sha256(candidate.evaluationBytes);
|
|
194
|
-
// All candidates must use the same suite, baseline, runtime and protocol.
|
|
195
|
-
const signature = JSON.stringify([value.suite_sha256, value.protocol_sha256, value.baseline, value.total, value.baseline_correct, value.baseline_truncated, value.baseline_output_sha256]);
|
|
196
|
-
const validation = await native(config, { op: 'evaluate', evaluation: evaluationPath, receipt: receiptPath });
|
|
197
|
-
assert(validation.valid === true && validation.activation_authorized === false, 'Evaluation not valid');
|
|
198
|
-
if (sharedEvaluation) assert(sharedEvaluation === signature, 'Candidates evaluated against different baselines or suites'); else sharedEvaluation = signature;
|
|
199
|
-
const total = value.total;
|
|
200
|
-
assert(Number.isInteger(total) && total > 0, 'Evaluation total must be positive');
|
|
201
|
-
const score = (correct, truncated) => ({ primary: correct / total, noopRate: truncated / total, costPerWin: 0, regressed: false });
|
|
202
|
-
baselineScore = value.baseline_correct / total;
|
|
203
|
-
const gate = meetsPromotionRule({ baseline: score(value.baseline_correct, value.baseline_truncated), candidate: score(value.candidate_correct, value.candidate_truncated) });
|
|
204
|
-
if (value.candidate_correct <= value.baseline_correct) { gate.promote = false; gate.reasons.push('no_strict_accuracy_improvement'); }
|
|
205
|
-
result.gate = { ...gate, meaning: 'research qualification only; no activation authority' };
|
|
206
|
-
result.score = score(value.candidate_correct, value.candidate_truncated);
|
|
207
|
-
result.status = gate.promote ? 'qualified' : 'unqualified';
|
|
208
|
-
} else result.gate = { promote: false, reasons: ['missing_evaluation'] };
|
|
209
|
-
const artifact = join(output, 'evidence.rvf');
|
|
210
|
-
const exported = await native(config, { op: 'export', patch, policy: copiedPolicy, receipt: receiptPath, output: artifact, ...(evaluationPath ? { evaluation: evaluationPath } : {}) });
|
|
211
|
-
const verified = await native(config, { op: 'verify', artifact, expected_sha256: exported.sha256 });
|
|
212
|
-
assert(verified.integrity_verified === true && verified.activation_authorized === false, 'RVF verification failed'); result.rvfSha256 = exported.sha256; result.rvfVerified = true;
|
|
213
|
-
} catch (error) { result.status = 'rejected'; result.error = error.message; }
|
|
214
|
-
finally {
|
|
215
|
-
if (receipt) {
|
|
216
|
-
const restored = join(output, 'restored.safetensors');
|
|
217
|
-
const rollback = await native(config, { op: 'rollback', source: checkpoint, output: restored, patch, policy: copiedPolicy, receipt: receiptPath });
|
|
218
|
-
result.restoredSha256 = rollback.candidate_sha256;
|
|
219
|
-
result.rollbackExact = result.rollbackVerified = rollback.candidate_sha256 === report.sourceSha256 && await identicalFiles(source, restored);
|
|
220
|
-
assert(result.rollbackExact, 'Rollback did not restore original bytes');
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
report.candidates.push(result);
|
|
224
|
-
}
|
|
225
|
-
assert(await fileDigest(source) === report.sourceSha256, 'Source checkpoint changed during experiment');
|
|
226
|
-
const qualified = report.candidates.filter(candidate => candidate.status === 'qualified');
|
|
227
|
-
qualified.sort((a, b) => b.score.primary - a.score.primary || a.score.noopRate - b.score.noopRate || a.id.localeCompare(b.id));
|
|
228
|
-
if (qualified.length) {
|
|
229
|
-
report.developmentSelection = await selectDevelopmentCandidate({
|
|
230
|
-
baseline: { id: 'source.baseline', score: baselineScore, evidenceSha256: report.sourceSha256 },
|
|
231
|
-
candidates: qualified.map(candidate => ({ id: candidate.id, score: candidate.score.primary, evidenceSha256: candidate.evaluationSha256 })),
|
|
232
|
-
envelope: Object.fromEntries(['sourceSha256', 'policySha256', 'binarySha256', 'gateSha256', 'planSha256'].map(key => [key, report[key]])),
|
|
233
|
-
});
|
|
234
|
-
assert(qualified.some(candidate => candidate.id === report.developmentSelection.selectedId), 'Darwin selected an unqualified candidate');
|
|
235
|
-
report.selectedCandidateId = report.developmentSelection.selectedId;
|
|
236
|
-
}
|
|
237
|
-
await save(reportPath, report); return report;
|
|
238
|
-
}
|