harness-everything 0.21.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +12 -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/ci/fixtures/system-one-resident-stub.py +28 -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 +185 -0
- package/ci/system-one-adapter-test.py +166 -0
- package/docs/platform-capabilities.md +3 -0
- package/docs/system-one-routing.md +72 -3
- 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 +5 -2
- package/harness-everything/scripts/system-one/resident.js +176 -0
- package/harness-everything/scripts/system-one/router.js +1 -1
- 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 +5 -2
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/resident.js +176 -0
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/router.js +1 -1
- package/sbom.cdx.json +7 -7
- package/scripts/build-openai-submission.js +2 -0
- package/scripts/evaluate-system-one.js +13 -4
- package/scripts/lib/packaging-noise.js +6 -0
- package/scripts/lib/skills.js +2 -0
- package/scripts/sync-openai-plugin.js +2 -1
package/plugins/harness-everything/skills/harness-everything/scripts/system-one/cua_adapter.py
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
"""Optional CPU CUA-S1 bridge. Stdout is protocol-only; never execute UI actions."""
|
|
2
2
|
import hashlib
|
|
3
|
+
import hmac
|
|
3
4
|
import json
|
|
5
|
+
import os
|
|
4
6
|
from pathlib import Path
|
|
5
7
|
import re
|
|
8
|
+
import secrets
|
|
9
|
+
import socket
|
|
10
|
+
import subprocess
|
|
6
11
|
import sys
|
|
12
|
+
import threading
|
|
13
|
+
import time
|
|
7
14
|
|
|
8
15
|
|
|
9
16
|
def verify_artifacts(manifest):
|
|
@@ -25,18 +32,23 @@ def check_limits(request, config):
|
|
|
25
32
|
raise ValueError('input-too-long')
|
|
26
33
|
|
|
27
34
|
|
|
28
|
-
def
|
|
29
|
-
|
|
35
|
+
def load_scorer(weights, manifest):
|
|
36
|
+
"""Load the verified checkpoint once; return (score(request) -> probabilities, config)."""
|
|
30
37
|
import torch
|
|
31
38
|
from cua_s1.model import ChoiceExample, load_checkpoint
|
|
32
39
|
|
|
33
40
|
torch.set_num_threads(1)
|
|
34
41
|
torch.use_deterministic_algorithms(True)
|
|
35
42
|
model, collator, config = load_checkpoint(weights, 'cpu')
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
|
|
44
|
+
def score(request):
|
|
45
|
+
example = ChoiceExample(context=request['context'], options=tuple(o['text'] for o in request['options']), label=0)
|
|
46
|
+
with torch.inference_mode():
|
|
47
|
+
return model(collator([example])).softmax(-1)[0].tolist()
|
|
48
|
+
return score, config
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def build_response(request, manifest, probabilities):
|
|
40
52
|
return {
|
|
41
53
|
'schemaVersion': 1, 'requestHash': request['requestHash'], 'catalogHash': request['catalogHash'],
|
|
42
54
|
'model': {'id': manifest['modelId'], 'revision': manifest['revision'], 'domain': manifest['domain']},
|
|
@@ -44,6 +56,251 @@ def infer(request, manifest):
|
|
|
44
56
|
}
|
|
45
57
|
|
|
46
58
|
|
|
59
|
+
def infer(request, manifest):
|
|
60
|
+
weights = verify_artifacts(manifest)
|
|
61
|
+
score, config = load_scorer(weights, manifest)
|
|
62
|
+
check_limits(request, config)
|
|
63
|
+
return build_response(request, manifest, score(request))
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
MAX_REQUEST_BYTES = 2 * 1024 * 1024
|
|
67
|
+
MAX_OPTIONS = 256
|
|
68
|
+
MAX_CLIENTS = 64
|
|
69
|
+
READ_DEADLINE_S = 1.0 # never longer than the Node client's 1000 ms call deadline
|
|
70
|
+
STARTUP_REASONS = ('artifact-hash', 'checkpoint-format')
|
|
71
|
+
ID_PATTERN = re.compile(r'[a-z0-9._-]{1,80}')
|
|
72
|
+
HASH_PATTERN = re.compile(r'[0-9a-f]{64}')
|
|
73
|
+
_USER_SID = []
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _artifact_stamp(weights):
|
|
77
|
+
return [(p.stat().st_size, p.stat().st_mtime_ns) for p in (weights, weights.with_suffix('.json'))]
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _restrict_to_current_user(path):
|
|
81
|
+
"""Windows: replace the whole DACL with one protected full-control ACE for the current user.
|
|
82
|
+
|
|
83
|
+
Editing ACEs is not enough: some hosts create files with explicit (non-inherited) SYSTEM,
|
|
84
|
+
Administrators or OWNER RIGHTS entries that survive `icacls /inheritance:r /grant:r`.
|
|
85
|
+
"""
|
|
86
|
+
if os.name != 'nt':
|
|
87
|
+
return
|
|
88
|
+
import ctypes
|
|
89
|
+
from ctypes import wintypes
|
|
90
|
+
if not _USER_SID:
|
|
91
|
+
tools = Path(os.environ.get('SystemRoot', 'C:/Windows')) / 'System32'
|
|
92
|
+
out = subprocess.run([str(tools / 'whoami.exe'), '/user', '/fo', 'csv', '/nh'],
|
|
93
|
+
capture_output=True, text=True, timeout=10, check=True).stdout
|
|
94
|
+
sid = out.strip().split(',')[-1].strip().strip('"')
|
|
95
|
+
if not re.fullmatch(r'S-1-[0-9-]+', sid):
|
|
96
|
+
raise OSError('user-sid')
|
|
97
|
+
_USER_SID.append(sid)
|
|
98
|
+
advapi32 = ctypes.WinDLL('advapi32', use_last_error=True)
|
|
99
|
+
kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
|
|
100
|
+
descriptor = ctypes.c_void_p()
|
|
101
|
+
if not advapi32.ConvertStringSecurityDescriptorToSecurityDescriptorW(
|
|
102
|
+
f'D:P(A;;FA;;;{_USER_SID[0]})', 1, ctypes.byref(descriptor), None):
|
|
103
|
+
raise OSError('dacl-build')
|
|
104
|
+
try:
|
|
105
|
+
present, defaulted, dacl = wintypes.BOOL(), wintypes.BOOL(), ctypes.c_void_p()
|
|
106
|
+
if not advapi32.GetSecurityDescriptorDacl(descriptor, ctypes.byref(present), ctypes.byref(dacl), ctypes.byref(defaulted)):
|
|
107
|
+
raise OSError('dacl-read')
|
|
108
|
+
SE_FILE_OBJECT, DACL_INFO, PROTECTED_DACL_INFO = 1, 0x4, 0x80000000
|
|
109
|
+
advapi32.SetNamedSecurityInfoW.argtypes = [wintypes.LPWSTR, ctypes.c_int, wintypes.DWORD,
|
|
110
|
+
ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
|
111
|
+
if advapi32.SetNamedSecurityInfoW(str(path), SE_FILE_OBJECT, DACL_INFO | PROTECTED_DACL_INFO, None, None, dacl, None) != 0:
|
|
112
|
+
raise OSError('dacl-set')
|
|
113
|
+
finally:
|
|
114
|
+
kernel32.LocalFree(descriptor)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def _write_private_json(target, value):
|
|
118
|
+
"""Atomic replace of an owner-only file (0600; explicit owner-only DACL on Windows) before the token is written."""
|
|
119
|
+
tmp = target.with_name(f'.{target.name}.{os.getpid()}.{secrets.token_hex(4)}.tmp')
|
|
120
|
+
os.close(os.open(tmp, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600))
|
|
121
|
+
_restrict_to_current_user(tmp)
|
|
122
|
+
with open(tmp, 'w', encoding='utf-8') as handle:
|
|
123
|
+
json.dump(value, handle)
|
|
124
|
+
os.replace(tmp, target)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _read_request_line(conn):
|
|
128
|
+
buffer = bytearray()
|
|
129
|
+
while b'\n' not in buffer and len(buffer) <= MAX_REQUEST_BYTES:
|
|
130
|
+
chunk = conn.recv(65536)
|
|
131
|
+
if not chunk:
|
|
132
|
+
break
|
|
133
|
+
buffer.extend(chunk)
|
|
134
|
+
if len(buffer.split(b'\n', 1)[0]) > MAX_REQUEST_BYTES:
|
|
135
|
+
# Drain to EOF (bounded by size and the read deadline) so the reply is not lost to a reset.
|
|
136
|
+
drained = 0
|
|
137
|
+
try:
|
|
138
|
+
while drained < 8 * MAX_REQUEST_BYTES and conn.recv(65536):
|
|
139
|
+
drained += 65536
|
|
140
|
+
except OSError:
|
|
141
|
+
pass
|
|
142
|
+
raise ValueError('request-limit')
|
|
143
|
+
return bytes(buffer).split(b'\n', 1)[0]
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def _valid_score_request(request):
|
|
147
|
+
"""Phase 0 request structure. Hashes are fingerprints, not authentication, so they are shape-checked only."""
|
|
148
|
+
if (not isinstance(request, dict)
|
|
149
|
+
or set(request) != {'schemaVersion', 'task', 'context', 'options', 'catalogHash', 'requestHash'}
|
|
150
|
+
or request['schemaVersion'] != 1 or not isinstance(request['task'], str) or not ID_PATTERN.fullmatch(request['task'])
|
|
151
|
+
or not isinstance(request['context'], str)
|
|
152
|
+
or not all(isinstance(request[k], str) and HASH_PATTERN.fullmatch(request[k]) for k in ('catalogHash', 'requestHash'))):
|
|
153
|
+
return False
|
|
154
|
+
options = request['options']
|
|
155
|
+
if not isinstance(options, list) or not 2 <= len(options) <= MAX_OPTIONS:
|
|
156
|
+
return False
|
|
157
|
+
if any(not isinstance(o, dict) or set(o) != {'id', 'text'} or not isinstance(o['id'], str)
|
|
158
|
+
or not ID_PATTERN.fullmatch(o['id']) or not isinstance(o['text'], str) for o in options):
|
|
159
|
+
return False
|
|
160
|
+
return len({o['id'] for o in options}) == len(options)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def _handle(conn, token, manifest, weights, stamp, score, config):
|
|
164
|
+
"""Return (reply, stop). Errors carry bounded reason codes only: no prompt, path, or traceback."""
|
|
165
|
+
invalid = {'ok': False, 'reason': 'invalid-request'}
|
|
166
|
+
try:
|
|
167
|
+
line = _read_request_line(conn)
|
|
168
|
+
except ValueError:
|
|
169
|
+
return {'ok': False, 'reason': 'request-limit'}, False
|
|
170
|
+
except OSError:
|
|
171
|
+
return invalid, False
|
|
172
|
+
try:
|
|
173
|
+
message = json.loads(line)
|
|
174
|
+
except ValueError:
|
|
175
|
+
return invalid, False
|
|
176
|
+
if not isinstance(message, dict):
|
|
177
|
+
return invalid, False
|
|
178
|
+
supplied = message.get('token')
|
|
179
|
+
if not isinstance(supplied, str) or not hmac.compare_digest(supplied.encode('utf-8'), token.encode('utf-8')):
|
|
180
|
+
return {'ok': False, 'reason': 'unauthorized'}, False
|
|
181
|
+
op = message.get('op')
|
|
182
|
+
if op == 'ping':
|
|
183
|
+
return {'ok': True, 'pid': os.getpid(), 'model': {'id': manifest['modelId'], 'revision': manifest['revision'], 'domain': manifest['domain']}}, False
|
|
184
|
+
if op == 'shutdown':
|
|
185
|
+
return {'ok': True}, True
|
|
186
|
+
if op != 'score' or not _valid_score_request(message.get('request')):
|
|
187
|
+
return invalid, False
|
|
188
|
+
try:
|
|
189
|
+
changed = _artifact_stamp(weights) != stamp
|
|
190
|
+
except OSError:
|
|
191
|
+
changed = True
|
|
192
|
+
if changed:
|
|
193
|
+
return {'ok': False, 'reason': 'artifact-changed'}, True
|
|
194
|
+
request = message['request']
|
|
195
|
+
try:
|
|
196
|
+
check_limits(request, config)
|
|
197
|
+
except ValueError:
|
|
198
|
+
return {'ok': False, 'reason': 'input-too-long'}, False
|
|
199
|
+
try:
|
|
200
|
+
return {'ok': True, 'response': build_response(request, manifest, score(request))}, False
|
|
201
|
+
except Exception:
|
|
202
|
+
return {'ok': False, 'reason': 'score-failed'}, False
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def serve(manifest, state_path, lock_path, scorer_factory=None, idle_timeout_s=None):
|
|
206
|
+
"""Resident loopback scorer: verify, load once, publish state, serve until idle/shutdown/artifact change."""
|
|
207
|
+
state_path, lock_path = Path(state_path), Path(lock_path)
|
|
208
|
+
try:
|
|
209
|
+
weights = verify_artifacts(manifest)
|
|
210
|
+
stamp = _artifact_stamp(weights)
|
|
211
|
+
score, config = (scorer_factory or load_scorer)(weights, manifest)
|
|
212
|
+
except Exception as exc:
|
|
213
|
+
reason = str(exc) if str(exc) in STARTUP_REASONS else 'load-failed'
|
|
214
|
+
try:
|
|
215
|
+
_write_private_json(lock_path, {'failed': reason, 'at': time.time()})
|
|
216
|
+
except OSError:
|
|
217
|
+
pass
|
|
218
|
+
return 1
|
|
219
|
+
idle = idle_timeout_s if idle_timeout_s is not None else manifest.get('idleTimeoutMs', 1800000) / 1000
|
|
220
|
+
token = secrets.token_hex(32)
|
|
221
|
+
pid = os.getpid()
|
|
222
|
+
stop = threading.Event()
|
|
223
|
+
score_lock = threading.Lock() # one model, one inference at a time; connections are handled concurrently
|
|
224
|
+
slots = threading.BoundedSemaphore(MAX_CLIENTS)
|
|
225
|
+
|
|
226
|
+
def guarded_score(request):
|
|
227
|
+
with score_lock:
|
|
228
|
+
return score(request)
|
|
229
|
+
|
|
230
|
+
def send(conn, reply):
|
|
231
|
+
try:
|
|
232
|
+
conn.sendall((json.dumps(reply, allow_nan=False) + '\n').encode('utf-8'))
|
|
233
|
+
except OSError:
|
|
234
|
+
pass
|
|
235
|
+
|
|
236
|
+
def worker(conn):
|
|
237
|
+
try:
|
|
238
|
+
with conn:
|
|
239
|
+
conn.settimeout(READ_DEADLINE_S)
|
|
240
|
+
reply, halt = _handle(conn, token, manifest, weights, stamp, guarded_score, config)
|
|
241
|
+
send(conn, reply)
|
|
242
|
+
if halt:
|
|
243
|
+
stop.set()
|
|
244
|
+
finally:
|
|
245
|
+
slots.release()
|
|
246
|
+
|
|
247
|
+
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
248
|
+
try:
|
|
249
|
+
server.bind(('127.0.0.1', 0))
|
|
250
|
+
server.listen(MAX_CLIENTS)
|
|
251
|
+
server.settimeout(0.25)
|
|
252
|
+
_write_private_json(state_path, {'schemaVersion': 1, 'pid': pid, 'port': server.getsockname()[1], 'token': token, 'startedAt': time.time()})
|
|
253
|
+
try:
|
|
254
|
+
lock_path.unlink()
|
|
255
|
+
except FileNotFoundError:
|
|
256
|
+
pass
|
|
257
|
+
last = time.monotonic()
|
|
258
|
+
# A server whose state file no longer names it is undiscoverable (replaced or corrupted): exit, never orphan.
|
|
259
|
+
while not stop.is_set() and time.monotonic() - last <= idle and _owns_state(state_path, pid, token):
|
|
260
|
+
try:
|
|
261
|
+
conn, _ = server.accept()
|
|
262
|
+
except socket.timeout:
|
|
263
|
+
continue
|
|
264
|
+
last = time.monotonic()
|
|
265
|
+
if not slots.acquire(blocking=False):
|
|
266
|
+
with conn:
|
|
267
|
+
conn.settimeout(0.2)
|
|
268
|
+
try:
|
|
269
|
+
_read_request_line(conn)
|
|
270
|
+
except (OSError, ValueError):
|
|
271
|
+
pass
|
|
272
|
+
send(conn, {'ok': False, 'reason': 'busy'})
|
|
273
|
+
continue
|
|
274
|
+
threading.Thread(target=worker, args=(conn,), daemon=True).start()
|
|
275
|
+
finally:
|
|
276
|
+
server.close()
|
|
277
|
+
if _owns_state(state_path, pid, token, missing=False):
|
|
278
|
+
try:
|
|
279
|
+
state_path.unlink()
|
|
280
|
+
except OSError:
|
|
281
|
+
pass
|
|
282
|
+
return 0
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
def _owns_state(state_path, pid, token, missing=False):
|
|
286
|
+
"""True while the state file still names this server. A transient Windows sharing violation counts as owned."""
|
|
287
|
+
try:
|
|
288
|
+
data = json.loads(state_path.read_text(encoding='utf-8'))
|
|
289
|
+
except FileNotFoundError:
|
|
290
|
+
return missing
|
|
291
|
+
except OSError:
|
|
292
|
+
return True
|
|
293
|
+
except ValueError:
|
|
294
|
+
return False
|
|
295
|
+
return isinstance(data, dict) and data.get('pid') == pid and data.get('token') == token
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
def serve_main(argv, scorer_factory=None):
|
|
299
|
+
if len(argv) != 3:
|
|
300
|
+
return 2
|
|
301
|
+
return serve(json.loads(argv[0]), argv[1], argv[2], scorer_factory=scorer_factory)
|
|
302
|
+
|
|
303
|
+
|
|
47
304
|
def source_revision(direct_url_text):
|
|
48
305
|
"""Return the PEP 610 VCS commit recorded at install time, or None when unprovable."""
|
|
49
306
|
try:
|
|
@@ -76,6 +333,8 @@ def main():
|
|
|
76
333
|
if sys.argv[1:] == ['--provenance']:
|
|
77
334
|
print(json.dumps(provenance(), allow_nan=False))
|
|
78
335
|
return 0
|
|
336
|
+
if sys.argv[1:2] == ['--serve']:
|
|
337
|
+
return serve_main(sys.argv[2:])
|
|
79
338
|
manifest = json.loads(sys.argv[1])
|
|
80
339
|
raw = sys.stdin.buffer.read(2 * 1024 * 1024 + 1)
|
|
81
340
|
if len(raw) > 2 * 1024 * 1024:
|
|
@@ -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,6 +50,7 @@ function score(request, manifestPath) {
|
|
|
48
50
|
validateRequest(request);
|
|
49
51
|
let manifest;
|
|
50
52
|
try { manifest = readManifest(manifestPath); } catch (_) { return unavailable('provider-config'); }
|
|
53
|
+
if (manifest.transport === 'resident') return require('./resident').score({ ...request }, manifest, manifestPath);
|
|
51
54
|
// Send the exact validated manifest to the child on stdin: no config reread race.
|
|
52
55
|
return runProvider({ ...request }, manifest.python, [ADAPTER, JSON.stringify(manifest)], manifest.timeoutMs || 2000);
|
|
53
56
|
}
|
|
@@ -73,4 +76,4 @@ function provenance(manifestPath) {
|
|
|
73
76
|
try { return { status: 'recorded', provenance: validateProvenance(result.value) }; }
|
|
74
77
|
catch (_) { return unavailable('provider-json'); }
|
|
75
78
|
}
|
|
76
|
-
module.exports = { score, runProvider, validateManifest, provenance, validateProvenance, PINNED_CUA_S1_REVISION };
|
|
79
|
+
module.exports = { score, runProvider, validateManifest, readManifest, provenance, validateProvenance, PINNED_CUA_S1_REVISION };
|
|
@@ -0,0 +1,176 @@
|
|
|
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 { spawn } = require('node:child_process');
|
|
9
|
+
const { Worker } = require('node:worker_threads');
|
|
10
|
+
const { validateRequest } = require('./contract');
|
|
11
|
+
|
|
12
|
+
const ADAPTER = path.join(__dirname, 'cua_adapter.py');
|
|
13
|
+
const LOCK_TTL_MS = 60000;
|
|
14
|
+
const CALL_TIMEOUT_MS = 1000;
|
|
15
|
+
const MAX_REPLY_BYTES = 1024 * 1024;
|
|
16
|
+
const unavailable = reason => ({ status: 'unavailable', reason });
|
|
17
|
+
const sleep = ms => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
18
|
+
const exact = (value, keys) => value && typeof value === 'object' && !Array.isArray(value)
|
|
19
|
+
&& Object.keys(value).length === keys.length && keys.every(k => Object.hasOwn(value, k));
|
|
20
|
+
const defaultCommand = manifest => [manifest.python, [ADAPTER, '--serve']];
|
|
21
|
+
|
|
22
|
+
function stateFiles(manifest, manifestPath) {
|
|
23
|
+
const digest = createHash('sha256').update(JSON.stringify(manifest)).digest('hex').slice(0, 16);
|
|
24
|
+
const base = path.join(path.dirname(manifestPath), `system-one-resident-${digest}`);
|
|
25
|
+
return { state: `${base}.json`, lock: `${base}.starting` };
|
|
26
|
+
}
|
|
27
|
+
function readState(file) {
|
|
28
|
+
try {
|
|
29
|
+
const s = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
30
|
+
if (exact(s, ['schemaVersion', 'pid', 'port', 'token', 'startedAt']) && s.schemaVersion === 1
|
|
31
|
+
&& Number.isInteger(s.pid) && s.pid > 0 && Number.isInteger(s.port) && s.port > 0 && s.port < 65536
|
|
32
|
+
&& typeof s.token === 'string' && /^[0-9a-f]{64}$/.test(s.token) && Number.isFinite(s.startedAt)) return s;
|
|
33
|
+
} catch (_) { /* absent or unreadable state means no usable server */ }
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
function lockInfo(file) {
|
|
37
|
+
try {
|
|
38
|
+
const ageMs = Date.now() - fs.statSync(file).mtimeMs;
|
|
39
|
+
let failed = null;
|
|
40
|
+
try { const body = JSON.parse(fs.readFileSync(file, 'utf8')); if (typeof body.failed === 'string') failed = body.failed; } catch (_) { /* partial write */ }
|
|
41
|
+
return { ageMs, failed };
|
|
42
|
+
} catch (_) { return null; }
|
|
43
|
+
}
|
|
44
|
+
function pidAlive(pid) {
|
|
45
|
+
try { process.kill(pid, 0); return true; } catch (err) { return err.code === 'EPERM'; }
|
|
46
|
+
}
|
|
47
|
+
function removeIfSame(file, state) {
|
|
48
|
+
const current = readState(file);
|
|
49
|
+
if (current && current.pid === state.pid && current.token === state.token) { try { fs.unlinkSync(file); } catch (_) { /* raced */ } }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// One socket round trip on a worker thread; the caller blocks with Atomics.wait (router API is synchronous).
|
|
53
|
+
const WORKER = `
|
|
54
|
+
const net = require('node:net');
|
|
55
|
+
const { workerData } = require('node:worker_threads');
|
|
56
|
+
const { port, payload, signal, out } = workerData;
|
|
57
|
+
const view = new Uint8Array(out); const chunks = []; let size = 0; let done = false;
|
|
58
|
+
const finish = (code, buf) => {
|
|
59
|
+
if (done) return; done = true;
|
|
60
|
+
if (buf) { view.set(buf); Atomics.store(signal, 1, buf.length); }
|
|
61
|
+
Atomics.store(signal, 0, code); Atomics.notify(signal, 0);
|
|
62
|
+
};
|
|
63
|
+
const socket = net.connect({ port, host: '127.0.0.1' }, () => socket.end(payload));
|
|
64
|
+
socket.on('data', c => { size += c.length; if (size > view.length) { finish(4); socket.destroy(); } else chunks.push(c); });
|
|
65
|
+
socket.on('end', () => finish(1, Buffer.concat(chunks)));
|
|
66
|
+
socket.on('error', e => finish(e.code === 'ECONNREFUSED' ? 2 : 3));
|
|
67
|
+
`;
|
|
68
|
+
function callSync(port, message, timeoutMs = CALL_TIMEOUT_MS) {
|
|
69
|
+
const signal = new Int32Array(new SharedArrayBuffer(8));
|
|
70
|
+
const out = new SharedArrayBuffer(MAX_REPLY_BYTES);
|
|
71
|
+
let worker;
|
|
72
|
+
try {
|
|
73
|
+
worker = new Worker(WORKER, { eval: true, workerData: { port, payload: `${JSON.stringify(message)}\n`, signal, out } });
|
|
74
|
+
worker.unref();
|
|
75
|
+
} catch (_) { return { error: 'io' }; }
|
|
76
|
+
Atomics.wait(signal, 0, 0, timeoutMs);
|
|
77
|
+
const code = Atomics.load(signal, 0);
|
|
78
|
+
worker.terminate();
|
|
79
|
+
if (code === 0) return { error: 'timeout' };
|
|
80
|
+
if (code !== 1) return { error: code === 2 ? 'refused' : code === 4 ? 'limit' : 'io' };
|
|
81
|
+
try { return { reply: JSON.parse(Buffer.from(out, 0, Atomics.load(signal, 1)).toString('utf8')) }; }
|
|
82
|
+
catch (_) { return { error: 'json' }; }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function start(manifest, files, deps) {
|
|
86
|
+
const lock = lockInfo(files.lock);
|
|
87
|
+
if (lock && lock.ageMs < LOCK_TTL_MS) return unavailable(lock.failed ? 'provider-unavailable' : 'provider-starting');
|
|
88
|
+
if (lock) { try { fs.unlinkSync(files.lock); } catch (_) { /* another caller replaced it */ } }
|
|
89
|
+
try { fs.writeFileSync(files.lock, JSON.stringify({ createdAt: Date.now() }), { flag: 'wx', mode: 0o600 }); }
|
|
90
|
+
catch (_) { return unavailable('provider-starting'); }
|
|
91
|
+
let child = null;
|
|
92
|
+
try {
|
|
93
|
+
const [exe, prefix] = (deps.command || defaultCommand)(manifest);
|
|
94
|
+
child = spawn(exe, [...prefix, JSON.stringify(manifest), files.state, files.lock],
|
|
95
|
+
{ detached: true, stdio: 'ignore', windowsHide: true, shell: false });
|
|
96
|
+
child.on('error', () => { /* recorded synchronously below: a failed spawn has no pid */ });
|
|
97
|
+
child.unref();
|
|
98
|
+
} catch (_) { child = null; }
|
|
99
|
+
// The async 'error' event cannot run while callers block in Atomics.wait, so record the failure now.
|
|
100
|
+
if (!child || !child.pid) {
|
|
101
|
+
try { fs.writeFileSync(files.lock, JSON.stringify({ createdAt: Date.now(), failed: 'spawn-failed' })); } catch (_) { /* best effort */ }
|
|
102
|
+
return unavailable('provider-unavailable');
|
|
103
|
+
}
|
|
104
|
+
return unavailable('provider-starting');
|
|
105
|
+
}
|
|
106
|
+
// Returns a live server state, or null after removing state that provably belongs to a dead server.
|
|
107
|
+
function liveState(files) {
|
|
108
|
+
const state = readState(files.state);
|
|
109
|
+
if (state && !pidAlive(state.pid)) { removeIfSame(files.state, state); return null; }
|
|
110
|
+
return state;
|
|
111
|
+
}
|
|
112
|
+
function score(request, manifest, manifestPath, deps = {}) {
|
|
113
|
+
validateRequest(request);
|
|
114
|
+
const files = stateFiles(manifest, manifestPath);
|
|
115
|
+
const state = liveState(files);
|
|
116
|
+
if (!state) return start(manifest, files, deps);
|
|
117
|
+
const result = callSync(state.port, { token: state.token, op: 'score', request });
|
|
118
|
+
if (result.reply) {
|
|
119
|
+
if (result.reply.ok === true && Object.hasOwn(result.reply, 'response')) return { status: 'scored', response: result.reply.response };
|
|
120
|
+
if (result.reply.ok === false) return unavailable(result.reply.reason === 'unauthorized' ? 'provider-unavailable' : 'provider-exit');
|
|
121
|
+
return unavailable('provider-json');
|
|
122
|
+
}
|
|
123
|
+
if (result.error === 'refused') { removeIfSame(files.state, state); return start(manifest, files, deps); }
|
|
124
|
+
return unavailable({ timeout: 'provider-timeout', limit: 'provider-output-limit', json: 'provider-json' }[result.error] || 'provider-unavailable');
|
|
125
|
+
}
|
|
126
|
+
function ping(state) {
|
|
127
|
+
const result = callSync(state.port, { token: state.token, op: 'ping' });
|
|
128
|
+
return result.reply && result.reply.ok === true ? result.reply : null;
|
|
129
|
+
}
|
|
130
|
+
function ensureReady(manifest, manifestPath, waitMs, deps = {}) {
|
|
131
|
+
const files = stateFiles(manifest, manifestPath);
|
|
132
|
+
const deadline = Date.now() + waitMs;
|
|
133
|
+
while (Date.now() < deadline) {
|
|
134
|
+
const state = liveState(files);
|
|
135
|
+
if (state && ping(state)) return true;
|
|
136
|
+
if (!state) {
|
|
137
|
+
const lock = lockInfo(files.lock);
|
|
138
|
+
if (lock && lock.failed && lock.ageMs < LOCK_TTL_MS) return false;
|
|
139
|
+
if (!lock || lock.ageMs >= LOCK_TTL_MS) start(manifest, files, deps);
|
|
140
|
+
}
|
|
141
|
+
sleep(100);
|
|
142
|
+
}
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
function status(manifest, manifestPath) {
|
|
146
|
+
const state = liveState(stateFiles(manifest, manifestPath));
|
|
147
|
+
const reply = state && ping(state);
|
|
148
|
+
return reply ? { running: true, pid: state.pid, port: state.port, startedAt: state.startedAt, model: reply.model } : { running: false };
|
|
149
|
+
}
|
|
150
|
+
function stop(manifest, manifestPath) {
|
|
151
|
+
const files = stateFiles(manifest, manifestPath);
|
|
152
|
+
const state = liveState(files);
|
|
153
|
+
if (!state) return false;
|
|
154
|
+
const result = callSync(state.port, { token: state.token, op: 'shutdown' });
|
|
155
|
+
if (!(result.reply && result.reply.ok === true)) {
|
|
156
|
+
try { process.kill(state.pid); } catch (_) { /* already exited */ }
|
|
157
|
+
removeIfSame(files.state, state);
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (require.main === module) {
|
|
163
|
+
const [op, manifestPath, extra] = process.argv.slice(2);
|
|
164
|
+
let manifest = null;
|
|
165
|
+
try {
|
|
166
|
+
if (!['start', 'status', 'stop'].includes(op) || extra) throw new Error('usage');
|
|
167
|
+
manifest = require('./provider').readManifest(manifestPath);
|
|
168
|
+
} catch (_) {
|
|
169
|
+
console.error('Usage: resident.js start|status|stop <absolute manifest path>');
|
|
170
|
+
process.exit(2);
|
|
171
|
+
}
|
|
172
|
+
if (op === 'start') process.exitCode = ensureReady(manifest, manifestPath, 60000) ? 0 : 1;
|
|
173
|
+
if (op === 'stop') stop(manifest, manifestPath);
|
|
174
|
+
process.stdout.write(`${JSON.stringify(status(manifest, manifestPath))}\n`);
|
|
175
|
+
}
|
|
176
|
+
module.exports = { stateFiles, readState, callSync, score, 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);
|
package/sbom.cdx.json
CHANGED
|
@@ -2,23 +2,23 @@
|
|
|
2
2
|
"$schema": "https://cyclonedx.org/schema/bom-1.7.schema.json",
|
|
3
3
|
"bomFormat": "CycloneDX",
|
|
4
4
|
"specVersion": "1.7",
|
|
5
|
-
"serialNumber": "urn:uuid:
|
|
5
|
+
"serialNumber": "urn:uuid:0f18cc7a-103c-5369-a33b-bdbe1bf12efb",
|
|
6
6
|
"version": 1,
|
|
7
7
|
"metadata": {
|
|
8
|
-
"timestamp": "2026-09-
|
|
8
|
+
"timestamp": "2026-09-23T05:03:30.779Z",
|
|
9
9
|
"tools": [
|
|
10
10
|
{
|
|
11
11
|
"vendor": "Harness Everything",
|
|
12
12
|
"name": "generate-sbom.js",
|
|
13
|
-
"version": "0.
|
|
13
|
+
"version": "0.22.0"
|
|
14
14
|
}
|
|
15
15
|
],
|
|
16
16
|
"component": {
|
|
17
17
|
"type": "application",
|
|
18
|
-
"bom-ref": "pkg:npm/harness-everything@0.
|
|
18
|
+
"bom-ref": "pkg:npm/harness-everything@0.22.0",
|
|
19
19
|
"name": "harness-everything",
|
|
20
|
-
"version": "0.
|
|
21
|
-
"purl": "pkg:npm/harness-everything@0.
|
|
20
|
+
"version": "0.22.0",
|
|
21
|
+
"purl": "pkg:npm/harness-everything@0.22.0"
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"components": [
|
|
@@ -1999,7 +1999,7 @@
|
|
|
1999
1999
|
]
|
|
2000
2000
|
},
|
|
2001
2001
|
{
|
|
2002
|
-
"ref": "pkg:npm/harness-everything@0.
|
|
2002
|
+
"ref": "pkg:npm/harness-everything@0.22.0",
|
|
2003
2003
|
"dependsOn": [
|
|
2004
2004
|
"pkg:npm/%40commitlint/cli@19.8.1",
|
|
2005
2005
|
"pkg:npm/%40commitlint/config-conventional@19.8.1",
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
const crypto = require('crypto');
|
|
5
5
|
const fs = require('fs');
|
|
6
6
|
const path = require('path');
|
|
7
|
+
const { isPackagingNoise } = require('./lib/packaging-noise');
|
|
7
8
|
|
|
8
9
|
const ROOT = path.resolve(__dirname, '..');
|
|
9
10
|
const SKILLS_ROOT = path.join(ROOT, 'plugins', 'harness-everything', 'skills');
|
|
@@ -24,6 +25,7 @@ function parseArgs(argv) {
|
|
|
24
25
|
|
|
25
26
|
function filesUnder(root, base = root, out = []) {
|
|
26
27
|
for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
|
|
28
|
+
if (isPackagingNoise(entry.name)) continue;
|
|
27
29
|
const full = path.join(root, entry.name);
|
|
28
30
|
if (entry.isDirectory()) filesUnder(full, base, out);
|
|
29
31
|
else if (entry.isFile()) out.push(path.relative(base, full).replace(/\\/g, '/'));
|