harness-everything 1.5.0 → 1.5.2
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/ci.yml +16 -0
- package/CHANGELOG.md +15 -0
- package/benchmarks/results/error-ledger-oracle-484-pilot/README.md +57 -0
- package/benchmarks/results/error-ledger-oracle-484-pilot/candidates.json +22802 -0
- package/benchmarks/results/error-ledger-oracle-484-pilot/labels.json +131 -0
- package/benchmarks/results/error-ledger-oracle-484-pilot/oracle.json +362 -0
- package/benchmarks/results/error-ledger-oracle-484-pilot/rows.json +648 -0
- package/benchmarks/results/error-ledger-oracle-484-pilot/sample.json +215 -0
- package/benchmarks/results/error-ledger-oracle-484-pilot/select.js +127 -0
- package/ci/mechanism-332-fable-directive.test.js +98 -2
- package/ci/mechanism-349-ci-change-scope.test.js +69 -1
- package/ci/mechanism-548-bigint-identity.test.js +1 -1
- package/ci/mechanism-571-fit-guard.test.js +165 -0
- package/ci/mechanism-571-nll-labels.test.js +79 -0
- package/ci/mechanism-report-writer.test.js +17 -0
- package/ci/mechanism-system-one-curves.test.js +11 -5
- package/ci/mechanism-system-one-cycle.test.js +73 -0
- package/harness-everything/SKILL.md +1 -1
- package/harness-everything/scripts/system-one/layer.py +11 -1
- package/harness-everything/scripts/tier-router.js +27 -12
- 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/layer.py +11 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/tier-router.js +27 -12
- package/sbom.cdx.json +7 -7
- package/scripts/report-writer.js +1 -1
- package/scripts/system-one-curves.js +72 -15
- package/scripts/system-one-cycle/evaluate.js +25 -13
- package/scripts/system-one-cycle/train.js +67 -25
- package/scripts/system-one-fit-layer.py +11 -1
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('node:assert/strict');
|
|
4
|
+
const crypto = require('node:crypto');
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const os = require('node:os');
|
|
7
|
+
const path = require('node:path');
|
|
8
|
+
const { runGuarded, fitLayerStage, validateFitStage } = require('../scripts/system-one-cycle/train');
|
|
9
|
+
const { trainerCatalogs } = require('../scripts/system-one-cycle/package');
|
|
10
|
+
const { test } = require('node:test');
|
|
11
|
+
|
|
12
|
+
const ROOT = path.resolve(__dirname, '..');
|
|
13
|
+
const sha256 = file => crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex');
|
|
14
|
+
|
|
15
|
+
function makeFixture(t) {
|
|
16
|
+
const dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 's571b-fit-guard-'));
|
|
17
|
+
const runDir = path.join(dataDir, 'training', 'runs', 'guarded', 'tier');
|
|
18
|
+
const bundle = path.join(dataDir, 'training', 'v1');
|
|
19
|
+
const runner = path.join(dataDir, 'fake-fitter.js');
|
|
20
|
+
const sentinelDir = path.join(dataDir, 'guard-invocations');
|
|
21
|
+
fs.mkdirSync(runDir, { recursive: true });
|
|
22
|
+
fs.mkdirSync(bundle, { recursive: true });
|
|
23
|
+
fs.mkdirSync(sentinelDir);
|
|
24
|
+
t.after(() => fs.rmSync(dataDir, { recursive: true, force: true }));
|
|
25
|
+
|
|
26
|
+
const catalog = trainerCatalogs().tier;
|
|
27
|
+
const prompts = path.join(bundle, 'prompts.jsonl');
|
|
28
|
+
const labels = path.join(bundle, 'labels.jsonl');
|
|
29
|
+
fs.writeFileSync(prompts, '{"id":"validation-tier","text":"fixture"}\n');
|
|
30
|
+
fs.writeFileSync(labels, '{"id":"validation-tier","gold":"tier2"}\n');
|
|
31
|
+
fs.writeFileSync(path.join(runDir, 'harness-routing-v1.safetensors'), 'fixture-weights');
|
|
32
|
+
fs.writeFileSync(path.join(runDir, 'harness-routing-v1.json'), '{"context_tokens":1024}\n');
|
|
33
|
+
fs.writeFileSync(path.join(runDir, 'val-scores.jsonl'), `${JSON.stringify({ id: 'validation-tier', gold: 'tier2',
|
|
34
|
+
scores: Object.fromEntries(catalog.map(id => [id, id === 'tier2' ? 0.9 : 0.1])) })}\n`);
|
|
35
|
+
const report = { schemaVersion: 1, task: 'tier', target: 'label', catalog, counts: { train: 1, validation: 1 },
|
|
36
|
+
datasets: { 'prompts.jsonl': sha256(prompts), 'labels.jsonl': sha256(labels) }, config: { context_tokens: 1024 },
|
|
37
|
+
bestEpoch: 1, history: [], device: 'cpu', torch: 'fixture' };
|
|
38
|
+
fs.writeFileSync(path.join(runDir, 'train-report.json'), JSON.stringify(report));
|
|
39
|
+
fs.writeFileSync(path.join(runDir, 'resource-guard.json'), JSON.stringify({ schemaVersion: 1, exitCode: 0,
|
|
40
|
+
killedForLimit: false, monitorFailed: false, peakRssMb: 1, maxRssMb: 64, threads: 2 }));
|
|
41
|
+
|
|
42
|
+
fs.writeFileSync(runner, `#!/usr/bin/env node
|
|
43
|
+
'use strict';
|
|
44
|
+
const fs = require('node:fs');
|
|
45
|
+
const path = require('node:path');
|
|
46
|
+
const args = process.argv.slice(2);
|
|
47
|
+
const value = name => args[args.indexOf(name) + 1];
|
|
48
|
+
const runDir = value('--run-dir');
|
|
49
|
+
const task = value('--task');
|
|
50
|
+
const dataDir = value('--data-dir');
|
|
51
|
+
const holdout = value('--holdout');
|
|
52
|
+
const marker = process.env.S571B_SENTINEL;
|
|
53
|
+
const mode = process.env.S571B_MODE;
|
|
54
|
+
if (!marker || !runDir || task !== 'tier' || !dataDir || !holdout) process.exit(21);
|
|
55
|
+
fs.writeFileSync(marker, 'guard reached\\n');
|
|
56
|
+
const json = file => JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
57
|
+
const hash = file => require('node:crypto').createHash('sha256').update(fs.readFileSync(file)).digest('hex');
|
|
58
|
+
const report = json(path.join(runDir, 'train-report.json'));
|
|
59
|
+
const scoreFile = path.join(runDir, 'val-scores.jsonl');
|
|
60
|
+
const outcome = { schemaVersion: 1, task, outcome: 'keep-base', oofScoreSpace: null,
|
|
61
|
+
datasetSha256: report.datasets, trainerReportSha256: hash(path.join(runDir, 'train-report.json')),
|
|
62
|
+
holdoutSha256: hash(holdout), checkpointSha256: hash(path.join(runDir, 'harness-routing-v1.safetensors')),
|
|
63
|
+
checkpointConfigSha256: hash(path.join(runDir, 'harness-routing-v1.json')),
|
|
64
|
+
validationIds: [JSON.parse(fs.readFileSync(scoreFile, 'utf8')).id], calibrationInput: 'val-scores.jsonl',
|
|
65
|
+
calibrationInputSha256: hash(scoreFile), calibrationSha256: 'pending' };
|
|
66
|
+
fs.writeFileSync(path.join(runDir, 'layer-outcome.json'), JSON.stringify(outcome));
|
|
67
|
+
if (mode === 'exit') process.exit(7);
|
|
68
|
+
if (mode === 'limit' || mode === 'monitor') setInterval(() => {}, 1000);
|
|
69
|
+
`);
|
|
70
|
+
fs.chmodSync(runner, 0o700);
|
|
71
|
+
|
|
72
|
+
return { dataDir, runDir, runner, sentinelDir, outcomeFile: path.join(runDir, 'layer-outcome.json') };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
test('fitLayerStage uses the RSS guard, removes failed outcomes, and permits guarded retries', async t => {
|
|
76
|
+
const fixture = makeFixture(t);
|
|
77
|
+
const priorPython = process.env.PYTHON;
|
|
78
|
+
const priorMode = process.env.S571B_MODE;
|
|
79
|
+
const priorSentinel = process.env.S571B_SENTINEL;
|
|
80
|
+
process.env.PYTHON = process.execPath;
|
|
81
|
+
const guardResults = [];
|
|
82
|
+
let call = 0;
|
|
83
|
+
const run = async (command, args, limits) => {
|
|
84
|
+
assert.equal(command, process.execPath);
|
|
85
|
+
assert.equal(args[0], path.join(ROOT, 'scripts', 'system-one-fit-layer.py'),
|
|
86
|
+
'the fitter path must reach the existing guard call');
|
|
87
|
+
assert.equal(limits.maxRssMb, 24);
|
|
88
|
+
assert.equal(limits.threads, 2);
|
|
89
|
+
const marker = path.join(fixture.sentinelDir, `${++call}.reached`);
|
|
90
|
+
process.env.S571B_SENTINEL = marker;
|
|
91
|
+
const result = await runGuarded(process.execPath, [fixture.runner, ...args.slice(1)], {
|
|
92
|
+
...limits,
|
|
93
|
+
pollMs: 20,
|
|
94
|
+
rssReader: () => {
|
|
95
|
+
if (!fs.existsSync(marker)) return 0;
|
|
96
|
+
if (process.env.S571B_MODE === 'monitor') throw new Error('fixture monitor failure');
|
|
97
|
+
return process.env.S571B_MODE === 'limit' ? 25 : 0;
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
guardResults.push(result);
|
|
101
|
+
assert.equal(fs.readFileSync(marker, 'utf8'), 'guard reached\n', 'path-specific sentinel proves fake fitter ran');
|
|
102
|
+
return result;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
for (const [mode, expected] of [
|
|
107
|
+
['limit', /exceeded the 24 MB RSS limit/],
|
|
108
|
+
['monitor', /RSS monitoring failed/],
|
|
109
|
+
['exit', /system-one-fit-layer\.py failed \(7\)/],
|
|
110
|
+
]) {
|
|
111
|
+
process.env.S571B_MODE = mode;
|
|
112
|
+
fs.rmSync(fixture.outcomeFile, { force: true });
|
|
113
|
+
const failedCall = call + 1;
|
|
114
|
+
await assert.rejects(() => fitLayerStage({ dataDir: fixture.dataDir, runDir: fixture.runDir, task: 'tier',
|
|
115
|
+
maxRssMb: 24, threads: 2, run }), expected);
|
|
116
|
+
assert.ok(fs.existsSync(path.join(fixture.sentinelDir, `${failedCall}.reached`)), `${mode} reached the fake fitter`);
|
|
117
|
+
assert.deepEqual(JSON.parse(fs.readFileSync(fixture.outcomeFile, 'utf8')),
|
|
118
|
+
{ schemaVersion: 0, task: 'tier', failedFit: true }, `${mode} must leave only an invalid failure marker`);
|
|
119
|
+
assert.throws(() => validateFitStage({ dataDir: fixture.dataDir, runDir: fixture.runDir, task: 'tier' }), /fit outcome.*stale/i);
|
|
120
|
+
const failedGuard = guardResults.at(-1);
|
|
121
|
+
if (mode === 'limit') {
|
|
122
|
+
assert.equal(failedGuard.killedForLimit, true);
|
|
123
|
+
assert.ok(failedGuard.signal || failedGuard.exitCode !== 0, 'limit kill must be proven by process exit');
|
|
124
|
+
} else if (mode === 'monitor') {
|
|
125
|
+
assert.equal(failedGuard.monitorFailed, true);
|
|
126
|
+
assert.ok(failedGuard.signal || failedGuard.exitCode !== 0, 'monitor kill must be proven by process exit');
|
|
127
|
+
} else assert.equal(failedGuard.exitCode, 7);
|
|
128
|
+
|
|
129
|
+
process.env.S571B_MODE = 'success';
|
|
130
|
+
const retryCall = call + 1;
|
|
131
|
+
const outcome = await fitLayerStage({ dataDir: fixture.dataDir, runDir: fixture.runDir, task: 'tier',
|
|
132
|
+
maxRssMb: 24, threads: 2, run });
|
|
133
|
+
assert.ok(fs.existsSync(path.join(fixture.sentinelDir, `${retryCall}.reached`)), 'retry must execute the fitter');
|
|
134
|
+
assert.equal(outcome.outcome, 'keep-base');
|
|
135
|
+
const retryGuard = guardResults.at(-1);
|
|
136
|
+
assert.equal(retryGuard.exitCode, 0);
|
|
137
|
+
assert.equal(retryGuard.killedForLimit, false);
|
|
138
|
+
assert.equal(retryGuard.monitorFailed, false);
|
|
139
|
+
assert.doesNotThrow(() => validateFitStage({ dataDir: fixture.dataDir, runDir: fixture.runDir, task: 'tier' }));
|
|
140
|
+
fs.rmSync(fixture.outcomeFile);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
process.env.S571B_MODE = 'success';
|
|
144
|
+
await fitLayerStage({ dataDir: fixture.dataDir, runDir: fixture.runDir, task: 'tier', maxRssMb: 24, threads: 2, run });
|
|
145
|
+
const stale = JSON.parse(fs.readFileSync(fixture.outcomeFile, 'utf8'));
|
|
146
|
+
stale.checkpointConfigSha256 = '0'.repeat(64);
|
|
147
|
+
fs.writeFileSync(fixture.outcomeFile, JSON.stringify(stale));
|
|
148
|
+
process.env.S571B_MODE = 'exit';
|
|
149
|
+
await assert.rejects(() => fitLayerStage({ dataDir: fixture.dataDir, runDir: fixture.runDir, task: 'tier',
|
|
150
|
+
maxRssMb: 24, threads: 2, run }), /system-one-fit-layer\.py failed \(7\)/);
|
|
151
|
+
assert.deepEqual(JSON.parse(fs.readFileSync(fixture.outcomeFile, 'utf8')),
|
|
152
|
+
{ schemaVersion: 0, task: 'tier', failedFit: true }, 'a failed refit must not restore an older stale outcome');
|
|
153
|
+
assert.throws(() => validateFitStage({ dataDir: fixture.dataDir, runDir: fixture.runDir, task: 'tier' }), /fit outcome.*stale/i);
|
|
154
|
+
process.env.S571B_MODE = 'success';
|
|
155
|
+
const retryCall = call + 1;
|
|
156
|
+
const retry = await fitLayerStage({ dataDir: fixture.dataDir, runDir: fixture.runDir, task: 'tier',
|
|
157
|
+
maxRssMb: 24, threads: 2, run });
|
|
158
|
+
assert.ok(fs.existsSync(path.join(fixture.sentinelDir, `${retryCall}.reached`)), 'stale-outcome retry must execute the fitter');
|
|
159
|
+
assert.equal(retry.outcome, 'keep-base');
|
|
160
|
+
} finally {
|
|
161
|
+
if (priorPython === undefined) delete process.env.PYTHON; else process.env.PYTHON = priorPython;
|
|
162
|
+
if (priorMode === undefined) delete process.env.S571B_MODE; else process.env.S571B_MODE = priorMode;
|
|
163
|
+
if (priorSentinel === undefined) delete process.env.S571B_SENTINEL; else process.env.S571B_SENTINEL = priorSentinel;
|
|
164
|
+
}
|
|
165
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const test = require('node:test');
|
|
4
|
+
const assert = require('node:assert/strict');
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const os = require('node:os');
|
|
7
|
+
const { spawnSync } = require('node:child_process');
|
|
8
|
+
const path = require('node:path');
|
|
9
|
+
const { layerFitEvidence } = require('../scripts/system-one-curves');
|
|
10
|
+
const { fitEvidenceMatches } = require('../scripts/system-one-cycle/evaluate');
|
|
11
|
+
|
|
12
|
+
const ROOT = path.resolve(__dirname, '..');
|
|
13
|
+
|
|
14
|
+
test('fit selection NLL and OOF NLL retain distinct sources through the layer consumer', () => {
|
|
15
|
+
const program = String.raw`
|
|
16
|
+
import importlib.util, json, pathlib
|
|
17
|
+
root = pathlib.Path(${JSON.stringify(ROOT)})
|
|
18
|
+
def load(name, file):
|
|
19
|
+
spec = importlib.util.spec_from_file_location(name, file)
|
|
20
|
+
module = importlib.util.module_from_spec(spec)
|
|
21
|
+
spec.loader.exec_module(module)
|
|
22
|
+
return module
|
|
23
|
+
fit = load('fit', root / 'scripts/system-one-fit-layer.py')
|
|
24
|
+
layer = load('layer', root / 'harness-everything/scripts/system-one/layer.py')
|
|
25
|
+
rows = []
|
|
26
|
+
for fold, target in ((0, [1.0,0.0]), (1, [0.0,1.0])):
|
|
27
|
+
number = 0
|
|
28
|
+
while len([row for row in rows if fit.fold_for(row['id']) == fold]) < 2:
|
|
29
|
+
row_id = f'fold-{fold}-{number}'
|
|
30
|
+
number += 1
|
|
31
|
+
if fit.fold_for(row_id) == fold:
|
|
32
|
+
rows.append({'id':row_id,'text':row_id,'_targets':target})
|
|
33
|
+
logits = {row['id']:[0.0,0.0] for row in rows}
|
|
34
|
+
class Knn:
|
|
35
|
+
@staticmethod
|
|
36
|
+
def dist(_text, width): return [1 / width] * width
|
|
37
|
+
def fit_parameters(training, _logits, _task, use_bias):
|
|
38
|
+
if not use_bias: return 1.0, None
|
|
39
|
+
first = sum(row['_targets'][0] > 0 for row in training)
|
|
40
|
+
return 1.0, ([2.0,-2.0] if first >= len(training) - first else [-2.0,2.0])
|
|
41
|
+
layer_api = fit.load_layer_api()
|
|
42
|
+
selected = fit.select_recipe(rows, logits, 'tier', Knn(), layer_api, fit_parameters)
|
|
43
|
+
_recipes, oof = fit.cross_fit(rows, logits, 'tier', Knn(), layer_api, fit_parameters)
|
|
44
|
+
evidence = fit.nll_evidence(selected, rows, oof, 'tier')
|
|
45
|
+
artifact = {'schemaVersion':1,'kind':'echl-h','stage':'tier','options':['a','b'],
|
|
46
|
+
'temperature':selected['temperature'],'bias':selected['bias'],'alpha':selected['alpha'],'k':1,'ngrams':[3],'maxChars':20,
|
|
47
|
+
'index':[],'fit':{'candidate':selected['candidate'],'heldOutRows':len(rows),'nll':selected['nll'],
|
|
48
|
+
'baseNll':selected['baseNll'],'oof':True, **evidence}}
|
|
49
|
+
layer._validate_layer(artifact, 'tier', ['a','b'])
|
|
50
|
+
print(json.dumps({'evidence':evidence,'legacyNll':artifact['fit']['nll']}))
|
|
51
|
+
`;
|
|
52
|
+
const child = spawnSync(process.env.PYTHON || (process.platform === 'win32' ? 'python' : 'python3'),
|
|
53
|
+
['-B', '-c', program], { cwd: ROOT, encoding: 'utf8', env: { ...process.env, PYTHONDONTWRITEBYTECODE: '1' } });
|
|
54
|
+
assert.equal(child.status, 0, child.stderr || child.stdout);
|
|
55
|
+
const result = JSON.parse(child.stdout);
|
|
56
|
+
assert.equal(result.legacyNll, result.evidence.fitNll);
|
|
57
|
+
assert.ok(Number.isFinite(result.evidence.fitNll));
|
|
58
|
+
assert.ok(Number.isFinite(result.evidence.oofNll));
|
|
59
|
+
assert.notEqual(result.evidence.fitNll, result.evidence.oofNll);
|
|
60
|
+
assert.equal(result.evidence.fitNllSource, 'full-validation-recipe-selection');
|
|
61
|
+
assert.equal(result.evidence.oofNllSource, 'two-fold-cross-fit-validation');
|
|
62
|
+
assert.equal(fitEvidenceMatches(result.evidence, result.evidence), true);
|
|
63
|
+
assert.equal(fitEvidenceMatches(result.evidence, { ...result.evidence, oofNll: 9 }), false);
|
|
64
|
+
assert.equal(fitEvidenceMatches({}, { selectedNll: 0.2 }), true);
|
|
65
|
+
|
|
66
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'system-one-571-fit-evidence-'));
|
|
67
|
+
try {
|
|
68
|
+
fs.writeFileSync(path.join(dir, 'tier-layer.json'), JSON.stringify({ fit: {
|
|
69
|
+
...result.evidence, nll: result.legacyNll, baseNll: 0.8,
|
|
70
|
+
} }));
|
|
71
|
+
const report = layerFitEvidence({ stages: { tier: { layer: 'tier-layer.json' } } }, dir);
|
|
72
|
+
assert.deepEqual(report.tier.fitNll, { value: result.evidence.fitNll, source: 'full-validation-recipe-selection' });
|
|
73
|
+
assert.deepEqual(report.tier.oofNll, { value: result.evidence.oofNll, source: 'two-fold-cross-fit-validation' });
|
|
74
|
+
assert.deepEqual(report.tier.baseFitNll, { value: result.evidence.baseFitNll, source: 'full-validation-base-scores' });
|
|
75
|
+
assert.notEqual(report.tier.fitNll.value, report.tier.oofNll.value);
|
|
76
|
+
} finally {
|
|
77
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
78
|
+
}
|
|
79
|
+
});
|
|
@@ -205,6 +205,18 @@ test('441-A accepts trailing ASCII spaces or tabs on raw Codex STATUS and writes
|
|
|
205
205
|
assert.deepEqual(fs.readFileSync(output), Buffer.from('Summary\nSTATUS: DONE\n'));
|
|
206
206
|
assertOk(run(['check', '--file', output]));
|
|
207
207
|
|
|
208
|
+
// Raw Codex input remains normalized for both outcomes and padding forms.
|
|
209
|
+
for (const [rawStatus, status, reason, expected] of [
|
|
210
|
+
['STATUS: DONE ', 'DONE', null, 'STATUS: DONE'],
|
|
211
|
+
['STATUS: BLOCKED: verification unavailable\t', 'BLOCKED', 'verification unavailable', 'STATUS: BLOCKED: verification unavailable'],
|
|
212
|
+
]) {
|
|
213
|
+
fs.writeFileSync(raw, `Summary\n${rawStatus}\n`);
|
|
214
|
+
const args = writeArgs(output, status, ['--from-codex-output', raw], ...(reason ? ['--reason', reason] : []));
|
|
215
|
+
assertOk(run(args));
|
|
216
|
+
assert.deepEqual(fs.readFileSync(output), Buffer.from(`Summary\n${expected}\n`));
|
|
217
|
+
assertOk(run(['check', '--file', output]));
|
|
218
|
+
}
|
|
219
|
+
|
|
208
220
|
// Padded STATUS: BLOCKED followed by a blank line and an EOF host label.
|
|
209
221
|
const labeledRaw = Buffer.from(`Summary\nSTATUS: BLOCKED: verification unavailable \t\n\n${VALID_LABEL}\n`);
|
|
210
222
|
fs.writeFileSync(raw, labeledRaw);
|
|
@@ -371,6 +383,11 @@ test('check accepts one terminal status with LF or CRLF and rejects other contro
|
|
|
371
383
|
for (const invalid of [
|
|
372
384
|
'Summary',
|
|
373
385
|
'Summary\nSTATUS: DONE ',
|
|
386
|
+
'Summary\nSTATUS: DONE\t',
|
|
387
|
+
'Summary\nSTATUS: BLOCKED: reason ',
|
|
388
|
+
'Summary\nSTATUS: BLOCKED: reason\t',
|
|
389
|
+
'Summary\nSTATUS: BLOCKED: reason',
|
|
390
|
+
'Summary\nSTATUS: BLOCKED: reason ',
|
|
374
391
|
'Summary\n STATUS: DONE',
|
|
375
392
|
'Summary\nSTATUS: DONE\n\n',
|
|
376
393
|
'Summary\nSTATUS: DONE\ntrailing',
|
|
@@ -211,7 +211,8 @@ function layeredResumeFixture(t) {
|
|
|
211
211
|
fs.writeFileSync(valFiles[name], `${valRows[name].map(row => JSON.stringify(row)).join('\n')}\n`);
|
|
212
212
|
fs.writeFileSync(holdoutFiles[name], `${holdoutRows[name].map(row => JSON.stringify(row)).join('\n')}\n`);
|
|
213
213
|
}
|
|
214
|
-
const baseArgs = [cli, '--version', 'v1', '--version-dir', versionDir, '--history', history, '--out', out
|
|
214
|
+
const baseArgs = [cli, '--version', 'v1', '--version-dir', versionDir, '--history', history, '--out', out,
|
|
215
|
+
'--cycle-evidence'];
|
|
215
216
|
for (const name of Object.keys(stages)) {
|
|
216
217
|
baseArgs.push('--val-scores', `${name}=${valFiles[name]}`);
|
|
217
218
|
baseArgs.push('--holdout-scores', `${name}=${holdoutFiles[name]}`);
|
|
@@ -219,10 +220,10 @@ function layeredResumeFixture(t) {
|
|
|
219
220
|
const initial = spawnSync(process.execPath, baseArgs, { cwd: root, encoding: 'utf8', env: { ...process.env, HARNESS_SYSTEM_ONE_HOME: dir } });
|
|
220
221
|
assert.equal(initial.status, 0, initial.stderr);
|
|
221
222
|
const resume = () => spawnSync(process.execPath, [cli, '--version', 'v1', '--version-dir', versionDir,
|
|
222
|
-
'--history', history, '--out', out, '--resume-curves', path.join(out, 'curves.json'),
|
|
223
|
+
'--history', history, '--out', out, '--resume-curves', path.join(out, 'curves.json'), '--cycle-evidence',
|
|
223
224
|
...Object.keys(stages).flatMap(name => ['--val-scores', `${name}=${valFiles[name]}`, '--holdout-scores', `${name}=${holdoutFiles[name]}`])],
|
|
224
225
|
{ cwd: root, encoding: 'utf8', env: { ...process.env, HARNESS_SYSTEM_ONE_HOME: dir } });
|
|
225
|
-
return { valFile: valFiles.validity, layerPath, resume };
|
|
226
|
+
return { valFile: valFiles.validity, layerPath, versionDir, out, resume };
|
|
226
227
|
}
|
|
227
228
|
|
|
228
229
|
test('layered resume rejects score files that differ from the saved evaluation', t => {
|
|
@@ -230,14 +231,19 @@ test('layered resume rejects score files that differ from the saved evaluation',
|
|
|
230
231
|
fs.writeFileSync(valFile, `${JSON.stringify({ id: 'changed', gold: 'invalid', scores: { invalid: 0.8 } })}\n`);
|
|
231
232
|
const result = resume();
|
|
232
233
|
assert.notEqual(result.status, 0);
|
|
233
|
-
assert.match(result.stderr, /
|
|
234
|
+
assert.match(result.stderr, /saved-score-evaluation-evidence-is-stale/);
|
|
234
235
|
});
|
|
235
236
|
|
|
236
237
|
test('layered resume accepts the original score files and candidate', t => {
|
|
237
|
-
const { resume } = layeredResumeFixture(t);
|
|
238
|
+
const { resume, out } = layeredResumeFixture(t);
|
|
238
239
|
const result = resume();
|
|
239
240
|
assert.equal(result.status, 0, result.stderr);
|
|
240
241
|
assert.deepEqual(JSON.parse(result.stdout), { resumed: true, version: 'v1' });
|
|
242
|
+
const curves = JSON.parse(fs.readFileSync(path.join(out, 'curves.json'), 'utf8'));
|
|
243
|
+
assert.equal(curves.cycleEvidenceVersion, 1);
|
|
244
|
+
assert.match(curves.candidateDigest, /^[a-f0-9]{64}$/);
|
|
245
|
+
assert.deepEqual(Object.keys(curves.scoreDigests.validation).sort(), ['intent', 'tier', 'validity']);
|
|
246
|
+
assert.deepEqual(Object.keys(curves.scoreDigests.holdout).sort(), ['intent', 'tier', 'validity']);
|
|
241
247
|
});
|
|
242
248
|
|
|
243
249
|
test('layered resume rejects a layer whose bytes changed after evaluation', t => {
|
|
@@ -1282,6 +1282,79 @@ test('446 cross-cycle: resume keeps one immutable row, repairs a missing append,
|
|
|
1282
1282
|
assert.doesNotMatch(conflict.stderr, /synthetic-|holdout-|validation-/);
|
|
1283
1283
|
});
|
|
1284
1284
|
|
|
1285
|
+
test('new-cycle all-keep-base resume rejects candidate weights-only mutation before history changes', t => {
|
|
1286
|
+
const tmp = private446Root(t);
|
|
1287
|
+
const history = path.join(tmp, 'history.jsonl');
|
|
1288
|
+
const fixture = setup446Cycle(t, path.join(tmp, 'cycle'), [{ version: 'v1', quality: 0.9 }]);
|
|
1289
|
+
const initial = run446Cycle(fixture, 'v1', { history });
|
|
1290
|
+
assert.equal(initial.status, 0, initial.stderr || initial.stdout);
|
|
1291
|
+
const historyBefore = fs.readFileSync(history);
|
|
1292
|
+
const candidate = path.join(fixture.dataDir, 'training', 'candidates', 'v1');
|
|
1293
|
+
const manifestBefore = fs.readFileSync(path.join(candidate, 'manifest.json'));
|
|
1294
|
+
const evaluationDir = path.join(candidate, 'evaluation');
|
|
1295
|
+
const curvesFile = path.join(evaluationDir, 'curves.json');
|
|
1296
|
+
const curves = JSON.parse(fs.readFileSync(curvesFile, 'utf8'));
|
|
1297
|
+
assert.equal(curves.cycleEvidenceVersion, 1);
|
|
1298
|
+
assert.match(curves.candidateDigest, /^[a-f0-9]{64}$/);
|
|
1299
|
+
assert.deepEqual(Object.keys(curves.scoreDigests.validation).sort(), ['intent', 'tier', 'validity']);
|
|
1300
|
+
assert.deepEqual(Object.keys(curves.scoreDigests.holdout).sort(), ['intent', 'tier', 'validity']);
|
|
1301
|
+
const resume = run446Cycle(fixture, 'v1', { history });
|
|
1302
|
+
assert.equal(resume.status, 0, resume.stderr || resume.stdout, 'positive control: unmodified candidate resumes');
|
|
1303
|
+
assert.deepEqual(fs.readFileSync(history), historyBefore);
|
|
1304
|
+
|
|
1305
|
+
const source = path.join(fixture.dataDir, 'training', 'runs', 'v1');
|
|
1306
|
+
const validationFile = path.join(source, 'validity', 'val-scores.jsonl');
|
|
1307
|
+
const outcomeFile = path.join(source, 'validity', 'layer-outcome.json');
|
|
1308
|
+
const validationBefore = fs.readFileSync(validationFile);
|
|
1309
|
+
const outcomeBefore = fs.readFileSync(outcomeFile);
|
|
1310
|
+
const changedRows = JSON.parse(validationBefore.toString('utf8'));
|
|
1311
|
+
changedRows.scores.invalid = 0.37;
|
|
1312
|
+
writeJsonl(validationFile, [changedRows]);
|
|
1313
|
+
const outcome = JSON.parse(outcomeBefore.toString('utf8'));
|
|
1314
|
+
outcome.calibrationInputSha256 = digest(validationFile);
|
|
1315
|
+
fs.writeFileSync(outcomeFile, JSON.stringify(outcome));
|
|
1316
|
+
const rejectedScore = run446Cycle(fixture, 'v1', { history });
|
|
1317
|
+
assert.notEqual(rejectedScore.status, 0, 'changed fit-bound validation scores must reject resume');
|
|
1318
|
+
assert.match(rejectedScore.stderr, /saved-score-evaluation-evidence-is-stale/);
|
|
1319
|
+
assert.equal(fs.readFileSync(history).toString(), historyBefore.toString());
|
|
1320
|
+
fs.writeFileSync(validationFile, validationBefore);
|
|
1321
|
+
fs.writeFileSync(outcomeFile, outcomeBefore);
|
|
1322
|
+
|
|
1323
|
+
const holdoutFile = path.join(evaluationDir, 'validity-holdout-scores.jsonl');
|
|
1324
|
+
const holdoutBefore = fs.readFileSync(holdoutFile);
|
|
1325
|
+
const changedHoldout = JSON.parse(holdoutBefore.toString('utf8'));
|
|
1326
|
+
changedHoldout.scores.invalid = 0.31;
|
|
1327
|
+
writeJsonl(holdoutFile, [changedHoldout]);
|
|
1328
|
+
fs.writeFileSync(history, '');
|
|
1329
|
+
const rejectedHoldout = run446Cycle(fixture, 'v1', { history });
|
|
1330
|
+
assert.notEqual(rejectedHoldout.status, 0, 'changed holdout scores must reject resume');
|
|
1331
|
+
assert.match(rejectedHoldout.stderr, /saved-score-evaluation-evidence-is-stale/);
|
|
1332
|
+
assert.equal(fs.readFileSync(history).toString(), '', 'rejected missing-append reconciliation leaves history unchanged');
|
|
1333
|
+
fs.writeFileSync(history, historyBefore);
|
|
1334
|
+
fs.writeFileSync(holdoutFile, holdoutBefore);
|
|
1335
|
+
|
|
1336
|
+
const curvesBefore = fs.readFileSync(curvesFile);
|
|
1337
|
+
delete curves.cycleEvidenceVersion;
|
|
1338
|
+
delete curves.candidateDigest;
|
|
1339
|
+
delete curves.scoreDigests;
|
|
1340
|
+
fs.writeFileSync(curvesFile, JSON.stringify(curves, null, 2) + '\n');
|
|
1341
|
+
const rejectedUnbound = run446Cycle(fixture, 'v1', { history });
|
|
1342
|
+
assert.notEqual(rejectedUnbound.status, 0, 'older unbound cycle evidence must reject resume');
|
|
1343
|
+
assert.match(rejectedUnbound.stderr, /unbound-cycle-evaluation-cannot-resume/);
|
|
1344
|
+
assert.equal(fs.readFileSync(history).toString(), historyBefore.toString());
|
|
1345
|
+
fs.writeFileSync(curvesFile, curvesBefore);
|
|
1346
|
+
|
|
1347
|
+
const manifest = JSON.parse(manifestBefore.toString('utf8'));
|
|
1348
|
+
fs.appendFileSync(path.join(candidate, manifest.stages.validity.weights), 'tampered');
|
|
1349
|
+
assert.deepEqual(fs.readFileSync(path.join(candidate, 'manifest.json')), manifestBefore,
|
|
1350
|
+
'the mutation changes candidate weights only; manifest bytes stay fixed');
|
|
1351
|
+
const rejected = run446Cycle(fixture, 'v1', { history });
|
|
1352
|
+
assert.notEqual(rejected.status, 0, 'weights-only mutation must reject resume');
|
|
1353
|
+
assert.match(rejected.stderr, /candidate weights do not match its fit outcome/);
|
|
1354
|
+
assert.equal(fs.readFileSync(history).toString(), historyBefore.toString(),
|
|
1355
|
+
'rejected resume leaves immutable history byte-identical');
|
|
1356
|
+
});
|
|
1357
|
+
|
|
1285
1358
|
test('446 cross-cycle: default history remains local and explicit history validation fails closed', t => {
|
|
1286
1359
|
const tmp = private446Root(t);
|
|
1287
1360
|
const local = setup446Cycle(t, path.join(tmp, 'default-cycle'), [{ version: 'default-v0', quality: 0.9 }]);
|
|
@@ -120,11 +120,21 @@ def _validate_layer(layer, stage, options):
|
|
|
120
120
|
or not isinstance(layer.get('fit'), dict)):
|
|
121
121
|
_format_error()
|
|
122
122
|
fit = layer['fit']
|
|
123
|
-
|
|
123
|
+
legacy_fit_keys = {'candidate', 'heldOutRows', 'nll', 'baseNll', 'oof'}
|
|
124
|
+
evidence_keys = {'fitNll', 'fitNllSource', 'baseFitNll', 'baseFitNllSource', 'oofNll', 'oofNllSource'}
|
|
125
|
+
if (set(fit) not in (legacy_fit_keys, legacy_fit_keys | evidence_keys)
|
|
124
126
|
or not isinstance(fit['candidate'], str) or not fit['candidate']
|
|
125
127
|
or not _positive_int(fit['heldOutRows']) or not _finite_number(fit['nll'])
|
|
126
128
|
or not _finite_number(fit['baseNll']) or not isinstance(fit['oof'], bool)):
|
|
127
129
|
_format_error()
|
|
130
|
+
if evidence_keys.issubset(fit) and (
|
|
131
|
+
not _finite_number(fit['fitNll']) or fit['fitNll'] != fit['nll']
|
|
132
|
+
or fit['fitNllSource'] != 'full-validation-recipe-selection'
|
|
133
|
+
or not _finite_number(fit['baseFitNll']) or fit['baseFitNll'] != fit['baseNll']
|
|
134
|
+
or fit['baseFitNllSource'] != 'full-validation-base-scores'
|
|
135
|
+
or not _finite_number(fit['oofNll'])
|
|
136
|
+
or fit['oofNllSource'] != 'two-fold-cross-fit-validation'):
|
|
137
|
+
_format_error()
|
|
128
138
|
bias = layer.get('bias')
|
|
129
139
|
if bias is not None and (not isinstance(bias, list) or len(bias) != width
|
|
130
140
|
or any(not _finite_number(value) for value in bias)):
|
|
@@ -146,20 +146,33 @@ const FABLE_STRATEGIES = [
|
|
|
146
146
|
['fable-parallel', /\bfable[- ]parallel\b|\bparallel fable\b/i],
|
|
147
147
|
['fable-staged', /\bfable[- ]staged\b|\bstaged fable\b/i],
|
|
148
148
|
];
|
|
149
|
-
const
|
|
149
|
+
const FABLE_DIRECTIVE_VERBS = {
|
|
150
|
+
english: '(?:use|run|enter|switch\\s+to)',
|
|
151
|
+
chinese: '(?:使用|用|啟用|進入|執行|改用)',
|
|
152
|
+
};
|
|
153
|
+
const FABLE_PROHIBITION = new RegExp(
|
|
154
|
+
`\\b(?:no|without|do\\s+not|don't|never|cannot|can't|not)\\s+(?:(?:${FABLE_DIRECTIVE_VERBS.english})\\s+)?fable(?:[- ]mode)?\\b|(?:不要|不需要|無需|無須|不必|毋須|不用|別|勿|請勿|避免|停止|不)\\s*(?:(?:${FABLE_DIRECTIVE_VERBS.chinese})\\s*)?fable(?:[- ]mode)?`,
|
|
155
|
+
'i',
|
|
156
|
+
);
|
|
150
157
|
const FABLE_REQUEST_PREFIX = /^(?:(?:please|let's|now|could\s+you(?:\s+please)?|would\s+you(?:\s+please)?)\s+|(?:請|幫我|麻煩)\s*)*/i;
|
|
151
|
-
const FABLE_REQUEST_VERB =
|
|
152
|
-
const FABLE_NAMED_REQUEST =
|
|
153
|
-
const FABLE_PROFILE_REQUEST =
|
|
158
|
+
const FABLE_REQUEST_VERB = new RegExp(`^(?:${FABLE_DIRECTIVE_VERBS.english})\\s+fable(?:[- ]mode)?\\b|^(?:${FABLE_DIRECTIVE_VERBS.chinese})\\s*fable(?:[- ]mode)?`, 'i');
|
|
159
|
+
const FABLE_NAMED_REQUEST = new RegExp(`^(?:${FABLE_DIRECTIVE_VERBS.english}|改用)\\s+(fable[- ](?:multi[- ]agent[- ]workspace|parallel|staged))\\b`, 'i');
|
|
160
|
+
const FABLE_PROFILE_REQUEST = new RegExp(`^(?:${FABLE_DIRECTIVE_VERBS.english}|改用)\\s+fable(?:[- ]mode)?\\s+(?:on|with)\\s+(haiku|sonnet|sonnect|opus)\\b`, 'i');
|
|
161
|
+
const FABLE_QUOTE_PAIRS = new Map([
|
|
162
|
+
['"', '"'], ['`', '`'], ["'", "'"], ['“', '”'], ['‘', '’'],
|
|
163
|
+
['「', '」'], ['『', '』'], ['《', '》'],
|
|
164
|
+
]);
|
|
154
165
|
|
|
155
166
|
function splitFableDirectiveClauses(prompt) {
|
|
156
167
|
const text = String(prompt || '');
|
|
157
168
|
const parts = [];
|
|
158
169
|
let part = '';
|
|
170
|
+
let unquotedPart = '';
|
|
159
171
|
let quote = null;
|
|
160
172
|
const push = () => {
|
|
161
|
-
if (part.trim()) parts.push(part.trim());
|
|
173
|
+
if (part.trim()) parts.push({ text: part.trim(), unquotedText: unquotedPart.trim() });
|
|
162
174
|
part = '';
|
|
175
|
+
unquotedPart = '';
|
|
163
176
|
};
|
|
164
177
|
const wordSeparators = /^(?:and\s+then|and|then|also|plus|afterwards|additionally|but|並且|並|以及|接著|然後|另外)/iu;
|
|
165
178
|
|
|
@@ -170,10 +183,11 @@ function splitFableDirectiveClauses(prompt) {
|
|
|
170
183
|
part += char;
|
|
171
184
|
continue;
|
|
172
185
|
}
|
|
173
|
-
if (char
|
|
174
|
-
(char
|
|
175
|
-
quote = char
|
|
186
|
+
if (FABLE_QUOTE_PAIRS.has(char) &&
|
|
187
|
+
(char !== "'" || (!/[\p{L}\p{N}]/u.test(text[i - 1] || '') && /[\p{L}\p{N}]/u.test(text[i + 1] || '')))) {
|
|
188
|
+
quote = FABLE_QUOTE_PAIRS.get(char);
|
|
176
189
|
part += char;
|
|
190
|
+
unquotedPart += '\u0000';
|
|
177
191
|
continue;
|
|
178
192
|
}
|
|
179
193
|
if (/[;!??!,,;。、…]/u.test(char) || (char === '.' && (i + 1 === text.length || /\s/u.test(text[i + 1])))) {
|
|
@@ -188,6 +202,7 @@ function splitFableDirectiveClauses(prompt) {
|
|
|
188
202
|
continue;
|
|
189
203
|
}
|
|
190
204
|
part += char;
|
|
205
|
+
unquotedPart += char;
|
|
191
206
|
}
|
|
192
207
|
push();
|
|
193
208
|
return parts;
|
|
@@ -215,8 +230,8 @@ function detectFableDirective(prompt) {
|
|
|
215
230
|
let strategy = null;
|
|
216
231
|
let profile = null;
|
|
217
232
|
let prohibited = false;
|
|
218
|
-
for (const clause of clauses) {
|
|
219
|
-
const negated = FABLE_PROHIBITION.test(
|
|
233
|
+
for (const { text: clause, unquotedText } of clauses) {
|
|
234
|
+
const negated = FABLE_PROHIBITION.test(unquotedText);
|
|
220
235
|
if (negated) prohibited = true;
|
|
221
236
|
if (negated || strategy) continue;
|
|
222
237
|
const request = detectFableRequest(clause);
|
|
@@ -226,8 +241,8 @@ function detectFableDirective(prompt) {
|
|
|
226
241
|
}
|
|
227
242
|
}
|
|
228
243
|
if (!strategy) {
|
|
229
|
-
const linkedContinuations = clauses.slice(0, -1).flatMap((clause, index) => {
|
|
230
|
-
if (!isFableProfileLookup(clause, false) || !/^run\s+it\b/i.test(clauses[index + 1])) return [];
|
|
244
|
+
const linkedContinuations = clauses.slice(0, -1).flatMap(({ text: clause }, index) => {
|
|
245
|
+
if (!isFableProfileLookup(clause, false) || !/^run\s+it\b/i.test(clauses[index + 1].text)) return [];
|
|
231
246
|
const matches = clause.match(new RegExp(FABLE_PROFILE_INVOCATION.source, 'gi')) || [];
|
|
232
247
|
return matches.length === 1 ? [detectFableModel(clause)] : [];
|
|
233
248
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
|
|
3
3
|
"name": "harness-everything",
|
|
4
|
-
"version": "1.5.
|
|
4
|
+
"version": "1.5.2",
|
|
5
5
|
"description": "Invariant-first engineering harness for routing, verification, and failure recovery while preserving agent autonomy.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Miya Daniel",
|
|
@@ -120,11 +120,21 @@ def _validate_layer(layer, stage, options):
|
|
|
120
120
|
or not isinstance(layer.get('fit'), dict)):
|
|
121
121
|
_format_error()
|
|
122
122
|
fit = layer['fit']
|
|
123
|
-
|
|
123
|
+
legacy_fit_keys = {'candidate', 'heldOutRows', 'nll', 'baseNll', 'oof'}
|
|
124
|
+
evidence_keys = {'fitNll', 'fitNllSource', 'baseFitNll', 'baseFitNllSource', 'oofNll', 'oofNllSource'}
|
|
125
|
+
if (set(fit) not in (legacy_fit_keys, legacy_fit_keys | evidence_keys)
|
|
124
126
|
or not isinstance(fit['candidate'], str) or not fit['candidate']
|
|
125
127
|
or not _positive_int(fit['heldOutRows']) or not _finite_number(fit['nll'])
|
|
126
128
|
or not _finite_number(fit['baseNll']) or not isinstance(fit['oof'], bool)):
|
|
127
129
|
_format_error()
|
|
130
|
+
if evidence_keys.issubset(fit) and (
|
|
131
|
+
not _finite_number(fit['fitNll']) or fit['fitNll'] != fit['nll']
|
|
132
|
+
or fit['fitNllSource'] != 'full-validation-recipe-selection'
|
|
133
|
+
or not _finite_number(fit['baseFitNll']) or fit['baseFitNll'] != fit['baseNll']
|
|
134
|
+
or fit['baseFitNllSource'] != 'full-validation-base-scores'
|
|
135
|
+
or not _finite_number(fit['oofNll'])
|
|
136
|
+
or fit['oofNllSource'] != 'two-fold-cross-fit-validation'):
|
|
137
|
+
_format_error()
|
|
128
138
|
bias = layer.get('bias')
|
|
129
139
|
if bias is not None and (not isinstance(bias, list) or len(bias) != width
|
|
130
140
|
or any(not _finite_number(value) for value in bias)):
|