harness-everything 0.52.0 → 0.53.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/CHANGELOG.md +20 -0
- package/benchmarks/results/live-host/opencode-2026-11-15-workspace/README.md +7 -0
- package/benchmarks/results/live-host/opencode-2026-11-15-workspace/live-workspace-probe.js +16 -0
- package/benchmarks/results/live-host/opencode-2026-11-15-workspace/live-workspace-trace-2026-11-15.jsonl +4 -0
- package/ci/mechanism-2n-opencode-plugin.test.js +1 -1
- package/ci/mechanism-2p-opencode-v2-entrypoint.test.js +18 -3
- package/ci/mechanism-338-opencode-async.test.js +20 -3
- package/ci/mechanism-341-opencode-lane.test.js +7 -1
- package/ci/mechanism-397-cycle-import.test.js +399 -0
- package/ci/mechanism-397-host-acceptance.test.js +119 -0
- package/ci/mechanism-397-opencode-observations.test.js +1922 -0
- package/ci/mechanism-system-one-curves.test.js +17 -0
- package/ci/mechanism-system-one-cycle.test.js +621 -2
- package/docs/platform-capabilities.md +13 -6
- package/docs/system-one-cycle.md +12 -3
- package/docs/system-one-observations.md +35 -4
- package/hooks/scripts/lib/observations.js +5 -3
- package/opencode-plugin/README.md +22 -8
- package/opencode-plugin/index.mjs +424 -44
- package/opencode-plugin/plugin.json +1 -1
- package/package.json +1 -1
- package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
- package/plugins/harness-everything/hooks/scripts/lib/observations.js +5 -3
- package/plugins/harness-everything/plugin.json +1 -1
- package/sbom.cdx.json +7 -7
- package/scripts/system-one-curves.js +154 -14
- package/scripts/system-one-cycle/collect.js +20 -3
- package/scripts/system-one-cycle/common.js +39 -1
- package/scripts/system-one-cycle/evaluate.js +8 -5
- package/scripts/system-one-cycle.js +7 -2
- package/scripts/system-one-observations-export.js +29 -0
- package/scripts/system-one-observations-import-store.js +128 -0
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
const fs = require('node:fs');
|
|
5
5
|
const path = require('node:path');
|
|
6
|
+
const { isDeepStrictEqual } = require('node:util');
|
|
6
7
|
const { STAGES, validateVersionManifest } = require('../harness-everything/scripts/system-one/manifest');
|
|
8
|
+
const { assertPrivateHistoryFile, appendPrivateHistory } = require('./system-one-cycle/common');
|
|
7
9
|
|
|
8
10
|
const STAGE_SET = new Set(STAGES);
|
|
9
11
|
const EPSILON = 1e-12;
|
|
@@ -139,7 +141,8 @@ function scoreRows(rows, stage, options, referenceOnly = []) {
|
|
|
139
141
|
}
|
|
140
142
|
|
|
141
143
|
function comparisonMetrics(metrics) {
|
|
142
|
-
return { auc:
|
|
144
|
+
return { auc: Number.isFinite(metrics.coverageAccuracyAuc)
|
|
145
|
+
? metrics.coverageAccuracyAuc : coverageAccuracyAuc(metrics.coverageCurve), logLoss: metrics.logLoss, ece: metrics.ece };
|
|
143
146
|
}
|
|
144
147
|
|
|
145
148
|
function metricDeltas(current, previous) {
|
|
@@ -169,36 +172,153 @@ function assessFloor(holdout, history) {
|
|
|
169
172
|
let baselineMissing = false;
|
|
170
173
|
for (const [stage, metrics] of Object.entries(holdout)) {
|
|
171
174
|
const current = comparisonMetrics(metrics);
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
const baseline = baselineForStage(history, stage);
|
|
176
|
+
const prior = baseline?.metrics ? {
|
|
177
|
+
auc: baseline.metrics.coverageAccuracyAuc,
|
|
178
|
+
logLoss: baseline.metrics.logLoss,
|
|
179
|
+
ece: baseline.metrics.ece,
|
|
180
|
+
} : null;
|
|
177
181
|
if (!prior) {
|
|
178
182
|
baselineMissing = true;
|
|
179
|
-
detail.stages[stage] = { coverageAccuracyAuc: current.auc, logLoss: current.logLoss, ece: current.ece,
|
|
183
|
+
detail.stages[stage] = { coverageAccuracyAuc: current.auc, logLoss: current.logLoss, ece: current.ece,
|
|
184
|
+
baselineAvailable: false, ...(baseline?.version ? { baselineVersion: baseline.version } : {}) };
|
|
180
185
|
continue;
|
|
181
186
|
}
|
|
187
|
+
detail.stages[stage] = { coverageAccuracyAuc: current.auc, logLoss: current.logLoss, ece: current.ece,
|
|
188
|
+
baselineAvailable: true, baselineVersion: baseline.version };
|
|
182
189
|
const deltas = metricDeltas(current, prior);
|
|
183
190
|
if (!noWorse(deltas)) oldHoldoutRegression = true;
|
|
184
|
-
detail.stages[stage] =
|
|
191
|
+
detail.stages[stage].deltas = deltas;
|
|
192
|
+
}
|
|
193
|
+
const baselineVersions = Object.values(detail.stages).map(stage => stage.baselineVersion);
|
|
194
|
+
if (baselineVersions.length && baselineVersions.every(isText) && new Set(baselineVersions).size === 1) {
|
|
195
|
+
detail.baselineVersion = baselineVersions[0];
|
|
185
196
|
}
|
|
186
197
|
if (oldHoldoutRegression) detail.status = 'regression';
|
|
187
198
|
else if (baselineMissing || Object.keys(holdout).length === 0) detail.status = 'baseline-unavailable';
|
|
188
199
|
return { oldHoldoutRegression, detail };
|
|
189
200
|
}
|
|
190
201
|
|
|
202
|
+
function floorMetrics(item, stage) {
|
|
203
|
+
const metrics = item?.floor?.detail?.stages?.[stage];
|
|
204
|
+
return metrics && [metrics.coverageAccuracyAuc, metrics.logLoss, metrics.ece].every(Number.isFinite) ? metrics : null;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function baselineForStage(history, stage) {
|
|
208
|
+
let version;
|
|
209
|
+
for (const item of history) {
|
|
210
|
+
const stageVersion = item.floor?.detail?.stages?.[stage]?.baselineVersion;
|
|
211
|
+
const legacyVersion = item.floor?.detail?.baselineVersion;
|
|
212
|
+
if (isText(stageVersion) || isText(legacyVersion)) {
|
|
213
|
+
version = isText(stageVersion) ? stageVersion : legacyVersion;
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (version) {
|
|
218
|
+
const item = history.find(row => row.version === version);
|
|
219
|
+
return { version, metrics: floorMetrics(item, stage) };
|
|
220
|
+
}
|
|
221
|
+
const item = history.find(row => floorMetrics(row, stage));
|
|
222
|
+
return item ? { version: item.version, metrics: floorMetrics(item, stage) } : null;
|
|
223
|
+
}
|
|
224
|
+
|
|
191
225
|
function readHistory(file) {
|
|
192
226
|
if (!fs.existsSync(file)) return [];
|
|
193
227
|
let lines;
|
|
194
228
|
try { lines = fs.readFileSync(file, 'utf8').split(/\r?\n/).filter(line => line.trim()); } catch (_) { fail(); }
|
|
195
229
|
try {
|
|
196
230
|
const history = lines.map(line => JSON.parse(line));
|
|
197
|
-
|
|
231
|
+
const versions = new Set();
|
|
232
|
+
for (const item of history) {
|
|
233
|
+
validateCurveRecord(item);
|
|
234
|
+
if (versions.has(item.version)) fail();
|
|
235
|
+
versions.add(item.version);
|
|
236
|
+
}
|
|
198
237
|
return history;
|
|
199
238
|
} catch (_) { fail(); }
|
|
200
239
|
}
|
|
201
240
|
|
|
241
|
+
function validateCurveRecord(curves) {
|
|
242
|
+
if (!isObject(curves) || curves.schemaVersion !== 1 || !isText(curves.version) || !isText(curves.createdAt)
|
|
243
|
+
|| !isObject(curves.stages) || !Object.keys(curves.stages).length
|
|
244
|
+
|| !isObject(curves.floor) || typeof curves.floor.oldHoldoutRegression !== 'boolean'
|
|
245
|
+
|| !isObject(curves.floor.detail) || !isObject(curves.floor.detail.stages)
|
|
246
|
+
|| !['unknown', 'checked', 'regression', 'baseline-unavailable'].includes(curves.floor.detail.status)
|
|
247
|
+
|| (curves.floor.detail.baselineVersion !== null && curves.floor.detail.baselineVersion !== undefined
|
|
248
|
+
&& !isText(curves.floor.detail.baselineVersion))) fail();
|
|
249
|
+
for (const [stage, metrics] of Object.entries(curves.stages)) {
|
|
250
|
+
if (!STAGE_SET.has(stage) || !isObject(metrics) || ![metrics.logLoss, metrics.brier, metrics.ece].every(Number.isFinite)
|
|
251
|
+
|| !Array.isArray(metrics.coverageCurve) || metrics.coverageCurve.length !== 101
|
|
252
|
+
|| metrics.coverageCurve.some(point => !Array.isArray(point) || point.length !== 3
|
|
253
|
+
|| !Number.isFinite(point[0]) || point[0] < 0 || point[0] > 1
|
|
254
|
+
|| !Number.isFinite(point[1]) || point[1] < 0 || point[1] > 1
|
|
255
|
+
|| (point[2] !== null && (!Number.isFinite(point[2]) || point[2] < 0 || point[2] > 1)))) fail();
|
|
256
|
+
}
|
|
257
|
+
for (const [stage, metrics] of Object.entries(curves.floor.detail.stages)) {
|
|
258
|
+
if (!Object.hasOwn(curves.stages, stage) || !isObject(metrics)
|
|
259
|
+
|| ![metrics.coverageAccuracyAuc, metrics.logLoss, metrics.ece].every(Number.isFinite)
|
|
260
|
+
|| typeof metrics.baselineAvailable !== 'boolean'
|
|
261
|
+
|| (metrics.baselineVersion !== undefined && !isText(metrics.baselineVersion))) fail();
|
|
262
|
+
if (metrics.baselineAvailable && (!isObject(metrics.deltas)
|
|
263
|
+
|| !['auc', 'logLoss', 'ece'].every(key => Number.isFinite(metrics.deltas[key]))
|
|
264
|
+
|| (!isText(metrics.baselineVersion) && !isText(curves.floor.detail.baselineVersion)))) fail();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function withoutCreatedAt(curves) {
|
|
269
|
+
const immutable = JSON.parse(JSON.stringify(curves));
|
|
270
|
+
delete immutable.createdAt;
|
|
271
|
+
for (const stage of Object.values(immutable.floor?.detail?.stages || {})) {
|
|
272
|
+
if (!isText(stage.baselineVersion) && isText(immutable.floor.detail.baselineVersion)) {
|
|
273
|
+
stage.baselineVersion = immutable.floor.detail.baselineVersion;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return immutable;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function assertVersionReusable(history, curves) {
|
|
280
|
+
const existing = history.find(item => item.version === curves.version);
|
|
281
|
+
if (existing && !isDeepStrictEqual(withoutCreatedAt(existing), withoutCreatedAt(curves))) fail();
|
|
282
|
+
return existing;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function validateSavedCurves(curves, version, manifest) {
|
|
286
|
+
validateCurveRecord(curves);
|
|
287
|
+
if (curves.version !== version || Object.keys(curves.stages).length !== Object.keys(manifest.stages).length
|
|
288
|
+
|| Object.keys(curves.stages).some(stage => !Object.hasOwn(manifest.stages, stage))) fail();
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function validateSavedTrend(trend, version) {
|
|
292
|
+
if (!isObject(trend) || !['promote', 'hold', 'rollback'].includes(trend.verdict)
|
|
293
|
+
|| !Array.isArray(trend.compared) || trend.compared.some(version => !isText(version))
|
|
294
|
+
|| !trend.compared.includes(version)
|
|
295
|
+
|| !Array.isArray(trend.reasons) || trend.reasons.some(reason => !isText(reason))) fail();
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function validateBaselineReferences(curves, history) {
|
|
299
|
+
for (const [stage, baseline] of Object.entries(curves.floor.detail.stages)) {
|
|
300
|
+
if (baseline.baselineAvailable !== true) continue;
|
|
301
|
+
const baselineVersion = isText(baseline.baselineVersion) ? baseline.baselineVersion : curves.floor.detail.baselineVersion;
|
|
302
|
+
if (!isText(baselineVersion) || !floorMetrics(history.find(row => row.version === baselineVersion), stage)) fail();
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function validateResumeDecision(curves, trend, history) {
|
|
307
|
+
const candidateIndex = history.findIndex(row => row.version === curves.version);
|
|
308
|
+
const predecessor = candidateIndex < 0 ? history : history.slice(0, candidateIndex);
|
|
309
|
+
const compared = [...predecessor.slice(-3).map(row => row.version), curves.version];
|
|
310
|
+
if (!isDeepStrictEqual(trend.compared, compared)) fail();
|
|
311
|
+
|
|
312
|
+
const holdout = Object.keys(curves.floor.detail.stages).length ? curves.floor.detail.stages : null;
|
|
313
|
+
const floor = assessFloor(holdout, predecessor);
|
|
314
|
+
if (!isDeepStrictEqual(curves.floor, floor) || !isDeepStrictEqual(trend, decideTrend(curves, predecessor, floor))) fail();
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function appendHistoryRow(file, history, curves) {
|
|
318
|
+
if (assertVersionReusable(history, curves)) return;
|
|
319
|
+
appendPrivateHistory(file, `${JSON.stringify(curves)}\n`);
|
|
320
|
+
}
|
|
321
|
+
|
|
202
322
|
function worseningCycles(history, stages) {
|
|
203
323
|
if (history.length < 3) return null;
|
|
204
324
|
// shortcut: history has no active-version field, so its latest three records stand in for the active trend; upgrade when the shared schema records active identity.
|
|
@@ -268,7 +388,8 @@ function stageFiles(args, option) {
|
|
|
268
388
|
|
|
269
389
|
function parseArgs(argv) {
|
|
270
390
|
const parsed = { val: [], holdout: [] };
|
|
271
|
-
const names = { '--version': 'version', '--version-dir': 'versionDir', '--val-scores': 'val', '--holdout-scores': 'holdout',
|
|
391
|
+
const names = { '--version': 'version', '--version-dir': 'versionDir', '--val-scores': 'val', '--holdout-scores': 'holdout',
|
|
392
|
+
'--history': 'history', '--out': 'out', '--resume-curves': 'resumeCurves' };
|
|
272
393
|
for (let i = 0; i < argv.length; i++) {
|
|
273
394
|
const key = names[argv[i]]; const value = argv[++i];
|
|
274
395
|
if (!key || value === undefined) fail();
|
|
@@ -276,13 +397,32 @@ function parseArgs(argv) {
|
|
|
276
397
|
else if (Object.hasOwn(parsed, key)) fail();
|
|
277
398
|
else parsed[key] = value;
|
|
278
399
|
}
|
|
279
|
-
if (!isText(parsed.version) || !isText(parsed.versionDir) || !
|
|
400
|
+
if (!isText(parsed.version) || !isText(parsed.versionDir) || !isText(parsed.history) || !isText(parsed.out)) fail();
|
|
401
|
+
if (parsed.resumeCurves) {
|
|
402
|
+
if (!isText(parsed.resumeCurves) || parsed.val.length || parsed.holdout.length) fail();
|
|
403
|
+
} else if (!parsed.val.length) fail();
|
|
280
404
|
return parsed;
|
|
281
405
|
}
|
|
282
406
|
|
|
283
407
|
function run(argv) {
|
|
284
408
|
const args = parseArgs(argv);
|
|
409
|
+
args.history = assertPrivateHistoryFile(args.history);
|
|
285
410
|
const manifest = readManifest(args.versionDir, args.version);
|
|
411
|
+
if (args.resumeCurves) {
|
|
412
|
+
let curves; let trend;
|
|
413
|
+
try {
|
|
414
|
+
curves = JSON.parse(fs.readFileSync(args.resumeCurves, 'utf8'));
|
|
415
|
+
trend = JSON.parse(fs.readFileSync(path.join(args.out, 'trend.json'), 'utf8'));
|
|
416
|
+
} catch (_) { fail(); }
|
|
417
|
+
validateSavedCurves(curves, args.version, manifest);
|
|
418
|
+
validateSavedTrend(trend, args.version);
|
|
419
|
+
const history = readHistory(args.history);
|
|
420
|
+
validateBaselineReferences(curves, history);
|
|
421
|
+
validateResumeDecision(curves, trend, history);
|
|
422
|
+
appendHistoryRow(args.history, history, curves);
|
|
423
|
+
console.log(JSON.stringify({ resumed: true, version: args.version }));
|
|
424
|
+
return { curves, trend };
|
|
425
|
+
}
|
|
286
426
|
const valFiles = stageFiles(args, 'val');
|
|
287
427
|
const holdoutFiles = stageFiles(args, 'holdout');
|
|
288
428
|
if (Object.keys(holdoutFiles).some(stage => !Object.hasOwn(valFiles, stage))) fail();
|
|
@@ -304,13 +444,13 @@ function run(argv) {
|
|
|
304
444
|
const history = readHistory(args.history);
|
|
305
445
|
const floor = assessFloor(Object.keys(holdoutMetrics).length ? holdoutMetrics : null, history);
|
|
306
446
|
const curves = { schemaVersion: 1, version: args.version, createdAt: new Date().toISOString(), stages, floor };
|
|
447
|
+
const existing = assertVersionReusable(history, curves);
|
|
448
|
+
validateBaselineReferences(curves, history);
|
|
307
449
|
const trend = decideTrend(curves, history, floor);
|
|
308
450
|
fs.mkdirSync(args.out, { recursive: true });
|
|
309
|
-
fs.mkdirSync(path.dirname(args.history), { recursive: true });
|
|
310
451
|
fs.writeFileSync(path.join(args.out, 'curves.json'), `${JSON.stringify(curves, null, 2)}\n`);
|
|
311
452
|
fs.writeFileSync(path.join(args.out, 'trend.json'), `${JSON.stringify(trend, null, 2)}\n`);
|
|
312
|
-
|
|
313
|
-
fs.appendFileSync(args.history, `${oldHistory && !oldHistory.endsWith('\n') ? '\n' : ''}${JSON.stringify(curves)}\n`);
|
|
453
|
+
if (!existing) appendHistoryRow(args.history, history, curves);
|
|
314
454
|
const summary = Object.fromEntries(Object.entries(stages).map(([stage, value]) => [stage, {
|
|
315
455
|
rows: readJsonl(valFiles[stage]).length,
|
|
316
456
|
logLoss: value.logLoss,
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
const fs = require('node:fs');
|
|
4
4
|
const path = require('node:path');
|
|
5
5
|
const { REPO, readJsonl, writeJsonl, writeJson, runNode, assertPrivateDataDir } = require('./common');
|
|
6
|
+
const observations = require('../../hooks/scripts/lib/observations');
|
|
7
|
+
const { importStore } = require('../system-one-observations-import-store');
|
|
6
8
|
|
|
7
9
|
function collect({ dataDir, since, sessionsDir }) {
|
|
8
10
|
const privateDir = assertPrivateDataDir(dataDir);
|
|
@@ -14,7 +16,21 @@ function collect({ dataDir, since, sessionsDir }) {
|
|
|
14
16
|
const exporter = path.join(REPO, 'scripts', 'system-one-observations-export.js');
|
|
15
17
|
const importArgs = ['--store', store, '--since', since];
|
|
16
18
|
if (sessionsDir) importArgs.push('--sessions', sessionsDir);
|
|
17
|
-
|
|
19
|
+
const importStartedAt = new Date().toISOString();
|
|
20
|
+
let codexStatus = 'ok';
|
|
21
|
+
try { runNode(importer, importArgs); }
|
|
22
|
+
catch { codexStatus = 'error'; }
|
|
23
|
+
const live = importStore({ sourceRoot: observations.storeRoot(), store, since });
|
|
24
|
+
const importReportFile = path.join(observed, 'import-report.json');
|
|
25
|
+
writeJson(importReportFile, {
|
|
26
|
+
schemaVersion: 1,
|
|
27
|
+
run: { startedAt: importStartedAt },
|
|
28
|
+
sources: { live: live.source, codex: { status: codexStatus } },
|
|
29
|
+
byHost: live.byHost,
|
|
30
|
+
});
|
|
31
|
+
if (codexStatus !== 'ok' || live.source.status === 'error') {
|
|
32
|
+
throw new Error('observation import incomplete; see import-report.json');
|
|
33
|
+
}
|
|
18
34
|
runNode(exporter, ['--store', store, '--out', observed, '--self-report-only', '--since', since]);
|
|
19
35
|
|
|
20
36
|
const promptsFile = path.join(observed, 'prompts-observed.jsonl');
|
|
@@ -29,6 +45,7 @@ function collect({ dataDir, since, sessionsDir }) {
|
|
|
29
45
|
id: row.id,
|
|
30
46
|
tier: row.tier ?? null,
|
|
31
47
|
intents: Array.isArray(row.intents) ? row.intents : [],
|
|
48
|
+
host: row.host ?? null,
|
|
32
49
|
behaviorEvidence: row.behaviorEvidence || 'unobserved',
|
|
33
50
|
contradictions: Array.isArray(row.contradictions) ? row.contradictions : [],
|
|
34
51
|
}));
|
|
@@ -37,11 +54,11 @@ function collect({ dataDir, since, sessionsDir }) {
|
|
|
37
54
|
const exportReportFile = path.join(observed, 'export-report.json');
|
|
38
55
|
const exported = JSON.parse(fs.readFileSync(exportReportFile, 'utf8'));
|
|
39
56
|
writeJson(exportReportFile, Object.fromEntries(['schemaVersion', 'records', 'exported', 'skippedBeforeSince', 'skippedUnlabeled',
|
|
40
|
-
'skippedNoText', 'validationRows', 'withSelfReport'].filter(key => Object.hasOwn(exported, key)).map(key => [key, exported[key]])));
|
|
57
|
+
'skippedNoText', 'validationRows', 'withSelfReport', 'hostAcceptance'].filter(key => Object.hasOwn(exported, key)).map(key => [key, exported[key]])));
|
|
41
58
|
for (const dir of [training, path.dirname(store), store, observed]) {
|
|
42
59
|
try { fs.chmodSync(dir, 0o700); } catch { /* Windows does not expose POSIX modes. */ }
|
|
43
60
|
}
|
|
44
|
-
for (const file of [promptsFile, labelsFile, path.join(observed, 'export-report.json')]) {
|
|
61
|
+
for (const file of [promptsFile, labelsFile, path.join(observed, 'export-report.json'), importReportFile]) {
|
|
45
62
|
try { if (fs.existsSync(file)) fs.chmodSync(file, 0o600); } catch { /* Windows does not expose POSIX modes. */ }
|
|
46
63
|
}
|
|
47
64
|
return { prompts: prompts.length, selfLabels: labels.length, since };
|
|
@@ -127,11 +127,49 @@ function assertPrivateDataDir(dataDir, { allowSyntheticBuildRoot = false, create
|
|
|
127
127
|
return target;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
+
function assertPrivateHistoryFile(file) {
|
|
131
|
+
if (typeof file !== 'string' || !file.trim()) throw new Error('private history path must be nonempty');
|
|
132
|
+
let target;
|
|
133
|
+
try { target = canonicalDestination(file); }
|
|
134
|
+
catch { throw new Error('invalid private history path'); }
|
|
135
|
+
const repo = fs.realpathSync.native(REPO);
|
|
136
|
+
if (isWithin(repo, target)) throw new Error('private history must be stored outside the repository');
|
|
137
|
+
try {
|
|
138
|
+
if (!fs.statSync(target).isFile()) throw new Error('private history path must name a file');
|
|
139
|
+
} catch (error) {
|
|
140
|
+
if (error.code !== 'ENOENT') throw error;
|
|
141
|
+
}
|
|
142
|
+
return target;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function appendPrivateHistory(file, text) {
|
|
146
|
+
const target = assertPrivateHistoryFile(file);
|
|
147
|
+
fs.mkdirSync(path.dirname(target), { recursive: true, mode: 0o700 });
|
|
148
|
+
let separator = '';
|
|
149
|
+
try {
|
|
150
|
+
const fd = fs.openSync(assertPrivateHistoryFile(target), 'r');
|
|
151
|
+
try {
|
|
152
|
+
const size = fs.fstatSync(fd).size;
|
|
153
|
+
if (size) {
|
|
154
|
+
const lastByte = Buffer.alloc(1);
|
|
155
|
+
fs.readSync(fd, lastByte, 0, 1, size - 1);
|
|
156
|
+
if (lastByte[0] !== 0x0a) separator = '\n';
|
|
157
|
+
}
|
|
158
|
+
} finally {
|
|
159
|
+
fs.closeSync(fd);
|
|
160
|
+
}
|
|
161
|
+
} catch (error) {
|
|
162
|
+
if (error.code !== 'ENOENT') throw error;
|
|
163
|
+
}
|
|
164
|
+
fs.appendFileSync(assertPrivateHistoryFile(target), `${separator}${text}`, { encoding: 'utf8', mode: 0o600 });
|
|
165
|
+
}
|
|
166
|
+
|
|
130
167
|
function resultSummary(step, details) {
|
|
131
168
|
return { step, ...details };
|
|
132
169
|
}
|
|
133
170
|
|
|
134
171
|
module.exports = {
|
|
135
172
|
REPO, STEPS, readJsonl, writeJsonl, writeJson, parseFlags, flag, required, dataPath,
|
|
136
|
-
readState, stepComplete, markStep, runNode, assertPrivateDataDir,
|
|
173
|
+
readState, stepComplete, markStep, runNode, assertPrivateDataDir, assertPrivateHistoryFile,
|
|
174
|
+
appendPrivateHistory, isSyntheticBuildDataDir, resultSummary,
|
|
137
175
|
};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const fs = require('node:fs');
|
|
4
4
|
const path = require('node:path');
|
|
5
5
|
const { spawnSync } = require('node:child_process');
|
|
6
|
-
const { REPO, dataPath, writeJson, assertPrivateDataDir } = require('./common');
|
|
6
|
+
const { REPO, dataPath, writeJson, assertPrivateDataDir, assertPrivateHistoryFile } = require('./common');
|
|
7
7
|
const { buildVersion } = require('./package');
|
|
8
8
|
const { TASKS } = require('./train');
|
|
9
9
|
const { validateVersionManifest } = require('../../harness-everything/scripts/system-one/manifest');
|
|
@@ -29,21 +29,25 @@ function recordEvaluation(manifestFile, version) {
|
|
|
29
29
|
return manifest;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
function evaluateCycle({ dataDir, version }) {
|
|
32
|
+
function evaluateCycle({ dataDir, version, history: historyOption }) {
|
|
33
33
|
const privateDir = assertPrivateDataDir(dataDir);
|
|
34
|
+
const history = assertPrivateHistoryFile(historyOption === undefined
|
|
35
|
+
? dataPath(privateDir, 'training', 'history.jsonl') : historyOption);
|
|
34
36
|
const source = dataPath(privateDir, 'training', 'runs', version);
|
|
35
37
|
const versionDir = dataPath(privateDir, 'training', 'candidates', version);
|
|
36
38
|
const evaluationDir = path.join(versionDir, 'evaluation');
|
|
37
39
|
const curvesFile = path.join(evaluationDir, 'curves.json');
|
|
38
40
|
const trendFile = path.join(evaluationDir, 'trend.json');
|
|
41
|
+
const curvesScript = path.join(REPO, 'scripts', 'system-one-curves.js');
|
|
42
|
+
if (!fs.existsSync(curvesScript)) throw new Error('contract C curves CLI is not available in this checkout');
|
|
39
43
|
if (fs.existsSync(curvesFile) && fs.existsSync(trendFile)) {
|
|
44
|
+
runProcess(process.execPath, [curvesScript, '--version', version, '--version-dir', versionDir,
|
|
45
|
+
'--history', history, '--out', evaluationDir, '--resume-curves', curvesFile]);
|
|
40
46
|
const manifestFile = path.join(versionDir, 'manifest.json');
|
|
41
47
|
recordEvaluation(manifestFile, version);
|
|
42
48
|
const trend = JSON.parse(fs.readFileSync(trendFile, 'utf8'));
|
|
43
49
|
return { version, verdict: trend.verdict, compared: trend.compared.length, resumed: true };
|
|
44
50
|
}
|
|
45
|
-
const curvesScript = path.join(REPO, 'scripts', 'system-one-curves.js');
|
|
46
|
-
if (!fs.existsSync(curvesScript)) throw new Error('contract C curves CLI is not available in this checkout');
|
|
47
51
|
buildVersion({ dataDir: privateDir, version, sourceDir: source, versionDir });
|
|
48
52
|
|
|
49
53
|
fs.mkdirSync(evaluationDir, { recursive: true, mode: 0o700 });
|
|
@@ -57,7 +61,6 @@ function evaluateCycle({ dataDir, version }) {
|
|
|
57
61
|
curvesArgs.push('--val-scores', `${task}=${path.join(source, task, 'val-scores.jsonl')}`);
|
|
58
62
|
curvesArgs.push('--holdout-scores', `${task}=${scores}`);
|
|
59
63
|
}
|
|
60
|
-
const history = dataPath(privateDir, 'training', 'history.jsonl');
|
|
61
64
|
curvesArgs.push('--history', history, '--out', evaluationDir);
|
|
62
65
|
runProcess(process.execPath, [curvesScript, ...curvesArgs]);
|
|
63
66
|
|
|
@@ -18,7 +18,7 @@ const USAGE = `Usage:
|
|
|
18
18
|
node scripts/system-one-cycle.js all --until <step> --data-dir <private cycle directory> [options]
|
|
19
19
|
|
|
20
20
|
Steps: ${STEPS.join(', ')}
|
|
21
|
-
Options: --since YYYY-MM-DD --sessions <Codex sessions dir> --version <id> --threads 4 --max-rss-mb 6144 --holdout <file> (repeatable)`;
|
|
21
|
+
Options: --since YYYY-MM-DD --sessions <Codex sessions dir> --version <id> --threads 4 --max-rss-mb 6144 --holdout <file> (repeatable) --history <private-history.jsonl> (evaluate/all)`;
|
|
22
22
|
|
|
23
23
|
function values(flags, name) {
|
|
24
24
|
const value = flags[name];
|
|
@@ -37,6 +37,11 @@ function numberFlag(flags, name, fallback) {
|
|
|
37
37
|
return value;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
function historyFlag(flags) {
|
|
41
|
+
if (Array.isArray(flags.history)) throw new Error('--history may be supplied only once');
|
|
42
|
+
return flag(flags, 'history');
|
|
43
|
+
}
|
|
44
|
+
|
|
40
45
|
function outputsFor(step, dataDir, version, versionDir, result) {
|
|
41
46
|
switch (step) {
|
|
42
47
|
case 'collect': return ['training/observed/prompts-observed.jsonl', 'training/observed/labels-observed.jsonl'];
|
|
@@ -82,7 +87,7 @@ async function runStep(step, flags, dataDir) {
|
|
|
82
87
|
break;
|
|
83
88
|
case 'evaluate':
|
|
84
89
|
version = validateVersion(required(flags, 'version'));
|
|
85
|
-
result = evaluateCycle({ dataDir, version });
|
|
90
|
+
result = evaluateCycle({ dataDir, version, history: historyFlag(flags) });
|
|
86
91
|
break;
|
|
87
92
|
case 'package':
|
|
88
93
|
version = validateVersion(required(flags, 'version'));
|
|
@@ -82,6 +82,33 @@ function run(args) {
|
|
|
82
82
|
obs.sweep(store);
|
|
83
83
|
const index = obs.readJson(path.join(store, 'observations-index.json'), null);
|
|
84
84
|
if (!index || index.schemaVersion !== 1 || !Array.isArray(index.records)) throw new Error(`no observation index in ${store}`);
|
|
85
|
+
const malformedLabelReasons = new Set(['label-invalid', 'label-unparseable']);
|
|
86
|
+
const acceptanceByHost = {};
|
|
87
|
+
const seenTurns = new Set();
|
|
88
|
+
for (const record of index.records) {
|
|
89
|
+
const host = String(record.host || 'unknown');
|
|
90
|
+
const counts = acceptanceByHost[host] || (acceptanceByHost[host] = { valid: 0, invalid: 0, missing: 0 });
|
|
91
|
+
if (since !== null && (!Number.isFinite(Date.parse(record.observedAt || '')) || Date.parse(record.observedAt) < since)) continue;
|
|
92
|
+
const writer = record.writer || {};
|
|
93
|
+
const sessionId = String(writer.sessionId || '');
|
|
94
|
+
const turnId = String(writer.turnId || '');
|
|
95
|
+
const turn = Number.isInteger(record.turn) ? String(record.turn) : '';
|
|
96
|
+
const uniqueTurn = sessionId && turnId ? `${host}\0${sessionId}\0id:${turnId}`
|
|
97
|
+
: sessionId && turn ? `${host}\0${sessionId}\0ordinal:${turn}` : record.id ? `${host}\0record:${record.id}` : '';
|
|
98
|
+
if (uniqueTurn && seenTurns.has(uniqueTurn)) continue;
|
|
99
|
+
if (uniqueTurn) seenTurns.add(uniqueTurn);
|
|
100
|
+
if (record.selfReport) counts.valid++;
|
|
101
|
+
else if (malformedLabelReasons.has(record.selfReportReason)) counts.invalid++;
|
|
102
|
+
else counts.missing++;
|
|
103
|
+
}
|
|
104
|
+
const hostAcceptanceByHost = Object.fromEntries(Object.entries(acceptanceByHost).sort(([left], [right]) => left.localeCompare(right))
|
|
105
|
+
.map(([host, counts]) => {
|
|
106
|
+
const eligible = counts.valid + counts.invalid + counts.missing;
|
|
107
|
+
return [host, { eligible, ...counts, acceptanceRate: eligible ? counts.valid / eligible : null }];
|
|
108
|
+
}));
|
|
109
|
+
const malformedLabelsByHost = Object.fromEntries(Object.entries(hostAcceptanceByHost)
|
|
110
|
+
.filter(([, counts]) => counts.invalid)
|
|
111
|
+
.map(([host, counts]) => [host, counts.invalid]));
|
|
85
112
|
const rows = [];
|
|
86
113
|
let skippedNoText = 0;
|
|
87
114
|
let skippedBeforeSince = 0;
|
|
@@ -137,6 +164,8 @@ function run(args) {
|
|
|
137
164
|
since: sinceText, selfReportOnly, skippedBeforeSince, skippedUnlabeled,
|
|
138
165
|
skippedNoText, validationRows: validation, withSelfReport: withSelf.length,
|
|
139
166
|
selfReportReasons: count(r => r.record.selfReportReason || 'ok'), hosts: count(r => r.record.host),
|
|
167
|
+
malformedLabelsByHost: Object.fromEntries(Object.entries(malformedLabelsByHost).sort(([left], [right]) => left.localeCompare(right))),
|
|
168
|
+
hostAcceptance: { population: 'stored-observations', byHost: hostAcceptanceByHost },
|
|
140
169
|
validity: count(r => r.label.validity), tiers: count(r => r.label.tier), tierSources: count(r => r.label.tierSource),
|
|
141
170
|
behaviorEvidence: {
|
|
142
171
|
observed: rows.filter(r => r.label.behaviorEvidence === 'observed').length,
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const obs = require('../hooks/scripts/lib/observations');
|
|
6
|
+
const { assertPrivateDataDir } = require('./system-one-cycle/common');
|
|
7
|
+
|
|
8
|
+
function parseSince(value) {
|
|
9
|
+
if (typeof value !== 'string') throw new Error('invalid-since');
|
|
10
|
+
const text = value;
|
|
11
|
+
const timestamp = Date.parse(/^\d{4}-\d{2}-\d{2}$/.test(text) ? `${text}T00:00:00.000Z` : text);
|
|
12
|
+
if (!Number.isFinite(timestamp)) throw new Error('invalid-since');
|
|
13
|
+
return timestamp;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function bucket(byHost, host) {
|
|
17
|
+
if (!Object.hasOwn(byHost, host)) {
|
|
18
|
+
Object.defineProperty(byHost, host, {
|
|
19
|
+
value: { persisted: 0, duplicate: 0, ambiguous: 0, importFailure: 0 }, enumerable: true, configurable: true, writable: true,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return byHost[host];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function importStore({ sourceRoot = obs.storeRoot(), store, since, lockTimeoutMs } = {}) {
|
|
26
|
+
const report = {
|
|
27
|
+
source: { root: 'configured-private-store', status: 'absent' },
|
|
28
|
+
byHost: {},
|
|
29
|
+
};
|
|
30
|
+
const fail = (host, code) => {
|
|
31
|
+
bucket(report.byHost, host).importFailure++;
|
|
32
|
+
report.source.status = 'error';
|
|
33
|
+
report.source.error ||= code;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
let cutoff;
|
|
37
|
+
try { cutoff = parseSince(since); }
|
|
38
|
+
catch { fail('unknown', 'invalid-since'); return report; }
|
|
39
|
+
|
|
40
|
+
if (typeof store !== 'string' || !store.trim() || !path.isAbsolute(store)
|
|
41
|
+
|| typeof sourceRoot !== 'string' || !sourceRoot.trim()) {
|
|
42
|
+
fail('unknown', typeof store !== 'string' || !store.trim() || !path.isAbsolute(store) ? 'invalid-destination' : 'invalid-source-root');
|
|
43
|
+
return report;
|
|
44
|
+
}
|
|
45
|
+
let destination;
|
|
46
|
+
let source;
|
|
47
|
+
try { destination = assertPrivateDataDir(store); }
|
|
48
|
+
catch { fail('unknown', 'destination-unavailable'); return report; }
|
|
49
|
+
try { source = assertPrivateDataDir(sourceRoot, { create: false }); }
|
|
50
|
+
catch { fail('unknown', 'source-unavailable'); return report; }
|
|
51
|
+
|
|
52
|
+
const destinationIndex = path.join(destination, 'observations-index.json');
|
|
53
|
+
try {
|
|
54
|
+
fs.mkdirSync(destination, { recursive: true, mode: 0o700 });
|
|
55
|
+
try { fs.writeFileSync(destinationIndex, '{"schemaVersion":1,"kind":"system-one-observations","records":[]}\n', { flag: 'wx', mode: 0o600 }); }
|
|
56
|
+
catch (error) { if (error.code !== 'EEXIST') throw error; }
|
|
57
|
+
const existing = JSON.parse(fs.readFileSync(destinationIndex, 'utf8'));
|
|
58
|
+
if (existing.schemaVersion !== 1 || !Array.isArray(existing.records)) throw new Error('invalid destination index');
|
|
59
|
+
} catch { fail('unknown', 'destination-unavailable'); return report; }
|
|
60
|
+
|
|
61
|
+
const sourceIndex = path.join(source, 'observations-index.json');
|
|
62
|
+
if (!fs.existsSync(sourceIndex)) return report;
|
|
63
|
+
|
|
64
|
+
let index;
|
|
65
|
+
try { index = JSON.parse(fs.readFileSync(sourceIndex, 'utf8')); }
|
|
66
|
+
catch { fail('unknown', 'source-index-invalid'); return report; }
|
|
67
|
+
if (!index || index.schemaVersion !== 1 || !Array.isArray(index.records)) {
|
|
68
|
+
fail('unknown', 'source-index-invalid');
|
|
69
|
+
return report;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
report.source.status = 'ok';
|
|
73
|
+
for (const record of index.records) {
|
|
74
|
+
if (!record || typeof record !== 'object' || Array.isArray(record)) {
|
|
75
|
+
fail('unknown', 'source-record-invalid');
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const host = typeof record.host === 'string' && record.host.trim() ? record.host : 'unknown';
|
|
79
|
+
const observedAt = typeof record.observedAt === 'string' ? Date.parse(record.observedAt) : NaN;
|
|
80
|
+
if (!Number.isFinite(observedAt)) { fail(host, 'source-record-invalid'); continue; }
|
|
81
|
+
if (observedAt < cutoff) continue;
|
|
82
|
+
const result = bucket(report.byHost, host);
|
|
83
|
+
const writer = record.writer && typeof record.writer === 'object' ? record.writer : {};
|
|
84
|
+
const sessionId = typeof writer.sessionId === 'string' ? writer.sessionId : '';
|
|
85
|
+
if (typeof record.id !== 'string' || !record.id || typeof record.contentSha256 !== 'string'
|
|
86
|
+
|| !/^[a-f\d]{64}$/i.test(record.contentSha256)) {
|
|
87
|
+
fail(host, 'source-record-invalid');
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (host === 'unknown' || !sessionId || (writer.turnId !== undefined && typeof writer.turnId !== 'string')) {
|
|
91
|
+
result.ambiguous++;
|
|
92
|
+
report.source.status = 'error';
|
|
93
|
+
report.source.error ||= 'ambiguous-records';
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const retained = Number.isFinite(Date.parse(record.validUntil || ''));
|
|
98
|
+
const text = retained ? obs.recordText(source, record) : null;
|
|
99
|
+
if (text !== null && (!text || typeof text.prompt !== 'string'
|
|
100
|
+
|| !(text.previous === undefined || typeof text.previous === 'string'))) {
|
|
101
|
+
fail(host, 'source-text-invalid');
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
let appended;
|
|
105
|
+
try {
|
|
106
|
+
appended = obs.appendRecordDetailed(destination, record, text, {
|
|
107
|
+
dedupeByTurn: true,
|
|
108
|
+
...(lockTimeoutMs === undefined ? {} : { lockTimeoutMs }),
|
|
109
|
+
});
|
|
110
|
+
} catch {
|
|
111
|
+
fail(host, 'append-failed');
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
if (appended.status === 'appended') result.persisted++;
|
|
115
|
+
else if (appended.status === 'duplicate') result.duplicate++;
|
|
116
|
+
else if (appended.status === 'ambiguous') {
|
|
117
|
+
result.ambiguous++;
|
|
118
|
+
report.source.status = 'error';
|
|
119
|
+
report.source.error ||= 'ambiguous-records';
|
|
120
|
+
} else {
|
|
121
|
+
fail(host, 'append-failed');
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return report;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
module.exports = { importStore };
|