harness-everything 1.3.2 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.github/workflows/release.yml +23 -6
- package/CHANGELOG.md +42 -0
- package/RELEASING.md +2 -0
- package/ci/fixtures/system-one-colab-fit-layer-sitecustomize.py +72 -0
- package/ci/mechanism-2x-release-automation.test.js +17 -0
- package/ci/mechanism-system-one-colab.test.js +528 -0
- package/ci/mechanism-system-one-contract.test.js +30 -0
- package/ci/mechanism-system-one-curves.test.js +85 -0
- package/ci/mechanism-system-one-cycle.test.js +344 -34
- package/ci/mechanism-system-one-install.test.js +47 -0
- package/ci/mechanism-system-one-provider.test.js +2 -0
- package/ci/mechanism-system-one-resident.test.js +69 -0
- package/ci/system-one-adapter-test.py +86 -0
- package/ci/system-one-fit-layer-test.py +371 -0
- package/ci/system-one-layer-test.py +122 -0
- package/ci/system-one-train-test.py +26 -0
- package/docs/system-one-cycle.md +10 -0
- package/docs/system-one-training.md +3 -1
- package/harness-everything/SKILL.md +1 -1
- package/harness-everything/scripts/system-one/cua_adapter.py +36 -1
- package/harness-everything/scripts/system-one/install.js +10 -0
- package/harness-everything/scripts/system-one/layer.py +178 -0
- package/harness-everything/scripts/system-one/manifest.js +8 -1
- package/harness-everything/scripts/system-one/provider.js +12 -2
- package/opencode-plugin/plugin.json +1 -1
- package/package.json +1 -1
- package/plugins/harness-everything/.antigravity-plugin/plugin.json +1 -1
- package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
- package/plugins/harness-everything/plugin.json +1 -1
- package/plugins/harness-everything/skills/harness-everything/SKILL.md +1 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/cua_adapter.py +36 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/install.js +10 -0
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/layer.py +178 -0
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/manifest.js +8 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/provider.js +12 -2
- package/sbom.cdx.json +7 -7
- package/scripts/system-one-colab.js +240 -0
- package/scripts/system-one-curves.js +52 -8
- package/scripts/system-one-cycle/evaluate.js +56 -5
- package/scripts/system-one-cycle/package.js +61 -3
- package/scripts/system-one-cycle/score.py +23 -2
- package/scripts/system-one-cycle/train.js +212 -20
- package/scripts/system-one-fit-layer.py +369 -0
- package/scripts/system-one-train.py +36 -9
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
const fs = require('node:fs');
|
|
5
|
+
const crypto = require('node:crypto');
|
|
5
6
|
const path = require('node:path');
|
|
6
7
|
const { isDeepStrictEqual } = require('node:util');
|
|
7
8
|
const { STAGES, validateVersionManifest } = require('../harness-everything/scripts/system-one/manifest');
|
|
@@ -15,6 +16,7 @@ const fail = () => { throw new TypeError('invalid-system-one-curves-input'); };
|
|
|
15
16
|
const isObject = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
16
17
|
const isText = value => typeof value === 'string' && value.trim().length > 0;
|
|
17
18
|
const isProbability = value => Number.isFinite(value) && value >= 0 && value <= 1;
|
|
19
|
+
const hasLayeredStages = manifest => Object.values(manifest.stages).some(entry => Object.hasOwn(entry, 'layer'));
|
|
18
20
|
|
|
19
21
|
function readJsonl(file) {
|
|
20
22
|
let lines;
|
|
@@ -27,12 +29,40 @@ function readManifest(dir, version) {
|
|
|
27
29
|
let manifest;
|
|
28
30
|
try { manifest = JSON.parse(fs.readFileSync(path.join(dir, 'manifest.json'), 'utf8')); } catch (_) { fail(); }
|
|
29
31
|
try { validateVersionManifest(manifest, version); } catch (_) { fail(); }
|
|
32
|
+
const layered = hasLayeredStages(manifest);
|
|
30
33
|
for (const entry of Object.values(manifest.stages)) {
|
|
31
|
-
|
|
34
|
+
const weights = path.join(dir, entry.weights);
|
|
35
|
+
const config = path.join(dir, entry.config);
|
|
36
|
+
if (!fs.existsSync(weights) || !fs.existsSync(config)) fail();
|
|
37
|
+
if (layered && Object.hasOwn(entry, 'layer')
|
|
38
|
+
&& crypto.createHash('sha256').update(fs.readFileSync(weights)).digest('hex') !== entry.sha256) fail();
|
|
39
|
+
if (Object.hasOwn(entry, 'layer') || Object.hasOwn(entry, 'layerSha256')) {
|
|
40
|
+
if (!isText(entry.layer) || !/^[a-f0-9]{64}$/.test(entry.layerSha256 || '')) fail();
|
|
41
|
+
const layerPath = path.join(dir, entry.layer);
|
|
42
|
+
let stat;
|
|
43
|
+
try { stat = fs.statSync(layerPath); } catch (_) { fail(); }
|
|
44
|
+
if (!stat.isFile() || stat.size > 32 * 1024 * 1024
|
|
45
|
+
|| crypto.createHash('sha256').update(fs.readFileSync(layerPath)).digest('hex') !== entry.layerSha256) fail();
|
|
46
|
+
}
|
|
32
47
|
}
|
|
33
48
|
return manifest;
|
|
34
49
|
}
|
|
35
50
|
|
|
51
|
+
function candidateDigest(dir, manifest) {
|
|
52
|
+
const stages = Object.fromEntries(Object.entries(manifest.stages).map(([name, entry]) => {
|
|
53
|
+
const artifactHash = file => crypto.createHash('sha256').update(fs.readFileSync(path.join(dir, file))).digest('hex');
|
|
54
|
+
return [name, { weights: artifactHash(entry.weights), config: artifactHash(entry.config),
|
|
55
|
+
layer: entry.layer ? entry.layerSha256 : null, options: entry.options, thresholds: entry.thresholds,
|
|
56
|
+
referenceOnly: entry.referenceOnly || [] }];
|
|
57
|
+
}));
|
|
58
|
+
return crypto.createHash('sha256').update(JSON.stringify(stages)).digest('hex');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function scoreDigests(files) {
|
|
62
|
+
return Object.fromEntries(Object.entries(files).map(([stage, file]) => [stage,
|
|
63
|
+
crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex')]));
|
|
64
|
+
}
|
|
65
|
+
|
|
36
66
|
function positives(row, stage, options) {
|
|
37
67
|
if (stage === 'validity') {
|
|
38
68
|
if (!['invalid', 'actionable'].includes(row.gold) || options.length !== 1 || options[0] !== 'invalid') fail();
|
|
@@ -42,8 +72,8 @@ function positives(row, stage, options) {
|
|
|
42
72
|
if (!isText(row.gold) || !options.includes(row.gold)) fail();
|
|
43
73
|
return new Set([row.gold]);
|
|
44
74
|
}
|
|
45
|
-
const gold = Array.isArray(row.gold) ? row.gold : [row.gold];
|
|
46
|
-
if (gold.some(id => !isText(id) || !options.includes(id)) || new Set(gold).size !== gold.length) fail();
|
|
75
|
+
const gold = [...(Array.isArray(row.gold) ? row.gold : [row.gold]), ...(row.secondary || [])];
|
|
76
|
+
if (!gold.length || gold.some(id => !isText(id) || !options.includes(id)) || new Set(gold).size !== gold.length) fail();
|
|
47
77
|
return new Set(gold);
|
|
48
78
|
}
|
|
49
79
|
|
|
@@ -51,8 +81,9 @@ function readRows(file, stage, options) {
|
|
|
51
81
|
const rows = readJsonl(file);
|
|
52
82
|
const ids = new Set();
|
|
53
83
|
return rows.map(row => {
|
|
54
|
-
if (!isObject(row) || Object.keys(row).length
|
|
84
|
+
if (!isObject(row) || ![3, 4].includes(Object.keys(row).length) || !Object.hasOwn(row, 'id')
|
|
55
85
|
|| !Object.hasOwn(row, 'gold') || !Object.hasOwn(row, 'scores') || !isText(row.id) || ids.has(row.id)
|
|
86
|
+
|| (Object.hasOwn(row, 'secondary') && (!Array.isArray(row.secondary) || stage !== 'intent'))
|
|
56
87
|
|| !isObject(row.scores) || Object.keys(row.scores).length !== options.length
|
|
57
88
|
|| options.some(option => !Object.hasOwn(row.scores, option) || !isProbability(row.scores[option]))) fail();
|
|
58
89
|
ids.add(row.id);
|
|
@@ -283,10 +314,13 @@ function assertVersionReusable(history, curves) {
|
|
|
283
314
|
return existing;
|
|
284
315
|
}
|
|
285
316
|
|
|
286
|
-
function validateSavedCurves(curves, version, manifest) {
|
|
317
|
+
function validateSavedCurves(curves, version, manifest, digest, expectedScores) {
|
|
287
318
|
validateCurveRecord(curves);
|
|
288
319
|
if (curves.version !== version || Object.keys(curves.stages).length !== Object.keys(manifest.stages).length
|
|
289
320
|
|| Object.keys(curves.stages).some(stage => !Object.hasOwn(manifest.stages, stage))) fail();
|
|
321
|
+
const layered = hasLayeredStages(manifest);
|
|
322
|
+
if (layered && curves.candidateDigest !== digest) fail();
|
|
323
|
+
if (layered && (!expectedScores || !isDeepStrictEqual(curves.scoreDigests, expectedScores))) fail();
|
|
290
324
|
}
|
|
291
325
|
|
|
292
326
|
function validateSavedTrend(trend, version) {
|
|
@@ -400,7 +434,7 @@ function parseArgs(argv) {
|
|
|
400
434
|
}
|
|
401
435
|
if (!isText(parsed.version) || !isText(parsed.versionDir) || !isText(parsed.history) || !isText(parsed.out)) fail();
|
|
402
436
|
if (parsed.resumeCurves) {
|
|
403
|
-
if (!isText(parsed.resumeCurves)
|
|
437
|
+
if (!isText(parsed.resumeCurves)) fail();
|
|
404
438
|
} else if (!parsed.val.length) fail();
|
|
405
439
|
return parsed;
|
|
406
440
|
}
|
|
@@ -409,13 +443,21 @@ function run(argv) {
|
|
|
409
443
|
const args = parseArgs(argv);
|
|
410
444
|
args.history = assertPrivateHistoryFile(args.history);
|
|
411
445
|
const manifest = readManifest(args.versionDir, args.version);
|
|
446
|
+
const layered = hasLayeredStages(manifest);
|
|
447
|
+
if (args.resumeCurves && !layered && (args.val.length || args.holdout.length)) fail();
|
|
448
|
+
const digest = layered ? candidateDigest(args.versionDir, manifest) : null;
|
|
412
449
|
if (args.resumeCurves) {
|
|
450
|
+
const valFiles = stageFiles(args, 'val');
|
|
451
|
+
const holdoutFiles = stageFiles(args, 'holdout');
|
|
413
452
|
let curves; let trend;
|
|
414
453
|
try {
|
|
415
454
|
curves = JSON.parse(fs.readFileSync(args.resumeCurves, 'utf8'));
|
|
416
455
|
trend = JSON.parse(fs.readFileSync(path.join(args.out, 'trend.json'), 'utf8'));
|
|
417
456
|
} catch (_) { fail(); }
|
|
418
|
-
|
|
457
|
+
const expectedScores = layered && Object.keys(valFiles).length && Object.keys(holdoutFiles).length
|
|
458
|
+
? { validation: scoreDigests(valFiles), holdout: scoreDigests(holdoutFiles) } : null;
|
|
459
|
+
if (layered && (!expectedScores || !isDeepStrictEqual(Object.keys(valFiles).sort(), Object.keys(holdoutFiles).sort()))) fail();
|
|
460
|
+
validateSavedCurves(curves, args.version, manifest, digest, expectedScores);
|
|
419
461
|
validateSavedTrend(trend, args.version);
|
|
420
462
|
const history = readHistory(args.history);
|
|
421
463
|
validateBaselineReferences(curves, history);
|
|
@@ -445,7 +487,9 @@ function run(argv) {
|
|
|
445
487
|
const history = readHistory(args.history);
|
|
446
488
|
if (history.some(row => row.version === args.version)) throw new TypeError(VERSION_ALREADY_RECORDED);
|
|
447
489
|
const floor = assessFloor(Object.keys(holdoutMetrics).length ? holdoutMetrics : null, history);
|
|
448
|
-
const curves = { schemaVersion: 1, version: args.version, createdAt: new Date().toISOString(),
|
|
490
|
+
const curves = { schemaVersion: 1, version: args.version, createdAt: new Date().toISOString(),
|
|
491
|
+
...(layered ? { candidateDigest: digest,
|
|
492
|
+
scoreDigests: { validation: scoreDigests(valFiles), holdout: scoreDigests(holdoutFiles) } } : {}), stages, floor };
|
|
449
493
|
validateBaselineReferences(curves, history);
|
|
450
494
|
const trend = decideTrend(curves, history, floor);
|
|
451
495
|
fs.mkdirSync(args.out, { recursive: true });
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const crypto = require('node:crypto');
|
|
3
4
|
const fs = require('node:fs');
|
|
4
5
|
const path = require('node:path');
|
|
5
6
|
const { spawnSync } = require('node:child_process');
|
|
6
7
|
const { REPO, dataPath, writeJson, assertPrivateDataDir, assertPrivateHistoryFile } = require('./common');
|
|
7
8
|
const { buildVersion } = require('./package');
|
|
8
|
-
const { TASKS } = require('./train');
|
|
9
|
+
const { TASKS, fitLayerStage, hasTrainerReport } = require('./train');
|
|
9
10
|
const { validateVersionManifest } = require('../../harness-everything/scripts/system-one/manifest');
|
|
10
11
|
|
|
11
12
|
const HOLDOUTS = { validity: 'system-one-holdout.json', tier: 'system-one-holdout.json', intent: 'system-one-intent-holdout.json' };
|
|
@@ -29,6 +30,40 @@ function recordEvaluation(manifestFile, version) {
|
|
|
29
30
|
return manifest;
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
function verifyLayerPair(versionDir, sourceDir, outcomes) {
|
|
34
|
+
const manifestFile = path.join(versionDir, 'manifest.json');
|
|
35
|
+
const manifest = JSON.parse(fs.readFileSync(manifestFile, 'utf8'));
|
|
36
|
+
validateVersionManifest(manifest);
|
|
37
|
+
const digest = file => crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex');
|
|
38
|
+
for (const task of TASKS) {
|
|
39
|
+
const entry = manifest.stages[task];
|
|
40
|
+
const outcome = outcomes[task];
|
|
41
|
+
if (!outcome) throw new Error(`${task} candidate fit outcome is missing`);
|
|
42
|
+
if (entry.weights !== `${task}.safetensors` || entry.config !== `${task}.json`)
|
|
43
|
+
throw new Error(`${task} candidate manifest paths do not match the scorer checkpoint files`);
|
|
44
|
+
const runDir = path.join(sourceDir, task);
|
|
45
|
+
const calibration = JSON.parse(fs.readFileSync(path.join(runDir, 'calibration.json'), 'utf8'));
|
|
46
|
+
const expectedThresholds = Object.fromEntries(entry.options.map(id => [id,
|
|
47
|
+
calibration.thresholds?.[id] === null ? 1 : calibration.thresholds?.[id]]));
|
|
48
|
+
if (JSON.stringify(expectedThresholds) !== JSON.stringify(entry.thresholds))
|
|
49
|
+
throw new Error(`${task} candidate thresholds do not match the current validated calibration`);
|
|
50
|
+
if (entry.sha256 !== outcome.checkpointSha256)
|
|
51
|
+
throw new Error(`${task} candidate checkpoint does not match its fit outcome`);
|
|
52
|
+
if (!/^[a-f0-9]{64}$/.test(outcome.checkpointConfigSha256 || '')
|
|
53
|
+
|| digest(path.join(versionDir, entry.config)) !== outcome.checkpointConfigSha256)
|
|
54
|
+
throw new Error(`${task} candidate checkpoint config does not match its fit outcome`);
|
|
55
|
+
if (outcome.outcome === 'layer') {
|
|
56
|
+
if (!entry.layer || entry.layerSha256 !== digest(path.join(sourceDir, task, 'layer.json'))
|
|
57
|
+
|| entry.layerSha256 !== outcome.layerSha256 || entry.sha256 !== outcome.checkpointSha256) {
|
|
58
|
+
throw new Error(`${task} candidate layer does not match its fit`);
|
|
59
|
+
}
|
|
60
|
+
} else if (entry.layer || outcome.outcome !== 'keep-base') {
|
|
61
|
+
throw new Error(`${task} candidate layer fit is missing or inconsistent`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return manifest;
|
|
65
|
+
}
|
|
66
|
+
|
|
32
67
|
function evaluateCycle({ dataDir, version, history: historyOption }) {
|
|
33
68
|
const privateDir = assertPrivateDataDir(dataDir);
|
|
34
69
|
const history = assertPrivateHistoryFile(historyOption === undefined
|
|
@@ -40,15 +75,30 @@ function evaluateCycle({ dataDir, version, history: historyOption }) {
|
|
|
40
75
|
const trendFile = path.join(evaluationDir, 'trend.json');
|
|
41
76
|
const curvesScript = path.join(REPO, 'scripts', 'system-one-curves.js');
|
|
42
77
|
if (!fs.existsSync(curvesScript)) throw new Error('contract C curves CLI is not available in this checkout');
|
|
78
|
+
const outcomes = Object.fromEntries(TASKS.map(task => {
|
|
79
|
+
const runDir = path.join(source, task);
|
|
80
|
+
const hasFitInputs = hasTrainerReport(runDir, task);
|
|
81
|
+
return [task, hasFitInputs ? fitLayerStage({ dataDir: privateDir, runDir, task }) : null];
|
|
82
|
+
}));
|
|
43
83
|
if (fs.existsSync(curvesFile) && fs.existsSync(trendFile)) {
|
|
44
|
-
|
|
45
|
-
|
|
84
|
+
const candidate = verifyLayerPair(versionDir, source, outcomes);
|
|
85
|
+
const resumeArgs = [curvesScript, '--version', version, '--version-dir', versionDir,
|
|
86
|
+
'--history', history, '--out', evaluationDir, '--resume-curves', curvesFile];
|
|
87
|
+
if (Object.values(candidate.stages).some(stage => stage.layer)) {
|
|
88
|
+
for (const task of TASKS) {
|
|
89
|
+
const validation = candidate.stages[task].layer ? 'val-scores-layered.jsonl' : 'val-scores.jsonl';
|
|
90
|
+
resumeArgs.push('--val-scores', `${task}=${path.join(source, task, validation)}`);
|
|
91
|
+
resumeArgs.push('--holdout-scores', `${task}=${path.join(evaluationDir, `${task}-holdout-scores.jsonl`)}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
runProcess(process.execPath, resumeArgs);
|
|
46
95
|
const manifestFile = path.join(versionDir, 'manifest.json');
|
|
47
96
|
recordEvaluation(manifestFile, version);
|
|
48
97
|
const trend = JSON.parse(fs.readFileSync(trendFile, 'utf8'));
|
|
49
98
|
return { version, verdict: trend.verdict, compared: trend.compared.length, resumed: true };
|
|
50
99
|
}
|
|
51
100
|
buildVersion({ dataDir: privateDir, version, sourceDir: source, versionDir });
|
|
101
|
+
const candidate = verifyLayerPair(versionDir, source, outcomes);
|
|
52
102
|
|
|
53
103
|
fs.mkdirSync(evaluationDir, { recursive: true, mode: 0o700 });
|
|
54
104
|
const scoreScript = path.join(__dirname, 'score.py');
|
|
@@ -58,7 +108,8 @@ function evaluateCycle({ dataDir, version, history: historyOption }) {
|
|
|
58
108
|
const heldOut = path.join(holdoutDir, HOLDOUTS[task]);
|
|
59
109
|
const scores = path.join(evaluationDir, `${task}-holdout-scores.jsonl`);
|
|
60
110
|
runProcess(pythonExecutable(), [scoreScript, '--weights', path.join(versionDir, `${task}.safetensors`), '--holdout', heldOut, '--task', task, '--out', scores]);
|
|
61
|
-
|
|
111
|
+
const validation = candidate.stages[task].layer ? 'val-scores-layered.jsonl' : 'val-scores.jsonl';
|
|
112
|
+
curvesArgs.push('--val-scores', `${task}=${path.join(source, task, validation)}`);
|
|
62
113
|
curvesArgs.push('--holdout-scores', `${task}=${scores}`);
|
|
63
114
|
}
|
|
64
115
|
curvesArgs.push('--history', history, '--out', evaluationDir);
|
|
@@ -70,4 +121,4 @@ function evaluateCycle({ dataDir, version, history: historyOption }) {
|
|
|
70
121
|
return { version, verdict: trend.verdict, compared: trend.compared.length };
|
|
71
122
|
}
|
|
72
123
|
|
|
73
|
-
module.exports = { evaluateCycle, HOLDOUTS };
|
|
124
|
+
module.exports = { evaluateCycle, HOLDOUTS, verifyLayerPair };
|
|
@@ -5,7 +5,7 @@ const fs = require('node:fs');
|
|
|
5
5
|
const path = require('node:path');
|
|
6
6
|
const { spawnSync } = require('node:child_process');
|
|
7
7
|
const { REPO, dataPath, writeJson, assertPrivateDataDir } = require('./common');
|
|
8
|
-
const { TASKS } = require('./train');
|
|
8
|
+
const { TASKS, validateFitStage } = require('./train');
|
|
9
9
|
const { validateVersionManifest } = require('../../harness-everything/scripts/system-one/manifest');
|
|
10
10
|
|
|
11
11
|
function trainerCatalogs() {
|
|
@@ -41,11 +41,40 @@ function copy(source, target) {
|
|
|
41
41
|
if (process.platform !== 'win32') fs.chmodSync(target, 0o600);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
function validatePackagedFitEvidence(runDir, stage, task, checkpointPath, checkpointConfigPath, options, dataDir) {
|
|
45
|
+
const evidence = validateFitStage({ runDir, task, checkpointPath, checkpointConfigPath, dataDir });
|
|
46
|
+
const legacyOptions = task === 'intent' ? options.filter(id => id !== 'unclassified') : options;
|
|
47
|
+
if (evidence.report.catalog.join('\0') !== options.join('\0')
|
|
48
|
+
|| (stage.options.join('\0') !== options.join('\0') && stage.options.join('\0') !== legacyOptions.join('\0')))
|
|
49
|
+
throw new Error(`${task} candidate fit evidence is stale`);
|
|
50
|
+
const thresholds = Object.fromEntries(stage.options.map(id => [id,
|
|
51
|
+
evidence.calibration.thresholds[id] === null ? 1 : evidence.calibration.thresholds[id]]));
|
|
52
|
+
if (JSON.stringify(thresholds) !== JSON.stringify(stage.thresholds))
|
|
53
|
+
throw new Error(`${task} candidate thresholds do not match their bound calibration`);
|
|
54
|
+
return evidence;
|
|
55
|
+
}
|
|
56
|
+
|
|
44
57
|
function safeRelative(value) {
|
|
45
58
|
return typeof value === 'string' && value.length > 0 && !path.isAbsolute(value)
|
|
46
59
|
&& !value.split(/[\\/]/).some(part => part === '..' || part === '.');
|
|
47
60
|
}
|
|
48
61
|
|
|
62
|
+
function readLayer(source, task, options, expectedHash = null) {
|
|
63
|
+
const stat = fs.statSync(source);
|
|
64
|
+
if (!stat.isFile() || stat.size > 32 * 1024 * 1024) throw new Error(`${task} layer artifact is invalid`);
|
|
65
|
+
const actualHash = digest(source);
|
|
66
|
+
if (expectedHash && actualHash !== expectedHash) throw new Error(`${task} layer hash does not match its manifest`);
|
|
67
|
+
let layer;
|
|
68
|
+
try { layer = JSON.parse(fs.readFileSync(source, 'utf8')); }
|
|
69
|
+
catch { throw new Error(`${task} layer artifact is invalid`); }
|
|
70
|
+
if (layer.schemaVersion !== 1 || layer.kind !== 'echl-h' || layer.stage !== task
|
|
71
|
+
|| !Array.isArray(layer.options) || layer.options.join('\0') !== options.join('\0')
|
|
72
|
+
|| !Number.isFinite(layer.temperature) || layer.temperature <= 0
|
|
73
|
+
|| !Number.isFinite(layer.alpha) || layer.alpha < 0 || layer.alpha > 1
|
|
74
|
+
|| !layer.fit || layer.fit.oof !== true) throw new Error(`${task} layer fit is missing or stale`);
|
|
75
|
+
return actualHash;
|
|
76
|
+
}
|
|
77
|
+
|
|
49
78
|
function buildVersion({ dataDir, version, versionDir, sourceDir }) {
|
|
50
79
|
validateVersion(version);
|
|
51
80
|
const privateDir = assertPrivateDataDir(dataDir);
|
|
@@ -64,6 +93,8 @@ function buildVersion({ dataDir, version, versionDir, sourceDir }) {
|
|
|
64
93
|
let options;
|
|
65
94
|
let thresholds;
|
|
66
95
|
let priorReferenceOnly = [];
|
|
96
|
+
let sourceLayer = null;
|
|
97
|
+
let layerHash = null;
|
|
67
98
|
let targetWeights = `${task}.safetensors`;
|
|
68
99
|
let targetConfig = `${task}.json`;
|
|
69
100
|
|
|
@@ -81,6 +112,16 @@ function buildVersion({ dataDir, version, versionDir, sourceDir }) {
|
|
|
81
112
|
thresholds = { ...stage.thresholds };
|
|
82
113
|
priorReferenceOnly = stage.referenceOnly ?? [];
|
|
83
114
|
if (digest(sourceWeights) !== stage.sha256) throw new Error(`${task} checkpoint hash does not match its manifest`);
|
|
115
|
+
const runDir = path.join(dataPath(privateDir, 'training', 'runs', version), task);
|
|
116
|
+
const evidence = validatePackagedFitEvidence(runDir, stage, task, sourceWeights, sourceConfig, options, privateDir);
|
|
117
|
+
if (evidence.outcome.outcome === 'layer') {
|
|
118
|
+
if (!stage.layer || stage.layerSha256 !== evidence.outcome.layerSha256)
|
|
119
|
+
throw new Error(`${task} candidate layer does not match its fit evidence`);
|
|
120
|
+
sourceLayer = path.join(source, stage.layer);
|
|
121
|
+
layerHash = readLayer(sourceLayer, task, options, stage.layerSha256);
|
|
122
|
+
} else if (stage.layer || evidence.outcome.outcome !== 'keep-base') {
|
|
123
|
+
throw new Error(`${task} candidate fit outcome is inconsistent`);
|
|
124
|
+
}
|
|
84
125
|
} else {
|
|
85
126
|
const runDir = path.join(source, task);
|
|
86
127
|
sourceWeights = path.join(runDir, 'harness-routing-v1.safetensors');
|
|
@@ -88,6 +129,14 @@ function buildVersion({ dataDir, version, versionDir, sourceDir }) {
|
|
|
88
129
|
const calibration = JSON.parse(fs.readFileSync(path.join(runDir, 'calibration.json'), 'utf8'));
|
|
89
130
|
thresholds = calibration.thresholds;
|
|
90
131
|
options = catalogs[task];
|
|
132
|
+
const evidence = validateFitStage({ runDir, task, dataDir: privateDir,
|
|
133
|
+
checkpointPath: sourceWeights, checkpointConfigPath: sourceConfig });
|
|
134
|
+
if (evidence.report.catalog.join('\0') !== options.join('\0'))
|
|
135
|
+
throw new Error(`${task} trainer report catalog does not match the package`);
|
|
136
|
+
if (evidence.outcome.outcome === 'layer') {
|
|
137
|
+
sourceLayer = path.join(runDir, 'layer.json');
|
|
138
|
+
layerHash = readLayer(sourceLayer, task, options, evidence.outcome.layerSha256);
|
|
139
|
+
}
|
|
91
140
|
}
|
|
92
141
|
// Older packages omitted this non-selectable intent option; restore its metadata without retraining.
|
|
93
142
|
if (task === 'intent' && options.includes('unclassified') && thresholds && typeof thresholds === 'object'
|
|
@@ -110,8 +159,17 @@ function buildVersion({ dataDir, version, versionDir, sourceDir }) {
|
|
|
110
159
|
const targetConfigPath = path.join(target, targetConfig);
|
|
111
160
|
if (path.resolve(sourceWeights) !== targetWeightsPath) copy(sourceWeights, targetWeightsPath);
|
|
112
161
|
if (path.resolve(sourceConfig) !== targetConfigPath) copy(sourceConfig, targetConfigPath);
|
|
113
|
-
|
|
162
|
+
const stageManifest = { weights: targetWeights, config: targetConfig, sha256: digest(targetWeightsPath),
|
|
114
163
|
options: [...options], thresholds: finalThresholds, ...(referenceOnly.length ? { referenceOnly } : {}) };
|
|
164
|
+
if (sourceLayer) {
|
|
165
|
+
const targetLayer = `${task}.layer.json`;
|
|
166
|
+
const targetLayerPath = path.join(target, targetLayer);
|
|
167
|
+
if (path.resolve(sourceLayer) !== targetLayerPath) copy(sourceLayer, targetLayerPath);
|
|
168
|
+
if (digest(targetLayerPath) !== layerHash) throw new Error(`${task} layer copy did not preserve its hash`);
|
|
169
|
+
stageManifest.layer = targetLayer;
|
|
170
|
+
stageManifest.layerSha256 = layerHash;
|
|
171
|
+
} else fs.rmSync(path.join(target, `${task}.layer.json`), { force: true });
|
|
172
|
+
stages[task] = stageManifest;
|
|
115
173
|
}
|
|
116
174
|
|
|
117
175
|
const sourceEvaluation = path.join(source, 'evaluation');
|
|
@@ -170,4 +228,4 @@ function publishVersion({ dataDir, version }) {
|
|
|
170
228
|
return { version, publishedPath: target };
|
|
171
229
|
}
|
|
172
230
|
|
|
173
|
-
module.exports = { buildVersion, publishVersion, trainerCatalogs, validateVersion, digest, safeRelative };
|
|
231
|
+
module.exports = { buildVersion, publishVersion, trainerCatalogs, validateVersion, digest, safeRelative, readLayer };
|
|
@@ -10,6 +10,7 @@ example a tier case with no tier) is skipped and counted in the printed `skipped
|
|
|
10
10
|
import argparse
|
|
11
11
|
import importlib.util
|
|
12
12
|
import json
|
|
13
|
+
import math
|
|
13
14
|
import os
|
|
14
15
|
from pathlib import Path
|
|
15
16
|
import shutil
|
|
@@ -51,6 +52,23 @@ def trained_catalog(weights, task, holdout):
|
|
|
51
52
|
return [{'id': option_id, 'text': texts[option_id]} for option_id in ids]
|
|
52
53
|
|
|
53
54
|
|
|
55
|
+
def layer_for(weights, task, options):
|
|
56
|
+
manifest = json.loads((Path(weights).parent / 'manifest.json').read_text(encoding='utf-8'))
|
|
57
|
+
stage = manifest['stages'][task]
|
|
58
|
+
has_layer = 'layer' in stage
|
|
59
|
+
has_hash = 'layerSha256' in stage
|
|
60
|
+
if has_layer != has_hash:
|
|
61
|
+
raise ValueError('layer manifest is incomplete')
|
|
62
|
+
if not has_layer:
|
|
63
|
+
return None
|
|
64
|
+
layer_path = Path(weights).parent / stage['layer']
|
|
65
|
+
module_path = Path(__file__).resolve().parents[2] / 'harness-everything' / 'scripts' / 'system-one' / 'layer.py'
|
|
66
|
+
spec = importlib.util.spec_from_file_location('system_one_layer', module_path)
|
|
67
|
+
layer_api = importlib.util.module_from_spec(spec)
|
|
68
|
+
spec.loader.exec_module(layer_api)
|
|
69
|
+
return layer_api, layer_api.load_layer(layer_path, stage['layerSha256'], task, options)
|
|
70
|
+
|
|
71
|
+
|
|
54
72
|
def eligible(case, task, ids):
|
|
55
73
|
"""A case is scored when its gold label is a catalog id; validity always scores."""
|
|
56
74
|
if task == 'validity':
|
|
@@ -78,6 +96,7 @@ def main():
|
|
|
78
96
|
catalog = trained_catalog(args.weights, args.task, args.holdout)
|
|
79
97
|
ids = {option['id'] for option in catalog}
|
|
80
98
|
options = tuple(option['text'] for option in catalog)
|
|
99
|
+
layer = layer_for(args.weights, args.task, [option['id'] for option in catalog])
|
|
81
100
|
|
|
82
101
|
corpus = json.loads(Path(args.holdout).read_text(encoding='utf-8'))
|
|
83
102
|
cases = [case for case in corpus.get('cases', []) if case.get('split') == 'holdout']
|
|
@@ -95,8 +114,10 @@ def main():
|
|
|
95
114
|
if not isinstance(request.get('context'), str):
|
|
96
115
|
raise ValueError('holdout case has no request.context')
|
|
97
116
|
examples.append(ChoiceExample(context=request['context'], options=options, label=0))
|
|
98
|
-
|
|
99
|
-
for case, values in zip(batch,
|
|
117
|
+
logits = model(collator(examples)).float().tolist()
|
|
118
|
+
for case, values in zip(batch, logits, strict=True):
|
|
119
|
+
values = layer[0].apply_layer(layer[1], values, case['request']['context']) if layer else \
|
|
120
|
+
[1.0 / (1.0 + math.exp(-max(-80.0, min(80.0, value)))) for value in values]
|
|
100
121
|
gold = ('invalid' if case['gold'] is None else 'actionable') if args.task == 'validity' else case['gold']
|
|
101
122
|
rows.append({'id': case['id'], 'gold': gold, 'scores': {option['id']: value for option, value in zip(catalog, values, strict=True)}})
|
|
102
123
|
|