harness-everything 0.21.0 → 0.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +18 -0
- package/README.md +30 -0
- package/benchmarks/results/system-one/cua-s1-forms-resident-async-cpu-2026-09-23/README.md +87 -0
- package/benchmarks/results/system-one/cua-s1-forms-resident-async-cpu-2026-09-23/paired-latency.json +107 -0
- package/benchmarks/results/system-one/cua-s1-forms-resident-async-cpu-2026-09-23/report.json +856 -0
- package/benchmarks/results/system-one/cua-s1-forms-resident-cpu-2026-09-23/README.md +74 -0
- package/benchmarks/results/system-one/cua-s1-forms-resident-cpu-2026-09-23/report.json +856 -0
- package/benchmarks/results/system-one/pre-merge-review-2026-09-23/README.md +92 -0
- package/benchmarks/results/system-one/pre-merge-review-2026-09-23/haiku-spec-conformance.md +241 -0
- package/benchmarks/results/system-one/pre-merge-review-2026-09-23/luna-adversarial.md +212 -0
- package/benchmarks/results/system-one/pre-merge-review-2026-09-23/skill-top1-probe.js +83 -0
- package/benchmarks/results/system-one/pre-merge-review-2026-09-23/skill-top1-probe.json +7700 -0
- package/ci/fixtures/system-one-resident-stub.py +28 -0
- package/ci/fixtures/system-one-worker-probe.js +15 -0
- package/ci/mechanism-packaging-bytecode.test.js +61 -0
- package/ci/mechanism-system-one-install.test.js +11 -0
- package/ci/mechanism-system-one-resident.test.js +296 -0
- package/ci/mechanism-system-one-router.test.js +25 -0
- package/ci/system-one-adapter-test.py +166 -0
- package/docs/platform-capabilities.md +8 -0
- package/docs/system-one-routing.md +91 -3
- package/evals/pilot-router-nonsoftware/graders/no-tier-language.md +6 -0
- package/evals/pilot-router-nonsoftware/graders/skill-not-fired.md +9 -0
- package/evals/pilot-router-nonsoftware/prompt.md +8 -0
- package/evals/pilot-router-tier3/graders/skill-fired.md +6 -0
- package/evals/pilot-router-tier3/prompt.md +8 -0
- package/evals/pilot-tdd-bugfix/graders/skill-fired.md +6 -0
- package/evals/pilot-tdd-bugfix/prompt.md +8 -0
- package/evals/pilot-tdd-trivia/graders/no-red-phase-claim.md +7 -0
- package/evals/pilot-tdd-trivia/graders/skill-not-fired.md +9 -0
- package/evals/pilot-tdd-trivia/prompt.md +8 -0
- package/evals/pilot-verify-discussion/graders/no-verification-claim.md +7 -0
- package/evals/pilot-verify-discussion/graders/skill-not-fired.md +9 -0
- package/evals/pilot-verify-discussion/prompt.md +8 -0
- package/evals/pilot-verify-preship/graders/skill-fired.md +6 -0
- package/evals/pilot-verify-preship/prompt.md +8 -0
- package/harness-everything/SKILL.md +1 -1
- package/harness-everything/scripts/system-one/cua_adapter.py +265 -6
- package/harness-everything/scripts/system-one/install.js +17 -8
- package/harness-everything/scripts/system-one/provider.js +18 -3
- package/harness-everything/scripts/system-one/resident.js +200 -0
- package/harness-everything/scripts/system-one/router.js +18 -2
- package/harness-everything/scripts/tier-router.js +13 -4
- 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/plugin.json +1 -1
- package/plugins/harness-everything/scripts/lib/packaging-noise.js +6 -0
- package/plugins/harness-everything/scripts/lib/skills.js +2 -0
- package/plugins/harness-everything/skills/harness-everything/SKILL.md +1 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/cua_adapter.py +265 -6
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/install.js +17 -8
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/provider.js +18 -3
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/resident.js +200 -0
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/router.js +18 -2
- package/plugins/harness-everything/skills/harness-everything/scripts/tier-router.js +13 -4
- package/sbom.cdx.json +7 -7
- package/scripts/build-openai-submission.js +2 -0
- package/scripts/evaluate-system-one.js +18 -9
- package/scripts/lib/packaging-noise.js +6 -0
- package/scripts/lib/skills.js +2 -0
- package/scripts/sync-openai-plugin.js +2 -1
|
@@ -8,7 +8,8 @@ const path = require('node:path');
|
|
|
8
8
|
const { createHash } = require('node:crypto');
|
|
9
9
|
const { spawnSync } = require('node:child_process');
|
|
10
10
|
const { performance } = require('node:perf_hooks');
|
|
11
|
-
const { validateManifest, provenance, score, PINNED_CUA_S1_REVISION } = require('./provider');
|
|
11
|
+
const { validateManifest, readManifest, provenance, score, PINNED_CUA_S1_REVISION } = require('./provider');
|
|
12
|
+
const resident = require('./resident');
|
|
12
13
|
const { createRequest, decide } = require('./contract');
|
|
13
14
|
const { TIER_OPTIONS } = require('./router');
|
|
14
15
|
|
|
@@ -64,8 +65,8 @@ function buildManifest(dir, python) {
|
|
|
64
65
|
const manifest = { schemaVersion: 1, python, checkpoint: path.join(checkpointDir(dir), PINS.files.weights.name),
|
|
65
66
|
weightsSha256: PINS.files.weights.sha256, configSha256: PINS.files.config.sha256,
|
|
66
67
|
modelId: PINS.modelId, revision: PINS.modelRevision, domain: PINS.domain,
|
|
67
|
-
//
|
|
68
|
-
timeoutMs: 10000 };
|
|
68
|
+
// One-shot fallback budget (fresh Python + torch import per call); resident keeps the model loaded.
|
|
69
|
+
timeoutMs: 10000, transport: 'resident', idleTimeoutMs: 1800000 };
|
|
69
70
|
validateManifest(manifest);
|
|
70
71
|
return manifest;
|
|
71
72
|
}
|
|
@@ -85,7 +86,8 @@ async function ensureFile(url, dest, spec, fetcher = httpFetch) {
|
|
|
85
86
|
return 'downloaded';
|
|
86
87
|
}
|
|
87
88
|
function exec(cmd, args, capture = false) {
|
|
88
|
-
|
|
89
|
+
// Child progress goes to stderr (fd 2): stdout carries only the final JSON report.
|
|
90
|
+
const result = spawnSync(cmd, args, { shell: false, windowsHide: true, encoding: 'utf8', stdio: capture ? 'pipe' : ['ignore', 2, 2] });
|
|
89
91
|
if (result.error || result.status !== 0) throw new Error(`command-failed: ${[cmd, ...args].join(' ')}`);
|
|
90
92
|
return capture ? result.stdout.trim() : '';
|
|
91
93
|
}
|
|
@@ -108,20 +110,27 @@ function plan(opts) {
|
|
|
108
110
|
`${venvPy} -m pip install "${PINS.cuaS1Spec}"`,
|
|
109
111
|
...Object.values(PINS.files).map(f => `download ${fileUrl(f.name)} (sha256 ${f.sha256})`),
|
|
110
112
|
`write ${manifestPath}`,
|
|
111
|
-
'verify provenance (pinned revision)
|
|
113
|
+
'verify provenance (pinned revision), start the resident server, one warm CPU inference, stop it',
|
|
112
114
|
],
|
|
113
115
|
env: { HARNESS_SYSTEM_ONE_MODE: 'shadow', HARNESS_SYSTEM_ONE_CONFIG: manifestPath } };
|
|
114
116
|
}
|
|
117
|
+
// Starts the resident server (if needed), scores once warm, then stops a server it started.
|
|
115
118
|
function verify(manifestPath) {
|
|
116
119
|
const source = provenance(manifestPath);
|
|
120
|
+
const manifest = readManifest(manifestPath);
|
|
121
|
+
const wasRunning = resident.status(manifest, manifestPath).running;
|
|
122
|
+
const startMs = performance.now();
|
|
123
|
+
const ready = resident.ensureReady(manifest, manifestPath, 60000);
|
|
124
|
+
const readyMs = Math.round(performance.now() - startMs);
|
|
117
125
|
const request = createRequest('tier', 'fix a typo in README', TIER_OPTIONS);
|
|
118
126
|
const start = performance.now();
|
|
119
127
|
const result = score(request, manifestPath);
|
|
120
128
|
const latencyMs = Math.round(performance.now() - start);
|
|
129
|
+
if (!wasRunning) resident.stop(manifest, manifestPath);
|
|
121
130
|
const decision = result.status === 'scored' ? decide(request, result.response) : result;
|
|
122
131
|
const scores = result.status === 'scored' && decision.status !== 'invalid-output' ? result.response.scores : null;
|
|
123
|
-
const ok = source.status === 'recorded' && source.provenance.cuaS1.sourceRevisionStatus === 'pinned' && scores !== null;
|
|
124
|
-
return { ok, source, decision, scores, latencyMs };
|
|
132
|
+
const ok = ready && source.status === 'recorded' && source.provenance.cuaS1.sourceRevisionStatus === 'pinned' && scores !== null;
|
|
133
|
+
return { ok, source, residentReady: ready, readyMs, decision, scores, latencyMs };
|
|
125
134
|
}
|
|
126
135
|
async function main(argv) {
|
|
127
136
|
const opts = parseArgs(argv);
|
|
@@ -149,4 +158,4 @@ if (require.main === module) {
|
|
|
149
158
|
console.error(`System One install failed: ${err.message}`); process.exitCode = 1;
|
|
150
159
|
});
|
|
151
160
|
}
|
|
152
|
-
module.exports = { PINS, fileUrl, venvPython, supportedPython, pythonCandidates, parseArgs, buildManifest, ensureFile, plan, verify };
|
|
161
|
+
module.exports = { PINS, fileUrl, venvPython, supportedPython, pythonCandidates, parseArgs, buildManifest, ensureFile, exec, plan, verify };
|
|
@@ -13,11 +13,13 @@ const label = value => typeof value === 'string' && value.length > 0 && value.le
|
|
|
13
13
|
function validateManifest(m) {
|
|
14
14
|
const required = ['schemaVersion', 'python', 'checkpoint', 'weightsSha256', 'configSha256', 'modelId', 'revision', 'domain'];
|
|
15
15
|
if (!m || typeof m !== 'object' || Array.isArray(m) || required.some(k => !Object.hasOwn(m, k))
|
|
16
|
-
|| Object.keys(m).some(k => ![...required, 'timeoutMs'].includes(k)) || m.schemaVersion !== 1
|
|
16
|
+
|| Object.keys(m).some(k => ![...required, 'timeoutMs', 'transport', 'idleTimeoutMs'].includes(k)) || m.schemaVersion !== 1
|
|
17
17
|
|| ['python', 'modelId', 'revision', 'domain'].some(k => typeof m[k] !== 'string' || !m[k].trim() || m[k].length > 4096 || m[k].includes('\0'))
|
|
18
18
|
|| typeof m.checkpoint !== 'string' || !path.isAbsolute(m.checkpoint) || path.extname(m.checkpoint) !== '.safetensors'
|
|
19
19
|
|| ['weightsSha256', 'configSha256'].some(k => typeof m[k] !== 'string' || !/^[a-f0-9]{64}$/.test(m[k]))
|
|
20
20
|
|| (m.timeoutMs !== undefined && (!Number.isInteger(m.timeoutMs) || m.timeoutMs < 1 || m.timeoutMs > 10000))
|
|
21
|
+
|| (m.transport !== undefined && !['oneshot', 'resident'].includes(m.transport))
|
|
22
|
+
|| (m.idleTimeoutMs !== undefined && (!Number.isInteger(m.idleTimeoutMs) || m.idleTimeoutMs < 60000 || m.idleTimeoutMs > 14400000))
|
|
21
23
|
|| (m.modelId === 'cua-ai/cua-s1-forms' && m.domain !== 'forms-v1')) throw new TypeError('invalid-manifest');
|
|
22
24
|
return true;
|
|
23
25
|
}
|
|
@@ -48,7 +50,20 @@ function score(request, manifestPath) {
|
|
|
48
50
|
validateRequest(request);
|
|
49
51
|
let manifest;
|
|
50
52
|
try { manifest = readManifest(manifestPath); } catch (_) { return unavailable('provider-config'); }
|
|
51
|
-
|
|
53
|
+
if (manifest.transport === 'resident') return require('./resident').score({ ...request }, manifest, manifestPath);
|
|
54
|
+
return oneShot(request, manifest);
|
|
55
|
+
}
|
|
56
|
+
// Async callers (the hook entry) reach a resident server without the sync worker bridge.
|
|
57
|
+
// One-shot has no server to overlap with, so it runs the same child synchronously.
|
|
58
|
+
async function scoreAsync(request, manifestPath) {
|
|
59
|
+
validateRequest(request);
|
|
60
|
+
let manifest;
|
|
61
|
+
try { manifest = readManifest(manifestPath); } catch (_) { return unavailable('provider-config'); }
|
|
62
|
+
if (manifest.transport === 'resident') return require('./resident').scoreAsync({ ...request }, manifest, manifestPath);
|
|
63
|
+
return oneShot(request, manifest);
|
|
64
|
+
}
|
|
65
|
+
// Send the exact validated manifest to the child on stdin: no config reread race.
|
|
66
|
+
function oneShot(request, manifest) {
|
|
52
67
|
return runProvider({ ...request }, manifest.python, [ADAPTER, JSON.stringify(manifest)], manifest.timeoutMs || 2000);
|
|
53
68
|
}
|
|
54
69
|
// The probe reports what is installed; only a PEP 610 VCS commit counts as a source revision.
|
|
@@ -73,4 +88,4 @@ function provenance(manifestPath) {
|
|
|
73
88
|
try { return { status: 'recorded', provenance: validateProvenance(result.value) }; }
|
|
74
89
|
catch (_) { return unavailable('provider-json'); }
|
|
75
90
|
}
|
|
76
|
-
module.exports = { score, runProvider, validateManifest, provenance, validateProvenance, PINNED_CUA_S1_REVISION };
|
|
91
|
+
module.exports = { score, scoreAsync, runProvider, validateManifest, readManifest, provenance, validateProvenance, PINNED_CUA_S1_REVISION };
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
// Resident System One client: one verified model stays loaded in a loopback server.
|
|
4
|
+
// A score never blocks on model loading; a cold start returns provider-starting (lexical route wins).
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
const { createHash } = require('node:crypto');
|
|
8
|
+
const net = require('node:net');
|
|
9
|
+
const { spawn } = require('node:child_process');
|
|
10
|
+
const { Worker } = require('node:worker_threads');
|
|
11
|
+
const { validateRequest } = require('./contract');
|
|
12
|
+
|
|
13
|
+
const ADAPTER = path.join(__dirname, 'cua_adapter.py');
|
|
14
|
+
const LOCK_TTL_MS = 60000;
|
|
15
|
+
const CALL_TIMEOUT_MS = 1000;
|
|
16
|
+
const MAX_REPLY_BYTES = 1024 * 1024;
|
|
17
|
+
const unavailable = reason => ({ status: 'unavailable', reason });
|
|
18
|
+
const sleep = ms => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
19
|
+
const exact = (value, keys) => value && typeof value === 'object' && !Array.isArray(value)
|
|
20
|
+
&& Object.keys(value).length === keys.length && keys.every(k => Object.hasOwn(value, k));
|
|
21
|
+
const defaultCommand = manifest => [manifest.python, [ADAPTER, '--serve']];
|
|
22
|
+
|
|
23
|
+
function stateFiles(manifest, manifestPath) {
|
|
24
|
+
const digest = createHash('sha256').update(JSON.stringify(manifest)).digest('hex').slice(0, 16);
|
|
25
|
+
const base = path.join(path.dirname(manifestPath), `system-one-resident-${digest}`);
|
|
26
|
+
return { state: `${base}.json`, lock: `${base}.starting` };
|
|
27
|
+
}
|
|
28
|
+
function readState(file) {
|
|
29
|
+
try {
|
|
30
|
+
const s = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
31
|
+
if (exact(s, ['schemaVersion', 'pid', 'port', 'token', 'startedAt']) && s.schemaVersion === 1
|
|
32
|
+
&& Number.isInteger(s.pid) && s.pid > 0 && Number.isInteger(s.port) && s.port > 0 && s.port < 65536
|
|
33
|
+
&& typeof s.token === 'string' && /^[0-9a-f]{64}$/.test(s.token) && Number.isFinite(s.startedAt)) return s;
|
|
34
|
+
} catch (_) { /* absent or unreadable state means no usable server */ }
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
function lockInfo(file) {
|
|
38
|
+
try {
|
|
39
|
+
const ageMs = Date.now() - fs.statSync(file).mtimeMs;
|
|
40
|
+
let failed = null;
|
|
41
|
+
try { const body = JSON.parse(fs.readFileSync(file, 'utf8')); if (typeof body.failed === 'string') failed = body.failed; } catch (_) { /* partial write */ }
|
|
42
|
+
return { ageMs, failed };
|
|
43
|
+
} catch (_) { return null; }
|
|
44
|
+
}
|
|
45
|
+
function pidAlive(pid) {
|
|
46
|
+
try { process.kill(pid, 0); return true; } catch (err) { return err.code === 'EPERM'; }
|
|
47
|
+
}
|
|
48
|
+
function removeIfSame(file, state) {
|
|
49
|
+
const current = readState(file);
|
|
50
|
+
if (current && current.pid === state.pid && current.token === state.token) { try { fs.unlinkSync(file); } catch (_) { /* raced */ } }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// One socket round trip on a worker thread; the caller blocks with Atomics.wait (router API is synchronous).
|
|
54
|
+
const WORKER = `
|
|
55
|
+
const net = require('node:net');
|
|
56
|
+
const { workerData } = require('node:worker_threads');
|
|
57
|
+
const { port, payload, signal, out } = workerData;
|
|
58
|
+
const view = new Uint8Array(out); const chunks = []; let size = 0; let done = false;
|
|
59
|
+
const finish = (code, buf) => {
|
|
60
|
+
if (done) return; done = true;
|
|
61
|
+
if (buf) { view.set(buf); Atomics.store(signal, 1, buf.length); }
|
|
62
|
+
Atomics.store(signal, 0, code); Atomics.notify(signal, 0);
|
|
63
|
+
};
|
|
64
|
+
const socket = net.connect({ port, host: '127.0.0.1' }, () => socket.end(payload));
|
|
65
|
+
socket.on('data', c => { size += c.length; if (size > view.length) { finish(4); socket.destroy(); } else chunks.push(c); });
|
|
66
|
+
socket.on('end', () => finish(1, Buffer.concat(chunks)));
|
|
67
|
+
socket.on('error', e => finish(e.code === 'ECONNREFUSED' ? 2 : 3));
|
|
68
|
+
`;
|
|
69
|
+
function callSync(port, message, timeoutMs = CALL_TIMEOUT_MS) {
|
|
70
|
+
const signal = new Int32Array(new SharedArrayBuffer(8));
|
|
71
|
+
const out = new SharedArrayBuffer(MAX_REPLY_BYTES);
|
|
72
|
+
let worker;
|
|
73
|
+
try {
|
|
74
|
+
worker = new Worker(WORKER, { eval: true, workerData: { port, payload: `${JSON.stringify(message)}\n`, signal, out } });
|
|
75
|
+
worker.unref();
|
|
76
|
+
} catch (_) { return { error: 'io' }; }
|
|
77
|
+
Atomics.wait(signal, 0, 0, timeoutMs);
|
|
78
|
+
const code = Atomics.load(signal, 0);
|
|
79
|
+
worker.terminate();
|
|
80
|
+
if (code === 0) return { error: 'timeout' };
|
|
81
|
+
if (code !== 1) return { error: code === 2 ? 'refused' : code === 4 ? 'limit' : 'io' };
|
|
82
|
+
try { return { reply: JSON.parse(Buffer.from(out, 0, Atomics.load(signal, 1)).toString('utf8')) }; }
|
|
83
|
+
catch (_) { return { error: 'json' }; }
|
|
84
|
+
}
|
|
85
|
+
// The same round trip for async callers (the hook entry): no worker thread to bootstrap.
|
|
86
|
+
function callAsync(port, message, timeoutMs = CALL_TIMEOUT_MS) {
|
|
87
|
+
return new Promise(resolve => {
|
|
88
|
+
const chunks = []; let size = 0; let done = false; let socket = null;
|
|
89
|
+
const finish = value => { if (done) return; done = true; clearTimeout(timer); if (socket) socket.destroy(); resolve(value); };
|
|
90
|
+
const timer = setTimeout(() => finish({ error: 'timeout' }), timeoutMs);
|
|
91
|
+
socket = net.connect({ port, host: '127.0.0.1' }, () => socket.end(`${JSON.stringify(message)}\n`));
|
|
92
|
+
socket.on('data', c => { size += c.length; if (size > MAX_REPLY_BYTES) finish({ error: 'limit' }); else chunks.push(c); });
|
|
93
|
+
socket.on('end', () => {
|
|
94
|
+
try { finish({ reply: JSON.parse(Buffer.concat(chunks).toString('utf8')) }); } catch (_) { finish({ error: 'json' }); }
|
|
95
|
+
});
|
|
96
|
+
socket.on('error', e => finish({ error: e.code === 'ECONNREFUSED' ? 'refused' : 'io' }));
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function start(manifest, files, deps) {
|
|
101
|
+
const lock = lockInfo(files.lock);
|
|
102
|
+
if (lock && lock.ageMs < LOCK_TTL_MS) return unavailable(lock.failed ? 'provider-unavailable' : 'provider-starting');
|
|
103
|
+
if (lock) { try { fs.unlinkSync(files.lock); } catch (_) { /* another caller replaced it */ } }
|
|
104
|
+
try { fs.writeFileSync(files.lock, JSON.stringify({ createdAt: Date.now() }), { flag: 'wx', mode: 0o600 }); }
|
|
105
|
+
catch (_) { return unavailable('provider-starting'); }
|
|
106
|
+
let child = null;
|
|
107
|
+
try {
|
|
108
|
+
const [exe, prefix] = (deps.command || defaultCommand)(manifest);
|
|
109
|
+
child = spawn(exe, [...prefix, JSON.stringify(manifest), files.state, files.lock],
|
|
110
|
+
{ detached: true, stdio: 'ignore', windowsHide: true, shell: false });
|
|
111
|
+
child.on('error', () => { /* recorded synchronously below: a failed spawn has no pid */ });
|
|
112
|
+
child.unref();
|
|
113
|
+
} catch (_) { child = null; }
|
|
114
|
+
// The async 'error' event cannot run while callers block in Atomics.wait, so record the failure now.
|
|
115
|
+
if (!child || !child.pid) {
|
|
116
|
+
try { fs.writeFileSync(files.lock, JSON.stringify({ createdAt: Date.now(), failed: 'spawn-failed' })); } catch (_) { /* best effort */ }
|
|
117
|
+
return unavailable('provider-unavailable');
|
|
118
|
+
}
|
|
119
|
+
return unavailable('provider-starting');
|
|
120
|
+
}
|
|
121
|
+
// Returns a live server state, or null after removing state that provably belongs to a dead server.
|
|
122
|
+
function liveState(files) {
|
|
123
|
+
const state = readState(files.state);
|
|
124
|
+
if (state && !pidAlive(state.pid)) { removeIfSame(files.state, state); return null; }
|
|
125
|
+
return state;
|
|
126
|
+
}
|
|
127
|
+
function score(request, manifest, manifestPath, deps = {}) {
|
|
128
|
+
validateRequest(request);
|
|
129
|
+
const files = stateFiles(manifest, manifestPath);
|
|
130
|
+
const state = liveState(files);
|
|
131
|
+
if (!state) return start(manifest, files, deps);
|
|
132
|
+
return outcome(callSync(state.port, { token: state.token, op: 'score', request }), files, state, manifest, deps);
|
|
133
|
+
}
|
|
134
|
+
async function scoreAsync(request, manifest, manifestPath, deps = {}) {
|
|
135
|
+
validateRequest(request);
|
|
136
|
+
const files = stateFiles(manifest, manifestPath);
|
|
137
|
+
const state = liveState(files);
|
|
138
|
+
if (!state) return start(manifest, files, deps);
|
|
139
|
+
return outcome(await callAsync(state.port, { token: state.token, op: 'score', request }), files, state, manifest, deps);
|
|
140
|
+
}
|
|
141
|
+
function outcome(result, files, state, manifest, deps) {
|
|
142
|
+
if (result.reply) {
|
|
143
|
+
if (result.reply.ok === true && Object.hasOwn(result.reply, 'response')) return { status: 'scored', response: result.reply.response };
|
|
144
|
+
if (result.reply.ok === false) return unavailable(result.reply.reason === 'unauthorized' ? 'provider-unavailable' : 'provider-exit');
|
|
145
|
+
return unavailable('provider-json');
|
|
146
|
+
}
|
|
147
|
+
if (result.error === 'refused') { removeIfSame(files.state, state); return start(manifest, files, deps); }
|
|
148
|
+
return unavailable({ timeout: 'provider-timeout', limit: 'provider-output-limit', json: 'provider-json' }[result.error] || 'provider-unavailable');
|
|
149
|
+
}
|
|
150
|
+
function ping(state) {
|
|
151
|
+
const result = callSync(state.port, { token: state.token, op: 'ping' });
|
|
152
|
+
return result.reply && result.reply.ok === true ? result.reply : null;
|
|
153
|
+
}
|
|
154
|
+
function ensureReady(manifest, manifestPath, waitMs, deps = {}) {
|
|
155
|
+
const files = stateFiles(manifest, manifestPath);
|
|
156
|
+
const deadline = Date.now() + waitMs;
|
|
157
|
+
while (Date.now() < deadline) {
|
|
158
|
+
const state = liveState(files);
|
|
159
|
+
if (state && ping(state)) return true;
|
|
160
|
+
if (!state) {
|
|
161
|
+
const lock = lockInfo(files.lock);
|
|
162
|
+
if (lock && lock.failed && lock.ageMs < LOCK_TTL_MS) return false;
|
|
163
|
+
if (!lock || lock.ageMs >= LOCK_TTL_MS) start(manifest, files, deps);
|
|
164
|
+
}
|
|
165
|
+
sleep(100);
|
|
166
|
+
}
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
function status(manifest, manifestPath) {
|
|
170
|
+
const state = liveState(stateFiles(manifest, manifestPath));
|
|
171
|
+
const reply = state && ping(state);
|
|
172
|
+
return reply ? { running: true, pid: state.pid, port: state.port, startedAt: state.startedAt, model: reply.model } : { running: false };
|
|
173
|
+
}
|
|
174
|
+
function stop(manifest, manifestPath) {
|
|
175
|
+
const files = stateFiles(manifest, manifestPath);
|
|
176
|
+
const state = liveState(files);
|
|
177
|
+
if (!state) return false;
|
|
178
|
+
const result = callSync(state.port, { token: state.token, op: 'shutdown' });
|
|
179
|
+
if (!(result.reply && result.reply.ok === true)) {
|
|
180
|
+
try { process.kill(state.pid); } catch (_) { /* already exited */ }
|
|
181
|
+
removeIfSame(files.state, state);
|
|
182
|
+
}
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (require.main === module) {
|
|
187
|
+
const [op, manifestPath, extra] = process.argv.slice(2);
|
|
188
|
+
let manifest = null;
|
|
189
|
+
try {
|
|
190
|
+
if (!['start', 'status', 'stop'].includes(op) || extra) throw new Error('usage');
|
|
191
|
+
manifest = require('./provider').readManifest(manifestPath);
|
|
192
|
+
} catch (_) {
|
|
193
|
+
console.error('Usage: resident.js start|status|stop <absolute manifest path>');
|
|
194
|
+
process.exit(2);
|
|
195
|
+
}
|
|
196
|
+
if (op === 'start') process.exitCode = ensureReady(manifest, manifestPath, 60000) ? 0 : 1;
|
|
197
|
+
if (op === 'stop') stop(manifest, manifestPath);
|
|
198
|
+
process.stdout.write(`${JSON.stringify(status(manifest, manifestPath))}\n`);
|
|
199
|
+
}
|
|
200
|
+
module.exports = { stateFiles, readState, callSync, callAsync, score, scoreAsync, ensureReady, status, stop, LOCK_TTL_MS, CALL_TIMEOUT_MS };
|
|
@@ -23,7 +23,7 @@ function selectTier(input, env = process.env, scorer = provider.score) {
|
|
|
23
23
|
try { result = scorer(request, env.HARNESS_SYSTEM_ONE_CONFIG); }
|
|
24
24
|
catch (_) { return fallback('provider-unavailable'); }
|
|
25
25
|
if (!result || result.status !== 'scored') {
|
|
26
|
-
const allowed = ['provider-timeout', 'provider-output-limit', 'provider-exit', 'provider-json', 'provider-config', 'provider-unavailable'];
|
|
26
|
+
const allowed = ['provider-timeout', 'provider-output-limit', 'provider-exit', 'provider-json', 'provider-config', 'provider-unavailable', 'provider-starting'];
|
|
27
27
|
return fallback(allowed.includes(result?.reason) ? result.reason : 'provider-unavailable');
|
|
28
28
|
}
|
|
29
29
|
const decision = decide(request, result.response);
|
|
@@ -34,4 +34,20 @@ function selectTier(input, env = process.env, scorer = provider.score) {
|
|
|
34
34
|
const reason = input.explicit && accepted ? 'explicit-precedence' : belowFloor ? 'structural-floor' : decision.reason;
|
|
35
35
|
return { tier: applied ? LABELS[decision.selectedId] : input.tier, diagnostic: { mode, ...decision, applied, reason } };
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
// Hook entry: score the same fixed-catalog request asynchronously before routing (no sync worker bridge).
|
|
38
|
+
// Returns a scorer for selectTier, or null when System One is off/invalid; nothing is called then.
|
|
39
|
+
async function prescoreTier(prompt, env = process.env, scoreAsync = provider.scoreAsync) {
|
|
40
|
+
if (!['shadow', 'prefer'].includes(env.HARNESS_SYSTEM_ONE_MODE)) return null;
|
|
41
|
+
let request;
|
|
42
|
+
try { request = createRequest('tier', prompt, TIER_OPTIONS); }
|
|
43
|
+
catch (_) { return null; }
|
|
44
|
+
let result; let failed = false;
|
|
45
|
+
try { result = await scoreAsync(request, env.HARNESS_SYSTEM_ONE_CONFIG); }
|
|
46
|
+
catch (_) { failed = true; }
|
|
47
|
+
return (req, config) => {
|
|
48
|
+
if (req.requestHash !== request.requestHash) return provider.score(req, config);
|
|
49
|
+
if (failed) throw new Error('provider-unavailable');
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
module.exports = { selectTier, prescoreTier, TIER_OPTIONS };
|
|
@@ -231,7 +231,7 @@ function emitDynamicSkills(promptLower, context, recommendedGuides) {
|
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
-
function run(userPrompt, context) {
|
|
234
|
+
function run(userPrompt, context, options = {}) {
|
|
235
235
|
console.log(`[Tier Routing Pre-check]`);
|
|
236
236
|
|
|
237
237
|
const promptLower = userPrompt.toLowerCase();
|
|
@@ -317,7 +317,7 @@ function run(userPrompt, context) {
|
|
|
317
317
|
const structuralFloor = hasMacroSignal ? 'tier3'
|
|
318
318
|
: !isTrivialDocsEdit && hasMultipleTasks && hasMultipleSentences ? 'tier2' : null;
|
|
319
319
|
const semantic = selectTier({ prompt: userPrompt, tier: recommendedTier, floor: structuralFloor,
|
|
320
|
-
explicit: Boolean(detectExplicitStrategy(userPrompt, detectFableModel(userPrompt))) });
|
|
320
|
+
explicit: Boolean(detectExplicitStrategy(userPrompt, detectFableModel(userPrompt))) }, process.env, options.systemOneScorer || undefined);
|
|
321
321
|
if (semantic.diagnostic) console.log(`\n=> SYSTEM ONE: ${JSON.stringify(semantic.diagnostic)}`);
|
|
322
322
|
if (semantic.diagnostic?.applied) {
|
|
323
323
|
recommendedTier = semantic.tier;
|
|
@@ -460,12 +460,21 @@ function run(userPrompt, context) {
|
|
|
460
460
|
return contract;
|
|
461
461
|
}
|
|
462
462
|
|
|
463
|
+
// Entry point: pre-score System One asynchronously so routing never needs the sync worker bridge.
|
|
464
|
+
async function main(prompt, context) {
|
|
465
|
+
let systemOneScorer = null;
|
|
466
|
+
if (['shadow', 'prefer'].includes(process.env.HARNESS_SYSTEM_ONE_MODE)) {
|
|
467
|
+
try { systemOneScorer = await require('./system-one/router').prescoreTier(prompt); } catch (_) { /* the sync path still scores */ }
|
|
468
|
+
}
|
|
469
|
+
run(prompt, context, { systemOneScorer });
|
|
470
|
+
}
|
|
471
|
+
|
|
463
472
|
if (require.main === module) {
|
|
464
473
|
let userPrompt = process.argv[2] || '';
|
|
465
474
|
let hookContext = null;
|
|
466
475
|
|
|
467
476
|
if (process.argv[2]) {
|
|
468
|
-
|
|
477
|
+
main(userPrompt);
|
|
469
478
|
} else if (process.stdin.isTTY) {
|
|
470
479
|
run('');
|
|
471
480
|
} else {
|
|
@@ -482,7 +491,7 @@ if (process.argv[2]) {
|
|
|
482
491
|
} catch (err) {
|
|
483
492
|
// Not valid JSON on stdin - fall back to argv/manual behavior.
|
|
484
493
|
}
|
|
485
|
-
|
|
494
|
+
main(userPrompt, hookContext);
|
|
486
495
|
});
|
|
487
496
|
}
|
|
488
497
|
}
|
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": "0.
|
|
4
|
+
"version": "0.22.1",
|
|
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",
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Untracked local/CI build artifacts that no distribution (installer copy, plugin mirror,
|
|
3
|
+
// public submission) may ship, even when they exist in the working tree.
|
|
4
|
+
const isPackagingNoise = name => name === '__pycache__' || /\.py[co]$/.test(name);
|
|
5
|
+
|
|
6
|
+
module.exports = { isPackagingNoise };
|
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const manifest = require('./manifest');
|
|
5
|
+
const { isPackagingNoise } = require('./packaging-noise');
|
|
5
6
|
|
|
6
7
|
function copyDir(src, dest) {
|
|
7
8
|
fs.mkdirSync(dest, { recursive: true });
|
|
8
9
|
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
9
10
|
for (const entry of entries) {
|
|
11
|
+
if (isPackagingNoise(entry.name)) continue;
|
|
10
12
|
const srcPath = path.join(src, entry.name);
|
|
11
13
|
const destPath = path.join(dest, entry.name);
|
|
12
14
|
if (entry.isDirectory()) copyDir(srcPath, destPath);
|