harness-everything 0.50.0 → 0.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.github/workflows/ci.yml +23 -0
- package/CHANGELOG.md +174 -115
- package/benchmarks/results/doc-evidence-e1/cycle-2026-11-11-a-evid-001.md +123 -0
- package/benchmarks/results/doc-evidence-e1/cycle-2026-11-11-b-route-001.md +130 -0
- package/ci/mechanism-2am-observations-session-import.test.js +4 -1
- package/ci/mechanism-34-observations.test.js +127 -23
- package/ci/mechanism-349-ci-change-scope.test.js +260 -0
- package/ci/mechanism-handoff-file.test.js +121 -0
- package/ci/mechanism-prb-outline-review.test.js +783 -107
- package/ci/mechanism-system-one-contract.test.js +9 -2
- package/ci/mechanism-system-one-curves.test.js +206 -0
- package/ci/mechanism-system-one-cycle.test.js +585 -0
- package/ci/mechanism-system-one-evaluation.test.js +32 -5
- package/ci/mechanism-system-one-handoff-input.test.js +208 -0
- package/ci/mechanism-system-one-install.test.js +202 -77
- package/ci/mechanism-system-one-live.test.js +361 -0
- package/ci/mechanism-system-one-relevance.test.js +11 -1
- package/ci/mechanism-system-one-train.test.js +136 -53
- package/ci/release-unreleased-heading.test.js +24 -0
- package/ci/system-one-adapter-test.py +331 -0
- package/ci/system-one-train-test.py +116 -24
- package/docs/adr/EVID-001.md +123 -0
- package/docs/adr/ROUTE-001-error-lesson-delivery.md +305 -0
- package/docs/doc-workflow-reconciliation.md +29 -16
- package/docs/governed-index.md +2 -0
- package/docs/platform-capabilities.md +2 -0
- package/docs/routing.md +2 -2
- package/docs/system-one-cycle.md +68 -0
- package/docs/system-one-observations.md +9 -8
- package/docs/system-one-routing.md +163 -115
- package/docs/system-one-suggestion-gates.md +6 -8
- package/docs/system-one-training.md +44 -7
- package/docs/workflow-runtime.md +19 -0
- package/harness-everything/SKILL.md +1 -1
- package/harness-everything/scripts/kernel-router.js +2 -1
- package/harness-everything/scripts/system-one/contract.js +19 -15
- package/harness-everything/scripts/system-one/cua_adapter.py +211 -17
- package/harness-everything/scripts/system-one/evaluate.js +4 -9
- package/harness-everything/scripts/system-one/handoff-input.js +76 -0
- package/harness-everything/scripts/system-one/install.js +281 -113
- package/harness-everything/scripts/system-one/manifest.js +58 -0
- package/harness-everything/scripts/system-one/provider.js +96 -2
- package/harness-everything/scripts/system-one/resident.js +47 -1
- package/harness-everything/scripts/system-one/router.js +80 -1
- package/harness-everything/scripts/tier-router.js +21 -6
- package/hooks/scripts/lib/doc-reconciliation-pilot.js +12 -0
- package/hooks/scripts/lib/doc-reconciliation-provider.js +575 -12
- package/hooks/scripts/lib/observations.js +43 -4
- package/hooks/scripts/lib/workflow-obligations.js +8 -4
- package/hooks/scripts/state-persist.js +26 -7
- package/hooks/scripts/w6-state-operations.js +239 -0
- package/opencode-plugin/plugin.json +1 -1
- package/package.json +2 -2
- package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-pilot.js +12 -0
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-provider.js +575 -12
- package/plugins/harness-everything/hooks/scripts/lib/observations.js +43 -4
- package/plugins/harness-everything/hooks/scripts/lib/workflow-obligations.js +8 -4
- package/plugins/harness-everything/hooks/scripts/state-persist.js +26 -7
- package/plugins/harness-everything/hooks/scripts/w6-state-operations.js +239 -0
- package/plugins/harness-everything/plugin.json +1 -1
- package/plugins/harness-everything/scripts/handoff-file.js +223 -0
- package/plugins/harness-everything/skills/harness-everything/SKILL.md +1 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/kernel-router.js +2 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/contract.js +19 -15
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/cua_adapter.py +211 -17
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/evaluate.js +4 -9
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/handoff-input.js +76 -0
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/install.js +281 -113
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/manifest.js +58 -0
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/provider.js +96 -2
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/resident.js +47 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/router.js +80 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/tier-router.js +21 -6
- package/sbom.cdx.json +7 -7
- package/scripts/ci-change-scope.js +59 -0
- package/scripts/handoff-file.js +223 -0
- package/scripts/sync-openai-plugin.js +4 -0
- package/scripts/system-one-calibrate.js +108 -41
- package/scripts/system-one-curves.js +332 -0
- package/scripts/system-one-cycle/adjudication-input.js +65 -0
- package/scripts/system-one-cycle/build.js +165 -0
- package/scripts/system-one-cycle/collect.js +50 -0
- package/scripts/system-one-cycle/common.js +137 -0
- package/scripts/system-one-cycle/engines.js +62 -0
- package/scripts/system-one-cycle/evaluate.js +70 -0
- package/scripts/system-one-cycle/judge.js +106 -0
- package/scripts/system-one-cycle/label.js +59 -0
- package/scripts/system-one-cycle/package.js +173 -0
- package/scripts/system-one-cycle/score.py +111 -0
- package/scripts/system-one-cycle/train.js +136 -0
- package/scripts/system-one-cycle.js +131 -0
- package/scripts/system-one-observations-export.js +29 -6
- package/scripts/system-one-observations-review.js +4 -5
- package/scripts/system-one-train.py +117 -61
|
@@ -1,40 +1,73 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
|
-
// Opt-in
|
|
4
|
-
// It is never run from hooks, and it never changes the router mode; it prints the environment to set.
|
|
3
|
+
// Opt-in installer for private, versioned CUA-S1 checkpoints and their pinned runtime.
|
|
5
4
|
const fs = require('node:fs');
|
|
6
5
|
const os = require('node:os');
|
|
7
6
|
const path = require('node:path');
|
|
8
|
-
const { createHash } = require('node:crypto');
|
|
7
|
+
const { createHash, randomBytes } = require('node:crypto');
|
|
9
8
|
const { spawnSync } = require('node:child_process');
|
|
10
|
-
const {
|
|
11
|
-
const {
|
|
12
|
-
const resident = require('./resident');
|
|
13
|
-
const { createRequest, decide } = require('./contract');
|
|
14
|
-
const { TIER_OPTIONS } = require('./router');
|
|
9
|
+
const { PINNED_CUA_S1_REVISION } = require('./provider');
|
|
10
|
+
const { STAGES, validateVersionManifest } = require('./manifest');
|
|
15
11
|
|
|
16
12
|
const PINS = Object.freeze({
|
|
17
13
|
cuaS1Revision: PINNED_CUA_S1_REVISION,
|
|
18
14
|
cuaS1Spec: `cua-s1 @ git+https://github.com/trycua/cua@${PINNED_CUA_S1_REVISION}#subdirectory=libs/cua-s1/python`,
|
|
19
15
|
torchSpec: 'torch>=2.2,<3',
|
|
20
16
|
torchIndex: 'https://download.pytorch.org/whl/cpu',
|
|
21
|
-
modelId: 'cua-ai/cua-s1-forms',
|
|
22
|
-
modelRevision: 'f54adbf447f4ca6ec259f529ee3f2e3e09f8cc71',
|
|
23
|
-
domain: 'forms-v1',
|
|
24
|
-
// sha256/size from the Hugging Face tree API at modelRevision (LFS oid for weights; the JSON
|
|
25
|
-
// sidecar's git blob id d8f8426a... was re-hashed to confirm these exact CRLF bytes).
|
|
26
|
-
files: Object.freeze({
|
|
27
|
-
weights: Object.freeze({ name: 'cua-s1-forms.safetensors', size: 2828784, sha256: '05954c1caf51c2fb6c13ea4acbfc88a2e7653dea192252bb51dc89e76a356ddc' }),
|
|
28
|
-
config: Object.freeze({ name: 'cua-s1-forms.json', size: 1053, sha256: '62d31e2f9a001a8e9b6f8534c5194d07ebdd3f9d62ef1ac281906622992650ca' }),
|
|
29
|
-
}),
|
|
30
17
|
});
|
|
31
|
-
const USAGE = 'Usage: install.js [--dir <absolute
|
|
18
|
+
const USAGE = 'Usage: install.js install --from <local-path|git-ssh-url> --version <id> [--dir <absolute-dir>] [--python <3.11-3.13>] [--dry-run] | activate <id> | rollback | status';
|
|
19
|
+
|
|
20
|
+
const defaultDir = () => path.resolve(process.env.HARNESS_SYSTEM_ONE_HOME
|
|
21
|
+
|| path.join(os.homedir(), '.agents', 'harness-everything', 'system-one'));
|
|
22
|
+
const versionDir = (dir, version) => path.join(path.resolve(dir), 'versions', version);
|
|
23
|
+
const activePath = dir => path.join(path.resolve(dir), 'active.json');
|
|
24
|
+
const hash = bytes => createHash('sha256').update(bytes).digest('hex');
|
|
25
|
+
|
|
26
|
+
function validVersion(version) {
|
|
27
|
+
return typeof version === 'string' && /^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(version)
|
|
28
|
+
&& version !== '.' && version !== '..';
|
|
29
|
+
}
|
|
30
|
+
function assertVersion(version) {
|
|
31
|
+
if (!validVersion(version)) throw new Error('invalid-version: use a single safe version id');
|
|
32
|
+
}
|
|
33
|
+
function parseArgs(argv) {
|
|
34
|
+
const command = argv[0];
|
|
35
|
+
if (!['install', 'activate', 'rollback', 'status'].includes(command)) throw new Error('usage');
|
|
36
|
+
const opts = { command, dir: defaultDir() };
|
|
37
|
+
let positional = null;
|
|
38
|
+
const seen = new Set();
|
|
39
|
+
for (let i = 1; i < argv.length; i++) {
|
|
40
|
+
const arg = argv[i];
|
|
41
|
+
if (!arg.startsWith('--')) {
|
|
42
|
+
if (positional !== null) throw new Error('usage');
|
|
43
|
+
positional = arg;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (seen.has(arg)) throw new Error('usage');
|
|
47
|
+
seen.add(arg);
|
|
48
|
+
if (arg === '--dry-run' && command === 'install') { opts.dryRun = true; continue; }
|
|
49
|
+
if (!['--dir', '--python', '--from', '--version'].includes(arg)) throw new Error('usage');
|
|
50
|
+
const value = argv[++i];
|
|
51
|
+
if (!value || value.startsWith('--')) throw new Error('usage');
|
|
52
|
+
if (arg === '--dir') {
|
|
53
|
+
if (!path.isAbsolute(value)) throw new Error('usage');
|
|
54
|
+
opts.dir = path.resolve(value);
|
|
55
|
+
} else if (arg === '--python' && command === 'install') opts.python = value;
|
|
56
|
+
else if (arg === '--from' && command === 'install') opts.from = value;
|
|
57
|
+
else if (arg === '--version' && command === 'install') opts.version = value;
|
|
58
|
+
else throw new Error('usage');
|
|
59
|
+
}
|
|
60
|
+
if (command === 'install') {
|
|
61
|
+
if (positional !== null || !opts.from || !validVersion(opts.version)) throw new Error('usage');
|
|
62
|
+
if (opts.python === undefined) opts.python = null;
|
|
63
|
+
if (opts.dryRun === undefined) opts.dryRun = false;
|
|
64
|
+
} else if (command === 'activate') {
|
|
65
|
+
if (!validVersion(positional) || seen.has('--python') || seen.has('--from') || seen.has('--version') || seen.has('--dry-run')) throw new Error('usage');
|
|
66
|
+
opts.version = positional;
|
|
67
|
+
} else if (positional !== null || seen.has('--python') || seen.has('--from') || seen.has('--version') || seen.has('--dry-run')) throw new Error('usage');
|
|
68
|
+
return opts;
|
|
69
|
+
}
|
|
32
70
|
|
|
33
|
-
const defaultDir = () => path.join(os.homedir(), '.agents', 'harness-everything', 'system-one');
|
|
34
|
-
const fileUrl = name => `https://huggingface.co/${PINS.modelId}/resolve/${PINS.modelRevision}/${name}`;
|
|
35
|
-
const checkpointDir = dir => path.join(dir, 'checkpoints', PINS.modelRevision);
|
|
36
|
-
const venvPython = (dir, platform = process.platform) => (platform === 'win32'
|
|
37
|
-
? path.join(dir, 'venv', 'Scripts', 'python.exe') : path.join(dir, 'venv', 'bin', 'python'));
|
|
38
71
|
function supportedPython(version) {
|
|
39
72
|
const match = typeof version === 'string' && /^3\.(\d+)\.\d+$/.exec(version);
|
|
40
73
|
return Boolean(match) && Number(match[1]) >= 11 && Number(match[1]) <= 13;
|
|
@@ -44,54 +77,22 @@ function pythonCandidates(platform = process.platform) {
|
|
|
44
77
|
? [['py', '-3.13'], ['py', '-3.12'], ['py', '-3.11'], ['python'], ['python3']]
|
|
45
78
|
: [['python3.13'], ['python3.12'], ['python3.11'], ['python3'], ['python']];
|
|
46
79
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const flag = argv[i];
|
|
52
|
-
if (seen.has(flag)) throw new Error('usage');
|
|
53
|
-
seen.add(flag);
|
|
54
|
-
if (flag === '--dry-run') opts.dryRun = true;
|
|
55
|
-
else if (flag === '--dir' || flag === '--python') {
|
|
56
|
-
const value = argv[++i];
|
|
57
|
-
if (!value || value.startsWith('--')) throw new Error('usage');
|
|
58
|
-
if (flag === '--dir' && !path.isAbsolute(value)) throw new Error('usage');
|
|
59
|
-
opts[flag.slice(2)] = flag === '--dir' ? path.resolve(value) : value;
|
|
60
|
-
} else throw new Error('usage');
|
|
61
|
-
}
|
|
62
|
-
return opts;
|
|
63
|
-
}
|
|
64
|
-
function buildManifest(dir, python) {
|
|
65
|
-
const manifest = { schemaVersion: 1, python, checkpoint: path.join(checkpointDir(dir), PINS.files.weights.name),
|
|
66
|
-
weightsSha256: PINS.files.weights.sha256, configSha256: PINS.files.config.sha256,
|
|
67
|
-
modelId: PINS.modelId, revision: PINS.modelRevision, domain: PINS.domain,
|
|
68
|
-
// One-shot fallback budget (fresh Python + torch import per call); resident keeps the model loaded.
|
|
69
|
-
timeoutMs: 10000, transport: 'resident', idleTimeoutMs: 1800000 };
|
|
70
|
-
validateManifest(manifest);
|
|
71
|
-
return manifest;
|
|
72
|
-
}
|
|
73
|
-
const matches = (buf, spec) => buf.length === spec.size && createHash('sha256').update(buf).digest('hex') === spec.sha256;
|
|
74
|
-
async function httpFetch(url) {
|
|
75
|
-
const res = await fetch(url, { redirect: 'follow' });
|
|
76
|
-
if (!res.ok) throw new Error(`download-failed:${res.status}`);
|
|
77
|
-
return Buffer.from(await res.arrayBuffer());
|
|
78
|
-
}
|
|
79
|
-
async function ensureFile(url, dest, spec, fetcher = httpFetch) {
|
|
80
|
-
if (fs.existsSync(dest) && matches(fs.readFileSync(dest), spec)) return 'verified-existing';
|
|
81
|
-
const bytes = await fetcher(url);
|
|
82
|
-
if (!Buffer.isBuffer(bytes) || !matches(bytes, spec)) throw new Error(`download-verification:${spec.name}`);
|
|
83
|
-
const tmp = `${dest}.${process.pid}.tmp`;
|
|
84
|
-
fs.writeFileSync(tmp, bytes);
|
|
85
|
-
fs.renameSync(tmp, dest);
|
|
86
|
-
return 'downloaded';
|
|
87
|
-
}
|
|
80
|
+
const venvPython = (dir, platform = process.platform) => platform === 'win32'
|
|
81
|
+
? path.join(dir, 'venv', 'Scripts', 'python.exe') : path.join(dir, 'venv', 'bin', 'python');
|
|
82
|
+
const VERSION_PROBE = ['-c', 'import sys; print("%d.%d.%d" % sys.version_info[:3])'];
|
|
83
|
+
|
|
88
84
|
function exec(cmd, args, capture = false) {
|
|
89
|
-
// Child progress goes to stderr (fd 2): stdout carries only the final JSON report.
|
|
90
85
|
const result = spawnSync(cmd, args, { shell: false, windowsHide: true, encoding: 'utf8', stdio: capture ? 'pipe' : ['ignore', 2, 2] });
|
|
91
|
-
if (result.error || result.status !== 0) throw new Error(`command-failed: ${
|
|
86
|
+
if (result.error || result.status !== 0) throw new Error(`command-failed: ${path.basename(cmd)}`);
|
|
92
87
|
return capture ? result.stdout.trim() : '';
|
|
93
88
|
}
|
|
94
|
-
|
|
89
|
+
function git(args) {
|
|
90
|
+
const result = spawnSync('git', args, {
|
|
91
|
+
shell: false, windowsHide: true, encoding: 'utf8', stdio: 'ignore',
|
|
92
|
+
env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },
|
|
93
|
+
});
|
|
94
|
+
if (result.error || result.status !== 0) throw new Error('private-source-unavailable: check the SSH URL and SSH access');
|
|
95
|
+
}
|
|
95
96
|
function findPython(explicit) {
|
|
96
97
|
for (const [cmd, ...pre] of explicit ? [[explicit]] : pythonCandidates()) {
|
|
97
98
|
const result = spawnSync(cmd, [...pre, ...VERSION_PROBE], { shell: false, windowsHide: true, encoding: 'utf8' });
|
|
@@ -100,62 +101,229 @@ function findPython(explicit) {
|
|
|
100
101
|
}
|
|
101
102
|
throw new Error(explicit ? 'python-unsupported: need Python 3.11-3.13' : 'python-not-found: install Python 3.11-3.13 or pass --python');
|
|
102
103
|
}
|
|
104
|
+
|
|
105
|
+
function sourceKind(source) {
|
|
106
|
+
if (typeof source !== 'string' || !source) throw new Error('invalid-source: expected local path or Git SSH URL');
|
|
107
|
+
if (fs.existsSync(source)) return 'local';
|
|
108
|
+
if (typeof source === 'string' && source.startsWith('ssh://')) {
|
|
109
|
+
let remote;
|
|
110
|
+
try { remote = new URL(source); } catch { throw new Error('invalid-source: expected local path or Git SSH URL'); }
|
|
111
|
+
if (!remote.hostname || remote.password || (remote.username && !/^[A-Za-z0-9._-]+$/.test(remote.username))
|
|
112
|
+
|| remote.search || remote.hash) throw new Error('invalid-source: expected local path or Git SSH URL');
|
|
113
|
+
return 'ssh';
|
|
114
|
+
}
|
|
115
|
+
if (/^[A-Za-z][A-Za-z0-9+.-]*:\/\//.test(source)) throw new Error('invalid-source: expected local path or Git SSH URL');
|
|
116
|
+
if (/^(?:[A-Za-z0-9._-]+@)?[A-Za-z0-9.-]+:[A-Za-z0-9_./-]+$/.test(source || '')) return 'ssh';
|
|
117
|
+
throw new Error('invalid-source: expected local path or Git SSH URL');
|
|
118
|
+
}
|
|
119
|
+
function checkpointSource(source, version, dir) {
|
|
120
|
+
const kind = sourceKind(source);
|
|
121
|
+
if (kind === 'local') return { dir: path.join(fs.realpathSync.native(source), 'models', 'cua-s1', version), cleanup() {} };
|
|
122
|
+
const cacheRoot = path.join(dir, 'cache');
|
|
123
|
+
fs.mkdirSync(cacheRoot, { recursive: true });
|
|
124
|
+
const cacheDir = fs.mkdtempSync(path.join(cacheRoot, 'source-'));
|
|
125
|
+
const repo = path.join(cacheDir, 'repo');
|
|
126
|
+
try {
|
|
127
|
+
git(['clone', '--depth', '1', '--filter=blob:none', '--sparse', source, repo]);
|
|
128
|
+
git(['-C', repo, 'sparse-checkout', 'set', `models/cua-s1/${version}`]);
|
|
129
|
+
return { dir: path.join(repo, 'models', 'cua-s1', version), cleanup() { fs.rmSync(cacheDir, { recursive: true, force: true }); } };
|
|
130
|
+
} catch (error) {
|
|
131
|
+
fs.rmSync(cacheDir, { recursive: true, force: true });
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function resolveManifestFile(root, relative) {
|
|
137
|
+
if (typeof relative !== 'string' || !relative || relative.includes('\\') || path.isAbsolute(relative)
|
|
138
|
+
|| path.win32.isAbsolute(relative) || relative.split('/').some(part => !part || part === '.' || part === '..')) {
|
|
139
|
+
throw new Error('invalid-manifest: file paths must stay inside the checkpoint');
|
|
140
|
+
}
|
|
141
|
+
let current = root;
|
|
142
|
+
const parts = relative.split('/');
|
|
143
|
+
for (let i = 0; i < parts.length; i++) {
|
|
144
|
+
current = path.join(current, parts[i]);
|
|
145
|
+
const stat = fs.lstatSync(current);
|
|
146
|
+
if (stat.isSymbolicLink() || (i < parts.length - 1 ? !stat.isDirectory() : !stat.isFile())) {
|
|
147
|
+
throw new Error('invalid-manifest: checkpoint files must be regular files without symlink components');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return { path: current, relative: parts.join(path.sep) };
|
|
151
|
+
}
|
|
152
|
+
function readCheckpoint(dir, version) {
|
|
153
|
+
assertVersion(version);
|
|
154
|
+
const root = fs.realpathSync.native(dir);
|
|
155
|
+
const manifestFile = resolveManifestFile(root, 'manifest.json');
|
|
156
|
+
let manifest;
|
|
157
|
+
try { manifest = JSON.parse(fs.readFileSync(manifestFile.path, 'utf8')); }
|
|
158
|
+
catch { throw new Error('invalid-manifest: manifest.json is not valid JSON'); }
|
|
159
|
+
validateVersionManifest(manifest, version);
|
|
160
|
+
const files = new Map([['manifest.json', manifestFile]]);
|
|
161
|
+
for (const stage of STAGES) {
|
|
162
|
+
const record = manifest.stages[stage];
|
|
163
|
+
const weights = resolveManifestFile(root, record.weights);
|
|
164
|
+
const config = resolveManifestFile(root, record.config);
|
|
165
|
+
if (hash(fs.readFileSync(weights.path)) !== record.sha256) throw new Error(`checkpoint-hash-mismatch: ${stage}`);
|
|
166
|
+
files.set(weights.relative, weights); files.set(config.relative, config);
|
|
167
|
+
}
|
|
168
|
+
if (manifest.evaluation !== null) {
|
|
169
|
+
const evaluation = resolveManifestFile(root, manifest.evaluation);
|
|
170
|
+
files.set(evaluation.relative, evaluation);
|
|
171
|
+
}
|
|
172
|
+
return { root, manifest, files: [...files.values()] };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function installVersion(source, version, dir = defaultDir()) {
|
|
176
|
+
assertVersion(version);
|
|
177
|
+
dir = path.resolve(dir);
|
|
178
|
+
const resolved = checkpointSource(source, version, dir);
|
|
179
|
+
try {
|
|
180
|
+
const checkpoint = readCheckpoint(resolved.dir, version);
|
|
181
|
+
const versions = path.join(dir, 'versions');
|
|
182
|
+
fs.mkdirSync(versions, { recursive: true });
|
|
183
|
+
if (fs.lstatSync(versions).isSymbolicLink()) throw new Error('invalid-install-dir: versions directory cannot be a symlink');
|
|
184
|
+
const target = versionDir(dir, version);
|
|
185
|
+
if (fs.existsSync(target)) {
|
|
186
|
+
if (fs.lstatSync(target).isSymbolicLink()) throw new Error('invalid-install-dir: version directory cannot be a symlink');
|
|
187
|
+
const existing = readCheckpoint(target, version);
|
|
188
|
+
const same = checkpoint.files.every(file => {
|
|
189
|
+
const relative = path.relative(checkpoint.root, file.path);
|
|
190
|
+
const other = path.join(existing.root, relative);
|
|
191
|
+
return fs.existsSync(other) && fs.readFileSync(file.path).equals(fs.readFileSync(other));
|
|
192
|
+
});
|
|
193
|
+
if (!same) throw new Error(`version-conflict: ${version} is already installed with different files`);
|
|
194
|
+
return { version, dir: target, status: 'already-installed' };
|
|
195
|
+
}
|
|
196
|
+
const staging = fs.mkdtempSync(path.join(versions, `.${version}.`));
|
|
197
|
+
try {
|
|
198
|
+
for (const file of checkpoint.files) {
|
|
199
|
+
const relative = path.relative(checkpoint.root, file.path);
|
|
200
|
+
const dest = path.join(staging, relative);
|
|
201
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
202
|
+
fs.copyFileSync(file.path, dest, fs.constants.COPYFILE_EXCL);
|
|
203
|
+
}
|
|
204
|
+
fs.renameSync(staging, target);
|
|
205
|
+
} catch (error) {
|
|
206
|
+
fs.rmSync(staging, { recursive: true, force: true });
|
|
207
|
+
throw error;
|
|
208
|
+
}
|
|
209
|
+
return { version, dir: target, status: 'installed' };
|
|
210
|
+
} finally { resolved.cleanup(); }
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function readActive(dir = defaultDir()) {
|
|
214
|
+
const file = activePath(dir);
|
|
215
|
+
if (!fs.existsSync(file)) return null;
|
|
216
|
+
let active;
|
|
217
|
+
try { active = JSON.parse(fs.readFileSync(file, 'utf8')); }
|
|
218
|
+
catch { throw new Error('invalid-active-pointer: active.json is not valid JSON'); }
|
|
219
|
+
if (!active || active.schemaVersion !== 1 || !validVersion(active.version)
|
|
220
|
+
|| !(active.previous === null || validVersion(active.previous))
|
|
221
|
+
|| !path.isAbsolute(active.dir) || path.resolve(active.dir) !== versionDir(dir, active.version)
|
|
222
|
+
|| typeof active.activatedAt !== 'string' || !Number.isFinite(Date.parse(active.activatedAt))) {
|
|
223
|
+
throw new Error('invalid-active-pointer: expected the versioned active.json contract');
|
|
224
|
+
}
|
|
225
|
+
return active;
|
|
226
|
+
}
|
|
227
|
+
function writeActive(dir, value) {
|
|
228
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
229
|
+
const file = activePath(dir);
|
|
230
|
+
const temp = `${file}.${process.pid}.${randomBytes(6).toString('hex')}.tmp`;
|
|
231
|
+
let fd;
|
|
232
|
+
try {
|
|
233
|
+
fd = fs.openSync(temp, 'wx', 0o600);
|
|
234
|
+
fs.writeFileSync(fd, `${JSON.stringify(value, null, 2)}\n`);
|
|
235
|
+
fs.fsyncSync(fd);
|
|
236
|
+
fs.closeSync(fd); fd = undefined;
|
|
237
|
+
fs.renameSync(temp, file);
|
|
238
|
+
} catch (error) {
|
|
239
|
+
if (fd !== undefined) fs.closeSync(fd);
|
|
240
|
+
fs.rmSync(temp, { force: true });
|
|
241
|
+
throw new Error(`active-pointer-write-failed: ${error.message}`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
function activate(version, dir = defaultDir()) {
|
|
245
|
+
assertVersion(version);
|
|
246
|
+
const target = versionDir(dir, version);
|
|
247
|
+
readCheckpoint(target, version);
|
|
248
|
+
const current = readActive(dir);
|
|
249
|
+
if (current && current.version === version) return current;
|
|
250
|
+
const next = {
|
|
251
|
+
schemaVersion: 1, version, dir: path.resolve(target),
|
|
252
|
+
previous: current ? current.version : null, activatedAt: new Date().toISOString(),
|
|
253
|
+
};
|
|
254
|
+
writeActive(dir, next);
|
|
255
|
+
return next;
|
|
256
|
+
}
|
|
257
|
+
function rollback(dir = defaultDir()) {
|
|
258
|
+
const current = readActive(dir);
|
|
259
|
+
if (!current || !current.previous) throw new Error('rollback-unavailable: no previous version is recorded');
|
|
260
|
+
return activate(current.previous, dir);
|
|
261
|
+
}
|
|
262
|
+
function versionStatus(dir, version) {
|
|
263
|
+
if (!version) return null;
|
|
264
|
+
try {
|
|
265
|
+
const { manifest } = readCheckpoint(versionDir(dir, version), version);
|
|
266
|
+
return { version, hashesOk: true, hashes: Object.fromEntries(STAGES.map(stage => [stage, manifest.stages[stage].sha256])) };
|
|
267
|
+
} catch {
|
|
268
|
+
return { version, hashesOk: false, hashes: null };
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
function status(dir = defaultDir()) {
|
|
272
|
+
const active = readActive(dir);
|
|
273
|
+
const mode = process.env.HARNESS_SYSTEM_ONE_MODE || 'off';
|
|
274
|
+
return {
|
|
275
|
+
active: active ? versionStatus(dir, active.version) : null,
|
|
276
|
+
previous: active ? versionStatus(dir, active.previous) : null,
|
|
277
|
+
mode,
|
|
278
|
+
modeHint: mode === 'live' ? 'HARNESS_SYSTEM_ONE_MODE=live' : 'Set HARNESS_SYSTEM_ONE_MODE=live to opt in to the active checkpoint.',
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
|
|
103
282
|
function plan(opts) {
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
283
|
+
const kind = sourceKind(opts.from);
|
|
284
|
+
return {
|
|
285
|
+
dir: opts.dir, version: opts.version, manifest: path.join(versionDir(opts.dir, opts.version), 'manifest.json'),
|
|
286
|
+
sourceKind: kind,
|
|
107
287
|
steps: [
|
|
288
|
+
`copy and verify models/cua-s1/${opts.version} from ${kind} source`,
|
|
108
289
|
`create venv ${path.join(opts.dir, 'venv')} with ${opts.python || 'first Python 3.11-3.13 found'}`,
|
|
109
|
-
`${
|
|
110
|
-
`${
|
|
111
|
-
...Object.values(PINS.files).map(f => `download ${fileUrl(f.name)} (sha256 ${f.sha256})`),
|
|
112
|
-
`write ${manifestPath}`,
|
|
113
|
-
'verify provenance (pinned revision), start the resident server, one warm CPU inference, stop it',
|
|
290
|
+
`${venvPython(opts.dir)} -m pip install --index-url ${PINS.torchIndex} "${PINS.torchSpec}"`,
|
|
291
|
+
`${venvPython(opts.dir)} -m pip install "${PINS.cuaS1Spec}"`,
|
|
114
292
|
],
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function
|
|
119
|
-
const
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const latencyMs = Math.round(performance.now() - start);
|
|
129
|
-
if (!wasRunning) resident.stop(manifest, manifestPath);
|
|
130
|
-
const decision = result.status === 'scored' ? decide(request, result.response) : result;
|
|
131
|
-
const scores = result.status === 'scored' && decision.status !== 'invalid-output' ? result.response.scores : null;
|
|
132
|
-
const ok = ready && source.status === 'recorded' && source.provenance.cuaS1.sourceRevisionStatus === 'pinned' && scores !== null;
|
|
133
|
-
return { ok, source, residentReady: ready, readyMs, decision, scores, latencyMs };
|
|
293
|
+
modeHint: 'Set HARNESS_SYSTEM_ONE_MODE=live after review; installation does not activate the checkpoint.',
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
function setupRuntime(dir, explicitPython) {
|
|
297
|
+
const base = findPython(explicitPython);
|
|
298
|
+
const venv = path.join(dir, 'venv'); const python = venvPython(dir);
|
|
299
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
300
|
+
if (!fs.existsSync(python)) exec(base.cmd, [...base.pre, '-m', 'venv', venv]);
|
|
301
|
+
const version = exec(python, VERSION_PROBE, true);
|
|
302
|
+
if (!supportedPython(version)) throw new Error(`python-unsupported: existing venv uses ${version}`);
|
|
303
|
+
exec(python, ['-m', 'pip', 'install', '--disable-pip-version-check', '--index-url', PINS.torchIndex, PINS.torchSpec]);
|
|
304
|
+
exec(python, ['-m', 'pip', 'install', '--disable-pip-version-check', PINS.cuaS1Spec]);
|
|
305
|
+
return { python, version };
|
|
134
306
|
}
|
|
135
307
|
async function main(argv) {
|
|
136
308
|
const opts = parseArgs(argv);
|
|
309
|
+
if (opts.command === 'activate') { process.stdout.write(`${JSON.stringify(activate(opts.version, opts.dir), null, 2)}\n`); return 0; }
|
|
310
|
+
if (opts.command === 'rollback') { process.stdout.write(`${JSON.stringify(rollback(opts.dir), null, 2)}\n`); return 0; }
|
|
311
|
+
if (opts.command === 'status') { process.stdout.write(`${JSON.stringify(status(opts.dir), null, 2)}\n`); return 0; }
|
|
137
312
|
const p = plan(opts);
|
|
138
313
|
if (opts.dryRun) { process.stdout.write(`${JSON.stringify({ dryRun: true, ...p }, null, 2)}\n`); return 0; }
|
|
139
|
-
const
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const venvVersion = exec(venvPy, VERSION_PROBE, true);
|
|
144
|
-
if (!supportedPython(venvVersion)) throw new Error(`python-unsupported: existing venv uses ${venvVersion}`);
|
|
145
|
-
exec(venvPy, ['-m', 'pip', 'install', '--disable-pip-version-check', '--index-url', PINS.torchIndex, PINS.torchSpec]);
|
|
146
|
-
exec(venvPy, ['-m', 'pip', 'install', '--disable-pip-version-check', PINS.cuaS1Spec]);
|
|
147
|
-
for (const spec of Object.values(PINS.files)) {
|
|
148
|
-
console.error(`${spec.name}: ${await ensureFile(fileUrl(spec.name), path.join(checkpointDir(opts.dir), spec.name), spec)}`);
|
|
149
|
-
}
|
|
150
|
-
fs.writeFileSync(p.manifest, `${JSON.stringify(buildManifest(opts.dir, venvPy), null, 2)}\n`);
|
|
151
|
-
const check = verify(p.manifest);
|
|
152
|
-
process.stdout.write(`${JSON.stringify({ dryRun: false, ...p, verification: check }, null, 2)}\n`);
|
|
153
|
-
return check.ok ? 0 : 1;
|
|
314
|
+
const installed = installVersion(opts.from, opts.version, opts.dir);
|
|
315
|
+
const runtime = setupRuntime(opts.dir, opts.python);
|
|
316
|
+
process.stdout.write(`${JSON.stringify({ dryRun: false, ...p, install: installed, runtime }, null, 2)}\n`);
|
|
317
|
+
return 0;
|
|
154
318
|
}
|
|
155
319
|
if (require.main === module) {
|
|
156
|
-
main(process.argv.slice(2)).then(code => { process.exitCode = code; },
|
|
157
|
-
if (
|
|
158
|
-
console.error(`System One install failed: ${
|
|
320
|
+
main(process.argv.slice(2)).then(code => { process.exitCode = code; }, error => {
|
|
321
|
+
if (error.message === 'usage') { console.error(USAGE); process.exitCode = 2; return; }
|
|
322
|
+
console.error(`System One install failed: ${error.message}`); process.exitCode = 1;
|
|
159
323
|
});
|
|
160
324
|
}
|
|
161
|
-
module.exports = {
|
|
325
|
+
module.exports = {
|
|
326
|
+
PINS, STAGES, defaultDir, versionDir, activePath, validVersion, parseArgs,
|
|
327
|
+
supportedPython, pythonCandidates, venvPython, exec, findPython, sourceKind,
|
|
328
|
+
readCheckpoint, installVersion, readActive, writeActive, activate, rollback, status, plan, setupRuntime,
|
|
329
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
|
|
6
|
+
const STAGES = ['validity', 'intent', 'tier'];
|
|
7
|
+
const SAFE_ID = /^[a-z0-9._-]{1,80}$/;
|
|
8
|
+
const HASH = /^[a-f0-9]{64}$/;
|
|
9
|
+
const VERSION = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
10
|
+
const SAFE_PATH_PART = /^[A-Za-z0-9._-]+$/;
|
|
11
|
+
const exact = (value, keys) => value && typeof value === 'object' && !Array.isArray(value)
|
|
12
|
+
&& Object.keys(value).length === keys.length && keys.every(key => Object.hasOwn(value, key));
|
|
13
|
+
|
|
14
|
+
function safeRelative(value) {
|
|
15
|
+
return typeof value === 'string' && value.length > 0 && !value.includes('\\')
|
|
16
|
+
&& !path.posix.isAbsolute(value) && !path.win32.isAbsolute(value)
|
|
17
|
+
&& value.split('/').every(part => SAFE_PATH_PART.test(part) && part !== '.' && part !== '..');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function validateVersionManifest(manifest, expectedVersion) {
|
|
21
|
+
const fail = detail => { throw new TypeError(`invalid-manifest: ${detail}`); };
|
|
22
|
+
if (!exact(manifest, ['schemaVersion', 'version', 'createdAt', 'stages', 'evaluation'])
|
|
23
|
+
|| manifest.schemaVersion !== 1 || typeof manifest.version !== 'string' || !VERSION.test(manifest.version)
|
|
24
|
+
|| (expectedVersion !== undefined && manifest.version !== expectedVersion)
|
|
25
|
+
|| typeof manifest.createdAt !== 'string' || !Number.isFinite(Date.parse(manifest.createdAt))
|
|
26
|
+
|| !exact(manifest.stages, STAGES)
|
|
27
|
+
|| !(manifest.evaluation === null || safeRelative(manifest.evaluation))) fail('invalid version manifest');
|
|
28
|
+
|
|
29
|
+
for (const name of STAGES) {
|
|
30
|
+
const stage = manifest.stages[name];
|
|
31
|
+
const fields = ['weights', 'config', 'sha256', 'options', 'thresholds'];
|
|
32
|
+
if (!(exact(stage, fields) || exact(stage, [...fields, 'referenceOnly']))
|
|
33
|
+
|| !safeRelative(stage.weights) || !safeRelative(stage.config) || !HASH.test(stage.sha256)
|
|
34
|
+
|| !Array.isArray(stage.options) || !stage.options.length
|
|
35
|
+
|| stage.options.some(id => typeof id !== 'string' || !SAFE_ID.test(id)
|
|
36
|
+
|| (id === 'unclassified' && name !== 'intent'))
|
|
37
|
+
|| new Set(stage.options).size !== stage.options.length || !exact(stage.thresholds, stage.options)
|
|
38
|
+
|| Object.values(stage.thresholds).some(value => typeof value !== 'number' || !Number.isFinite(value) || value < 0 || value > 1)) {
|
|
39
|
+
fail(`malformed ${name} stage`);
|
|
40
|
+
}
|
|
41
|
+
if (Object.hasOwn(stage, 'referenceOnly')
|
|
42
|
+
&& (!Array.isArray(stage.referenceOnly) || new Set(stage.referenceOnly).size !== stage.referenceOnly.length
|
|
43
|
+
|| stage.referenceOnly.some(id => !stage.options.includes(id) || stage.thresholds[id] !== 1))) {
|
|
44
|
+
fail(`malformed ${name} referenceOnly`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return manifest;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (require.main === module) {
|
|
51
|
+
try {
|
|
52
|
+
const file = process.argv[2];
|
|
53
|
+
const source = file ? fs.readFileSync(file, 'utf8') : fs.readFileSync(0, 'utf8');
|
|
54
|
+
validateVersionManifest(JSON.parse(source));
|
|
55
|
+
} catch (_) { process.exitCode = 1; }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
module.exports = { STAGES, validateVersionManifest };
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
const fs = require('node:fs');
|
|
3
|
+
const os = require('node:os');
|
|
3
4
|
const path = require('node:path');
|
|
5
|
+
const { createHash } = require('node:crypto');
|
|
4
6
|
const { spawnSync } = require('node:child_process');
|
|
5
|
-
const { validateRequest } = require('./contract');
|
|
7
|
+
const { createRequest, validateRequest, validateResponse } = require('./contract');
|
|
8
|
+
const { STAGES, validateVersionManifest } = require('./manifest');
|
|
6
9
|
// Upstream cua_s1 source revision documented in docs/system-one-routing.md.
|
|
7
10
|
const PINNED_CUA_S1_REVISION = 'b7f7e2d8714609853a29c7d049140bc46aec0954';
|
|
8
11
|
const ADAPTER = path.join(__dirname, 'cua_adapter.py');
|
|
@@ -14,6 +17,9 @@ const label = value => typeof value === 'string' && value.length > 0 && value.le
|
|
|
14
17
|
const adapterName = value => typeof value === 'string' && /^[a-z][a-z0-9_-]{0,63}\.py$/.test(value);
|
|
15
18
|
// Thresholds calibrated on validation for this checkpoint (docs/system-one-training.md).
|
|
16
19
|
const inRange = (v, lo, hi) => typeof v === 'number' && Number.isFinite(v) && v >= lo && v <= hi;
|
|
20
|
+
const LIVE_STAGES = STAGES;
|
|
21
|
+
const SAFE_ID = /^[a-z0-9._-]{1,80}$/;
|
|
22
|
+
const sha256 = value => createHash('sha256').update(value).digest('hex');
|
|
17
23
|
// secondaryThreshold is optional and belongs to intent checkpoints (docs/system-one-intent.md#scoring).
|
|
18
24
|
const validAcceptance = a => (exact(a, ['minConfidence', 'minMargin']) || (exact(a, ['minConfidence', 'minMargin', 'secondaryThreshold']) && inRange(a.secondaryThreshold, 0.05, 0.5)))
|
|
19
25
|
&& inRange(a.minConfidence, 0.5, 0.99) && inRange(a.minMargin, 0, 0.9);
|
|
@@ -112,4 +118,92 @@ function provenance(manifestPath) {
|
|
|
112
118
|
try { return { status: 'recorded', provenance: validateProvenance(result.value) }; }
|
|
113
119
|
catch (_) { return unavailable('provider-json'); }
|
|
114
120
|
}
|
|
115
|
-
|
|
121
|
+
|
|
122
|
+
function liveHome(env) {
|
|
123
|
+
return env.HARNESS_SYSTEM_ONE_HOME || path.join(os.homedir(), '.agents', 'harness-everything', 'system-one');
|
|
124
|
+
}
|
|
125
|
+
function readableFile(dir, name, extension) {
|
|
126
|
+
if (typeof name !== 'string' || !/^[A-Za-z0-9._-]+$/.test(name) || path.basename(name) !== name
|
|
127
|
+
|| name === '.' || name === '..' || path.extname(name) !== extension) return null;
|
|
128
|
+
const file = path.join(dir, name);
|
|
129
|
+
try {
|
|
130
|
+
const stat = fs.lstatSync(file);
|
|
131
|
+
return stat.isFile() && !stat.isSymbolicLink() ? file : null;
|
|
132
|
+
} catch (_) { return null; }
|
|
133
|
+
}
|
|
134
|
+
function readActive(env = process.env) {
|
|
135
|
+
try {
|
|
136
|
+
const home = liveHome(env);
|
|
137
|
+
if (!path.isAbsolute(home)) return null;
|
|
138
|
+
const pointerPath = path.join(home, 'active.json');
|
|
139
|
+
const pointerStat = fs.lstatSync(pointerPath);
|
|
140
|
+
if (!pointerStat.isFile() || pointerStat.isSymbolicLink() || pointerStat.size > 65536) return null;
|
|
141
|
+
const pointer = JSON.parse(fs.readFileSync(pointerPath, 'utf8'));
|
|
142
|
+
if (!exact(pointer, ['schemaVersion', 'version', 'dir', 'previous', 'activatedAt']) || pointer.schemaVersion !== 1
|
|
143
|
+
|| typeof pointer.version !== 'string' || !SAFE_ID.test(pointer.version)
|
|
144
|
+
|| typeof pointer.dir !== 'string' || !path.isAbsolute(pointer.dir)
|
|
145
|
+
|| !(pointer.previous === null || (typeof pointer.previous === 'string' && SAFE_ID.test(pointer.previous)))
|
|
146
|
+
|| typeof pointer.activatedAt !== 'string' || !Number.isFinite(Date.parse(pointer.activatedAt))) return null;
|
|
147
|
+
const dir = pointer.dir;
|
|
148
|
+
const dirStat = fs.lstatSync(dir);
|
|
149
|
+
if (!dirStat.isDirectory() || dirStat.isSymbolicLink()) return null;
|
|
150
|
+
const manifestPath = path.join(dir, 'manifest.json');
|
|
151
|
+
const manifestStat = fs.lstatSync(manifestPath);
|
|
152
|
+
if (!manifestStat.isFile() || manifestStat.isSymbolicLink() || manifestStat.size > 131072) return null;
|
|
153
|
+
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
154
|
+
validateVersionManifest(manifest, pointer.version);
|
|
155
|
+
const loadedStages = {};
|
|
156
|
+
for (const stageName of LIVE_STAGES) {
|
|
157
|
+
const stage = manifest.stages[stageName];
|
|
158
|
+
const weightsPath = readableFile(dir, stage.weights, '.safetensors');
|
|
159
|
+
const configPath = readableFile(dir, stage.config, '.json');
|
|
160
|
+
if (!weightsPath || !configPath || sha256(fs.readFileSync(weightsPath)) !== stage.sha256) return null;
|
|
161
|
+
loadedStages[stageName] = { ...stage, referenceOnly: stage.referenceOnly ?? [], weightsPath, configPath,
|
|
162
|
+
configSha256: sha256(fs.readFileSync(configPath)) };
|
|
163
|
+
}
|
|
164
|
+
const fingerprint = sha256(`${pointer.version}\0${dir}\0${LIVE_STAGES.map(stage => `${stage}\0${loadedStages[stage].sha256}\0${loadedStages[stage].configSha256}`).join('\0')}`);
|
|
165
|
+
const python = env.HARNESS_SYSTEM_ONE_PYTHON || env.PYTHON || path.join(home, 'venv', process.platform === 'win32' ? 'Scripts/python.exe' : 'bin/python');
|
|
166
|
+
return { home, pointerPath, pointer, version: pointer.version, dir, manifest, stages: loadedStages,
|
|
167
|
+
fingerprint, python, sha256: loadedStages.tier.sha256.slice(0, 16) };
|
|
168
|
+
} catch (_) { return null; }
|
|
169
|
+
}
|
|
170
|
+
async function scoreLive(prompt, env = process.env, catalogs, scoreStage = (stage, request, active) =>
|
|
171
|
+
require('./resident').scoreActiveStage(active, stage, request)) {
|
|
172
|
+
const active = readActive(env);
|
|
173
|
+
if (!active || typeof prompt !== 'string' || !catalogs) return null;
|
|
174
|
+
const stageScores = { validity: null, intent: null, tier: null };
|
|
175
|
+
for (const stage of LIVE_STAGES) {
|
|
176
|
+
const catalog = catalogs[stage];
|
|
177
|
+
const ids = active.stages[stage].options;
|
|
178
|
+
// A packaged intent checkpoint may omit the non-selectable unclassified option (cycle/package.js legacyOptions).
|
|
179
|
+
const manifestIds = ids.filter(id => id !== 'unclassified');
|
|
180
|
+
const expectedIds = Array.isArray(catalog) ? catalog.map(option => option?.id)
|
|
181
|
+
.filter(id => !(stage === 'validity' && id === 'actionable')
|
|
182
|
+
&& !((stage === 'intent' || stage === 'tier') && id === 'unclassified')) : [];
|
|
183
|
+
if (!Array.isArray(catalog) || manifestIds.length !== expectedIds.length
|
|
184
|
+
|| manifestIds.some((id, index) => id !== expectedIds[index])) return null;
|
|
185
|
+
const options = ids.map(id => catalog.find(option => option?.id === id));
|
|
186
|
+
let result;
|
|
187
|
+
let request;
|
|
188
|
+
try {
|
|
189
|
+
request = createRequest(stage, prompt, options, stage === 'validity' ? { minOptions: 1 } : undefined);
|
|
190
|
+
result = await scoreStage(stage, request, active);
|
|
191
|
+
} catch (_) { result = null; }
|
|
192
|
+
if (!result || result.status !== 'scored' || !validateResponse(request, result.response)) {
|
|
193
|
+
if (stage === 'validity') break;
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
stageScores[stage] = Object.fromEntries(result.response.scores
|
|
197
|
+
.filter(score => !(stage === 'validity' && score.id === 'actionable'))
|
|
198
|
+
.map(score => [score.id, score.probability]));
|
|
199
|
+
if (stage === 'validity' && (active.stages.validity.referenceOnly.includes('invalid')
|
|
200
|
+
|| stageScores.validity.invalid >= active.stages.validity.thresholds.invalid)) break;
|
|
201
|
+
}
|
|
202
|
+
const current = readActive(env);
|
|
203
|
+
if (!current || current.fingerprint !== active.fingerprint) return null;
|
|
204
|
+
return { version: active.version, sha256: active.sha256, stageScores,
|
|
205
|
+
thresholds: Object.fromEntries(LIVE_STAGES.map(stage => [stage, { ...active.stages[stage].thresholds }])),
|
|
206
|
+
referenceOnly: Object.fromEntries(LIVE_STAGES.map(stage => [stage, [...active.stages[stage].referenceOnly]])) };
|
|
207
|
+
}
|
|
208
|
+
module.exports = { score, scoreAsync, runProvider, validateManifest, readManifest, provenance, validateProvenance,
|
|
209
|
+
decisionPolicy, readActive, scoreLive, PINNED_CUA_S1_REVISION };
|