harness-everything 0.27.0 → 0.29.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 +33 -0
- package/behavioral-evals/README.md +39 -0
- package/behavioral-evals/case-validator.js +34 -0
- package/behavioral-evals/cases/baseline-worktree-submodule-reachability.yaml +30 -0
- package/behavioral-evals/fixtures/setup/fail.js +3 -0
- package/behavioral-evals/fixtures/setup/noop.js +4 -0
- package/behavioral-evals/fixtures/setup/verify-worktree-submodule.js +46 -0
- package/behavioral-evals/fixtures/setup/worktree-submodule.js +86 -0
- package/behavioral-evals/paired-benchmark.js +39 -5
- package/behavioral-evals/run-with-plugin.js +53 -39
- package/behavioral-evals/run.js +88 -9
- package/benchmarks/fixtures/system-one-holdout-reviews.json +18 -18
- package/benchmarks/fixtures/system-one-holdout.json +9 -9
- package/benchmarks/results/system-one/harness-routing-v1-cpu-2026-09-24/README.md +75 -0
- package/benchmarks/results/system-one/harness-routing-v1-cpu-2026-09-24/report.json +10832 -0
- package/benchmarks/results/system-one/harness-routing-v1-ngram-2026-09-24/README.md +72 -0
- package/benchmarks/results/system-one/harness-routing-v1-ngram-2026-09-24/report.json +10817 -0
- package/benchmarks/results/system-one/harness-routing-v3-ngram-2026-09-24/README.md +63 -0
- package/benchmarks/results/system-one/harness-routing-v3-ngram-2026-09-24/report.json +10817 -0
- package/benchmarks/results/system-one/labeler-holdout-check-2026-09-24/report.json +1104 -0
- package/benchmarks/results/system-one/labeler-holdout-check-codex-2026-09-24/report.json +1104 -0
- package/benchmarks/results/system-one/labeler-holdout-check-codex-tier3-2026-09-24/report.json +1104 -0
- package/ci/mechanism-2j-behavioral-runner.test.js +121 -1
- package/ci/mechanism-2j-fixture-entrypoints.test.js +153 -0
- package/ci/mechanism-system-one-evaluation.test.js +17 -0
- package/ci/mechanism-system-one-label.test.js +27 -0
- package/ci/mechanism-system-one-ngram.test.js +161 -0
- package/ci/mechanism-system-one-train.test.js +12 -0
- package/ci/system-one-ngram-parity.py +19 -0
- package/ci/system-one-train-test.py +6 -0
- package/ci/test-behavioral-case-validation.js +26 -0
- package/docs/system-one-corpus.md +31 -3
- package/docs/system-one-routing.md +84 -2
- package/docs/system-one-training.md +14 -2
- package/harness-everything/SKILL.md +1 -1
- package/harness-everything/scripts/system-one/evaluate.js +3 -2
- package/harness-everything/scripts/system-one/ngram.js +84 -0
- package/harness-everything/scripts/system-one/provider.js +15 -5
- 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/skills/harness-everything/SKILL.md +1 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/evaluate.js +3 -2
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/ngram.js +84 -0
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/provider.js +15 -5
- package/sbom.cdx.json +7 -7
- package/scripts/evaluate-system-one.js +16 -9
- package/scripts/system-one-calibrate.js +1 -1
- package/scripts/system-one-label.js +32 -3
- package/scripts/system-one-train-ngram.py +129 -0
- package/scripts/system-one-train.py +14 -1
|
@@ -103,6 +103,52 @@ responses are checked by Phase 0. Transport fixtures prove IPC and failure
|
|
|
103
103
|
handling only. Real checkpoint inference and measured CPU latency remain a
|
|
104
104
|
separate gate, with explicit unavailable evidence if dependencies are absent.
|
|
105
105
|
|
|
106
|
+
## N-gram provider (Phase 4)
|
|
107
|
+
|
|
108
|
+
`transport: "ngram"` scores in the Node process itself. It needs no Python, no
|
|
109
|
+
torch, no resident server and no subprocess. It exists because a byte-level
|
|
110
|
+
transformer trained from scratch learned little beyond class priors on the
|
|
111
|
+
owner's data. A linear model over character n-grams learned more from the same
|
|
112
|
+
labels at about 1 MB. See
|
|
113
|
+
[harness-routing-v1-cpu-2026-09-24](../benchmarks/results/system-one/harness-routing-v1-cpu-2026-09-24/README.md).
|
|
114
|
+
|
|
115
|
+
**Artifact.** The manifest `checkpoint` is an absolute path to `<name>.bin`, and
|
|
116
|
+
`weightsSha256` is that file's hash. A `<name>.json` sidecar beside it has the
|
|
117
|
+
hash `configSha256`. `python` is not required for this transport. The sidecar
|
|
118
|
+
holds exactly:
|
|
119
|
+
|
|
120
|
+
| Field | Value |
|
|
121
|
+
| --- | --- |
|
|
122
|
+
| `format` | `harness-ngram` |
|
|
123
|
+
| `formatVersion` | `1` |
|
|
124
|
+
| `dim` | Feature buckets, a power of two between 2^10 and 2^20 |
|
|
125
|
+
| `nmax` | Longest n-gram, 1–4 |
|
|
126
|
+
| `hash` | `fnv1a32` |
|
|
127
|
+
| `catalog` | The option IDs in catalog order |
|
|
128
|
+
| `bias` | One number per option |
|
|
129
|
+
| `metadata` | An object with training provenance |
|
|
130
|
+
|
|
131
|
+
`.bin` holds `dim × catalog.length` little-endian float32 weights in row-major
|
|
132
|
+
order (feature, then option), so its size must equal `dim × options × 4` bytes.
|
|
133
|
+
Both files are hash-checked before use. Any mismatch in hash, shape or field
|
|
134
|
+
returns `provider-config` and never scores.
|
|
135
|
+
|
|
136
|
+
**Features.** Featurization is identical in the trainer and the provider, and a
|
|
137
|
+
cross-language test proves it.
|
|
138
|
+
|
|
139
|
+
1. Lowercase the text and join its whitespace-separated parts with one space.
|
|
140
|
+
2. For each n from 1 to `nmax`, take every n-gram of Unicode code points that is
|
|
141
|
+
not only spaces. Add it to bucket `fnv1a32("<n>:<gram>" as UTF-8) mod dim`.
|
|
142
|
+
3. Add one length feature, bucket `fnv1a32("len:<k>") mod dim`, where
|
|
143
|
+
`k = min(8, floor(log2(utf8Bytes + 1)))`.
|
|
144
|
+
4. Weight each bucket as `log(1 + count)` and L2-normalize the vector.
|
|
145
|
+
|
|
146
|
+
**Scoring.** The probabilities are `softmax(x·W + bias)` in catalog order. The
|
|
147
|
+
request's option IDs must equal `catalog`, or the result is `provider-config`.
|
|
148
|
+
The response has the Phase 0 shape, and the manifest `acceptance` thresholds
|
|
149
|
+
apply as for any transport. The Phase 0 context limit (64 KiB) is the only
|
|
150
|
+
length limit.
|
|
151
|
+
|
|
106
152
|
## Resident provider (Phase 4 prerequisite)
|
|
107
153
|
|
|
108
154
|
The one-shot bridge pays Python start, `import torch` and checkpoint load on every
|
|
@@ -262,6 +308,15 @@ The latter evidence is not supplied by this offline runner, so it always reports
|
|
|
262
308
|
those gates pending. With the one-shot adapter, all latency is cold and the warm
|
|
263
309
|
gate also remains pending. Exporting a report never changes router defaults.
|
|
264
310
|
|
|
311
|
+
For the `ngram` transport, samples are recorded with `coldStart: false`, because
|
|
312
|
+
scoring happens in process. The evaluator loads and verifies the artifact once
|
|
313
|
+
before any timed sample, so that load is not part of the warm latency. The
|
|
314
|
+
source check does not run the Python `cua_s1` probe, which this transport does
|
|
315
|
+
not use. It records `{status: "recorded", transport: "ngram", artifactVerified}`,
|
|
316
|
+
where `artifactVerified` is true only when both artifact files load and match
|
|
317
|
+
their SHA-256 values. For this transport, the `sourceProvenance` gate passes
|
|
318
|
+
when `artifactVerified` is true.
|
|
319
|
+
|
|
265
320
|
## Model suitability
|
|
266
321
|
|
|
267
322
|
The [CUA-S1-FORMS model card](https://huggingface.co/cua-ai/cua-s1-forms)
|
|
@@ -286,11 +341,38 @@ unversioned download during a prompt hook.
|
|
|
286
341
|
Phase 4 training data, labeling, calibration and release are defined in
|
|
287
342
|
[system-one-training.md](system-one-training.md).
|
|
288
343
|
|
|
344
|
+
## Staged classification
|
|
345
|
+
|
|
346
|
+
System One answers three narrow questions in sequence instead of one broad
|
|
347
|
+
question. Each stage is its own fixed catalog, scorer request and holdout, so a
|
|
348
|
+
small model only has to separate a few options at a time.
|
|
349
|
+
|
|
350
|
+
1. **Tier**: `tier1`, `tier2`, `tier3` or `unclassified`, following
|
|
351
|
+
[system-one-corpus.md](system-one-corpus.md).
|
|
352
|
+
2. **Intent**: the kind of work the prompt asks for, drawn from a small fixed
|
|
353
|
+
catalog (for example: ask or explain, discuss or decide, Git/GitHub
|
|
354
|
+
operation, fix a bug, build a feature, refactor, review or audit, test or
|
|
355
|
+
verify, write docs, plan or spec, investigate). The intent catalog is the
|
|
356
|
+
owner's and is recorded in the corpus document before any intent labels.
|
|
357
|
+
3. **Skills**: which canonical skills fit the prompt, scored against skill
|
|
358
|
+
descriptions. Only skills above the stage's calibrated threshold are
|
|
359
|
+
suggested, and they are suggestions, never required reads.
|
|
360
|
+
|
|
361
|
+
Each stage has its own gates, and a stage ships only when it passes them. Tier
|
|
362
|
+
comes first because the reviewed holdout exists for it. Later stages reuse the
|
|
363
|
+
same collector, labeler, trainer and evaluator with a different catalog.
|
|
364
|
+
Suggestions are advisory: explicit workflow requests, action gates, memory
|
|
365
|
+
ownership, the Rule of 3 and deterministic policy always take precedence.
|
|
366
|
+
|
|
289
367
|
## Rollout gates
|
|
290
368
|
|
|
291
369
|
Phase 4 requires a separately reviewed, family-disjoint holdout of at least 200
|
|
292
|
-
cases, at least 50 each in English and Traditional Chinese.
|
|
293
|
-
|
|
370
|
+
cases, at least 50 each in English and Traditional Chinese. System One output is
|
|
371
|
+
advisory: it informs the agent and suggests skills. It never grants or removes
|
|
372
|
+
policy. The owner therefore set the target at accepted precision ≥85% (the
|
|
373
|
+
80–90% band), coverage ≥80%, and macro-F1 at least the lexical baseline. A
|
|
374
|
+
probabilistic scorer small enough to ship inside a skills plugin (a few MB, not
|
|
375
|
+
hundreds) is not expected to reach 98%.
|
|
294
376
|
Policy invariants must remain intact in every case; repeat decisions twice with
|
|
295
377
|
100% agreement. Record checkpoint/source hashes, CPU, OS, runtime, thread count,
|
|
296
378
|
cold latency and warm p95 (target ≤100ms). Synthetic fixtures and mock providers
|
|
@@ -104,7 +104,19 @@ prompts written by an agent, not by the owner. VS Code terminal notifications
|
|
|
104
104
|
|
|
105
105
|
## Training and calibration
|
|
106
106
|
|
|
107
|
-
- **
|
|
107
|
+
- **Tier engine**: `scripts/system-one-train-ngram.py` trains the `ngram` transport, a
|
|
108
|
+
multinomial logistic regression over hashed character n-gram features. Featurization
|
|
109
|
+
follows [system-one-routing.md](system-one-routing.md#n-gram-provider-phase-4).
|
|
110
|
+
- The trainer uses torch for the optimizer only. The features are stdlib Python and match
|
|
111
|
+
the Node provider exactly.
|
|
112
|
+
- The configuration (`nmax`, class weighting, weight decay) is chosen on validation
|
|
113
|
+
macro-F1. The first exploration picked `nmax` 3, square-root inverse-frequency class
|
|
114
|
+
weights and a weight decay of 1e-4.
|
|
115
|
+
- The output is the `.bin` weights, the `.json` sidecar and validation scores for
|
|
116
|
+
calibration.
|
|
117
|
+
- The `tinyx` path below is kept for comparison. Its first checkpoint learned little beyond
|
|
118
|
+
class priors.
|
|
119
|
+
- **Model** (`tinyx`): a new `cua_s1` `tinyx` scorer built with `make_system`.
|
|
108
120
|
- Config: `width` 128, `rank` 128, `layers` 2, `heads` 4, `context_tokens` 1024 and
|
|
109
121
|
`option_tokens` 96.
|
|
110
122
|
- Weights are initialized fresh, not from the forms checkpoint, whose domain and
|
|
@@ -116,7 +128,7 @@ prompts written by an agent, not by the owner. VS Code terminal notifications
|
|
|
116
128
|
- The epoch with the lowest validation negative log-likelihood is kept.
|
|
117
129
|
- The checkpoint metadata records the dataset hashes, the config and the validation metrics.
|
|
118
130
|
- **Calibration**: `minConfidence` and `minMargin` are chosen on validation to maximize
|
|
119
|
-
coverage, subject to an accepted precision of at least
|
|
131
|
+
coverage, subject to an accepted precision of at least 85% (the owner's advisory target). The router currently uses the
|
|
120
132
|
Phase 0 defaults (0.9 and 0.2). Carrying calibrated thresholds into the manifest is a
|
|
121
133
|
separate contract change.
|
|
122
134
|
|
|
@@ -84,12 +84,13 @@ function evaluate(corpus, records, sourceEvidence = null) {
|
|
|
84
84
|
const gates = {
|
|
85
85
|
reviewedHoldout: cases.length >= 200 && cases.every(c => c.reviewed)
|
|
86
86
|
&& ['en', 'zh-TW'].every(lang => cases.filter(c => c.language === lang).length >= 50),
|
|
87
|
-
acceptedPrecision: model.acceptedPrecision !== null && model.acceptedPrecision >= 0.
|
|
87
|
+
acceptedPrecision: model.acceptedPrecision !== null && model.acceptedPrecision >= 0.85,
|
|
88
88
|
coverage: model.coverage >= 0.8,
|
|
89
89
|
macroF1: model.macroF1 >= baseline.macroF1,
|
|
90
90
|
repeatability: agreement === 1,
|
|
91
91
|
warmLatency: warm.length >= cases.length && latency.warmP95Ms <= 100,
|
|
92
|
-
sourceProvenance: sourceEvidence?.status === 'recorded' && sourceEvidence.provenance?.cuaS1?.sourceRevisionStatus === 'pinned'
|
|
92
|
+
sourceProvenance: sourceEvidence?.status === 'recorded' && (sourceEvidence.provenance?.cuaS1?.sourceRevisionStatus === 'pinned'
|
|
93
|
+
|| (sourceEvidence.transport === 'ngram' && sourceEvidence.artifactVerified === true)),
|
|
93
94
|
policyEvidence: false,
|
|
94
95
|
liveHostEvidence: false,
|
|
95
96
|
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// In-process System One scorer: hashed character n-grams + a linear layer (docs/system-one-routing.md, "N-gram provider").
|
|
3
|
+
// Featurization must match scripts/system-one-train-ngram.py exactly; ci/mechanism-system-one-ngram.test.js proves it.
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const { createHash } = require('node:crypto');
|
|
6
|
+
|
|
7
|
+
const SIDE_KEYS = ['format', 'formatVersion', 'dim', 'nmax', 'hash', 'catalog', 'bias', 'metadata'];
|
|
8
|
+
const cache = new Map();
|
|
9
|
+
const configError = () => Object.assign(new Error('provider-config'), { code: 'provider-config' });
|
|
10
|
+
const sha = buf => createHash('sha256').update(buf).digest('hex');
|
|
11
|
+
|
|
12
|
+
function fnv1a32(text) {
|
|
13
|
+
let h = 0x811c9dc5;
|
|
14
|
+
for (const byte of Buffer.from(text, 'utf8')) { h ^= byte; h = Math.imul(h, 0x01000193) >>> 0; }
|
|
15
|
+
return h >>> 0;
|
|
16
|
+
}
|
|
17
|
+
// Map of bucket -> weight: log(1 + count) per code-point n-gram, one length bucket, L2-normalized.
|
|
18
|
+
function featurize(text, nmax, dim) {
|
|
19
|
+
const t = text.toLowerCase().split(/\s+/).filter(Boolean).join(' ');
|
|
20
|
+
const cps = Array.from(t);
|
|
21
|
+
const counts = new Map();
|
|
22
|
+
for (let n = 1; n <= nmax; n++) {
|
|
23
|
+
for (let i = 0; i + n <= cps.length; i++) {
|
|
24
|
+
const gram = cps.slice(i, i + n).join('');
|
|
25
|
+
if (!gram.trim()) continue;
|
|
26
|
+
const b = fnv1a32(`${n}:${gram}`) % dim;
|
|
27
|
+
counts.set(b, (counts.get(b) || 0) + 1);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const k = Math.min(8, Math.floor(Math.log2(Buffer.byteLength(t, 'utf8') + 1)));
|
|
31
|
+
counts.set(fnv1a32(`len:${k}`) % dim, 1);
|
|
32
|
+
const feats = new Map();
|
|
33
|
+
let norm = 0;
|
|
34
|
+
for (const [b, c] of counts) { const v = Math.log1p(c); feats.set(b, v); norm += v * v; }
|
|
35
|
+
norm = Math.sqrt(norm);
|
|
36
|
+
for (const [b, v] of feats) feats.set(b, v / norm);
|
|
37
|
+
return feats;
|
|
38
|
+
}
|
|
39
|
+
function validSidecar(s) {
|
|
40
|
+
const isPow2 = n => Number.isInteger(n) && n >= 1024 && n <= 1 << 20 && (n & (n - 1)) === 0;
|
|
41
|
+
return s && typeof s === 'object' && !Array.isArray(s) && Object.keys(s).length === SIDE_KEYS.length && SIDE_KEYS.every(k => Object.hasOwn(s, k))
|
|
42
|
+
&& s.format === 'harness-ngram' && s.formatVersion === 1 && isPow2(s.dim) && Number.isInteger(s.nmax) && s.nmax >= 1 && s.nmax <= 4
|
|
43
|
+
&& s.hash === 'fnv1a32' && Array.isArray(s.catalog) && s.catalog.length >= 2 && new Set(s.catalog).size === s.catalog.length
|
|
44
|
+
&& s.catalog.every(id => typeof id === 'string' && /^[a-z0-9._-]{1,80}$/.test(id))
|
|
45
|
+
&& Array.isArray(s.bias) && s.bias.length === s.catalog.length && s.bias.every(Number.isFinite)
|
|
46
|
+
&& s.metadata && typeof s.metadata === 'object' && !Array.isArray(s.metadata);
|
|
47
|
+
}
|
|
48
|
+
// Loads and verifies the artifact once per process; any mismatch throws provider-config.
|
|
49
|
+
function loadModel(manifest) {
|
|
50
|
+
const key = `${manifest.checkpoint}|${manifest.weightsSha256}|${manifest.configSha256}`;
|
|
51
|
+
if (cache.has(key)) return cache.get(key);
|
|
52
|
+
const sidecarPath = manifest.checkpoint.replace(/\.bin$/, '.json');
|
|
53
|
+
let side; let bin;
|
|
54
|
+
try {
|
|
55
|
+
const raw = fs.readFileSync(sidecarPath);
|
|
56
|
+
if (raw.length > 65536 || sha(raw) !== manifest.configSha256) throw configError();
|
|
57
|
+
side = JSON.parse(raw.toString('utf8'));
|
|
58
|
+
bin = fs.readFileSync(manifest.checkpoint);
|
|
59
|
+
} catch (_) { throw configError(); }
|
|
60
|
+
if (sha(bin) !== manifest.weightsSha256 || !validSidecar(side) || bin.length !== side.dim * side.catalog.length * 4) throw configError();
|
|
61
|
+
const W = new Float32Array(side.dim * side.catalog.length);
|
|
62
|
+
for (let i = 0; i < W.length; i++) W[i] = bin.readFloatLE(i * 4);
|
|
63
|
+
const model = { dim: side.dim, nmax: side.nmax, catalog: side.catalog, bias: side.bias, W };
|
|
64
|
+
cache.set(key, model);
|
|
65
|
+
return model;
|
|
66
|
+
}
|
|
67
|
+
function score(request, manifest) {
|
|
68
|
+
const model = loadModel(manifest);
|
|
69
|
+
const C = model.catalog.length;
|
|
70
|
+
if (request.options.length !== C || request.options.some((o, i) => o.id !== model.catalog[i])) throw configError();
|
|
71
|
+
const logits = model.bias.slice();
|
|
72
|
+
for (const [b, v] of featurize(request.context, model.nmax, model.dim)) {
|
|
73
|
+
for (let c = 0; c < C; c++) logits[c] += v * model.W[b * C + c];
|
|
74
|
+
}
|
|
75
|
+
const max = Math.max(...logits);
|
|
76
|
+
const exps = logits.map(z => Math.exp(z - max));
|
|
77
|
+
const sum = exps.reduce((s, x) => s + x, 0);
|
|
78
|
+
return {
|
|
79
|
+
schemaVersion: 1, requestHash: request.requestHash, catalogHash: request.catalogHash,
|
|
80
|
+
model: { id: manifest.modelId, revision: manifest.revision, domain: manifest.domain },
|
|
81
|
+
scores: request.options.map((o, i) => ({ id: o.id, probability: exps[i] / sum })),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
module.exports = { fnv1a32, featurize, loadModel, score };
|
|
@@ -17,15 +17,18 @@ const validAcceptance = a => exact(a, ['minConfidence', 'minMargin']) && inRange
|
|
|
17
17
|
const withAcceptance = (result, manifest) => (result && result.status === 'scored' && manifest.acceptance
|
|
18
18
|
? { ...result, acceptance: { ...manifest.acceptance } } : result);
|
|
19
19
|
function validateManifest(m) {
|
|
20
|
-
|
|
20
|
+
// The in-process ngram transport needs no Python and loads a .bin; the others run the CUA-S1 adapter.
|
|
21
|
+
const ngram = !!m && m.transport === 'ngram';
|
|
22
|
+
const required = ['schemaVersion', ...(ngram ? [] : ['python']), 'checkpoint', 'weightsSha256', 'configSha256', 'modelId', 'revision', 'domain'];
|
|
23
|
+
const strings = ['modelId', 'revision', 'domain', ...(ngram && !Object.hasOwn(m, 'python') ? [] : ['python'])];
|
|
21
24
|
if (!m || typeof m !== 'object' || Array.isArray(m) || required.some(k => !Object.hasOwn(m, k))
|
|
22
|
-
|| Object.keys(m).some(k => ![...required, 'timeoutMs', 'transport', 'idleTimeoutMs', 'acceptance'].includes(k)) || m.schemaVersion !== 1
|
|
25
|
+
|| Object.keys(m).some(k => ![...required, 'python', 'timeoutMs', 'transport', 'idleTimeoutMs', 'acceptance'].includes(k)) || m.schemaVersion !== 1
|
|
23
26
|
|| (m.acceptance !== undefined && !validAcceptance(m.acceptance))
|
|
24
|
-
||
|
|
25
|
-
|| typeof m.checkpoint !== 'string' || !path.isAbsolute(m.checkpoint) || path.extname(m.checkpoint) !== '.safetensors'
|
|
27
|
+
|| strings.some(k => typeof m[k] !== 'string' || !m[k].trim() || m[k].length > 4096 || m[k].includes('\0'))
|
|
28
|
+
|| typeof m.checkpoint !== 'string' || !path.isAbsolute(m.checkpoint) || path.extname(m.checkpoint) !== (ngram ? '.bin' : '.safetensors')
|
|
26
29
|
|| ['weightsSha256', 'configSha256'].some(k => typeof m[k] !== 'string' || !/^[a-f0-9]{64}$/.test(m[k]))
|
|
27
30
|
|| (m.timeoutMs !== undefined && (!Number.isInteger(m.timeoutMs) || m.timeoutMs < 1 || m.timeoutMs > 10000))
|
|
28
|
-
|| (m.transport !== undefined && !['oneshot', 'resident'].includes(m.transport))
|
|
31
|
+
|| (m.transport !== undefined && !['oneshot', 'resident', 'ngram'].includes(m.transport))
|
|
29
32
|
|| (m.idleTimeoutMs !== undefined && (!Number.isInteger(m.idleTimeoutMs) || m.idleTimeoutMs < 60000 || m.idleTimeoutMs > 14400000))
|
|
30
33
|
|| (m.modelId === 'cua-ai/cua-s1-forms' && m.domain !== 'forms-v1')) throw new TypeError('invalid-manifest');
|
|
31
34
|
return true;
|
|
@@ -57,15 +60,22 @@ function score(request, manifestPath) {
|
|
|
57
60
|
validateRequest(request);
|
|
58
61
|
let manifest;
|
|
59
62
|
try { manifest = readManifest(manifestPath); } catch (_) { return unavailable('provider-config'); }
|
|
63
|
+
if (manifest.transport === 'ngram') return withAcceptance(inProcess(request, manifest), manifest);
|
|
60
64
|
if (manifest.transport === 'resident') return withAcceptance(require('./resident').score({ ...request }, manifest, manifestPath), manifest);
|
|
61
65
|
return withAcceptance(oneShot(request, manifest), manifest);
|
|
62
66
|
}
|
|
67
|
+
// The ngram transport scores in this process; an artifact mismatch is a configuration error, never a score.
|
|
68
|
+
function inProcess(request, manifest) {
|
|
69
|
+
try { return { status: 'scored', response: require('./ngram').score({ ...request }, manifest) }; }
|
|
70
|
+
catch (_) { return unavailable('provider-config'); }
|
|
71
|
+
}
|
|
63
72
|
// Async callers (the hook entry) reach a resident server without the sync worker bridge.
|
|
64
73
|
// One-shot has no server to overlap with, so it runs the same child synchronously.
|
|
65
74
|
async function scoreAsync(request, manifestPath) {
|
|
66
75
|
validateRequest(request);
|
|
67
76
|
let manifest;
|
|
68
77
|
try { manifest = readManifest(manifestPath); } catch (_) { return unavailable('provider-config'); }
|
|
78
|
+
if (manifest.transport === 'ngram') return withAcceptance(inProcess(request, manifest), manifest);
|
|
69
79
|
if (manifest.transport === 'resident') return withAcceptance(await require('./resident').scoreAsync({ ...request }, manifest, manifestPath), manifest);
|
|
70
80
|
return withAcceptance(oneShot(request, manifest), manifest);
|
|
71
81
|
}
|
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.29.0",
|
|
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",
|
|
@@ -84,12 +84,13 @@ function evaluate(corpus, records, sourceEvidence = null) {
|
|
|
84
84
|
const gates = {
|
|
85
85
|
reviewedHoldout: cases.length >= 200 && cases.every(c => c.reviewed)
|
|
86
86
|
&& ['en', 'zh-TW'].every(lang => cases.filter(c => c.language === lang).length >= 50),
|
|
87
|
-
acceptedPrecision: model.acceptedPrecision !== null && model.acceptedPrecision >= 0.
|
|
87
|
+
acceptedPrecision: model.acceptedPrecision !== null && model.acceptedPrecision >= 0.85,
|
|
88
88
|
coverage: model.coverage >= 0.8,
|
|
89
89
|
macroF1: model.macroF1 >= baseline.macroF1,
|
|
90
90
|
repeatability: agreement === 1,
|
|
91
91
|
warmLatency: warm.length >= cases.length && latency.warmP95Ms <= 100,
|
|
92
|
-
sourceProvenance: sourceEvidence?.status === 'recorded' && sourceEvidence.provenance?.cuaS1?.sourceRevisionStatus === 'pinned'
|
|
92
|
+
sourceProvenance: sourceEvidence?.status === 'recorded' && (sourceEvidence.provenance?.cuaS1?.sourceRevisionStatus === 'pinned'
|
|
93
|
+
|| (sourceEvidence.transport === 'ngram' && sourceEvidence.artifactVerified === true)),
|
|
93
94
|
policyEvidence: false,
|
|
94
95
|
liveHostEvidence: false,
|
|
95
96
|
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// In-process System One scorer: hashed character n-grams + a linear layer (docs/system-one-routing.md, "N-gram provider").
|
|
3
|
+
// Featurization must match scripts/system-one-train-ngram.py exactly; ci/mechanism-system-one-ngram.test.js proves it.
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const { createHash } = require('node:crypto');
|
|
6
|
+
|
|
7
|
+
const SIDE_KEYS = ['format', 'formatVersion', 'dim', 'nmax', 'hash', 'catalog', 'bias', 'metadata'];
|
|
8
|
+
const cache = new Map();
|
|
9
|
+
const configError = () => Object.assign(new Error('provider-config'), { code: 'provider-config' });
|
|
10
|
+
const sha = buf => createHash('sha256').update(buf).digest('hex');
|
|
11
|
+
|
|
12
|
+
function fnv1a32(text) {
|
|
13
|
+
let h = 0x811c9dc5;
|
|
14
|
+
for (const byte of Buffer.from(text, 'utf8')) { h ^= byte; h = Math.imul(h, 0x01000193) >>> 0; }
|
|
15
|
+
return h >>> 0;
|
|
16
|
+
}
|
|
17
|
+
// Map of bucket -> weight: log(1 + count) per code-point n-gram, one length bucket, L2-normalized.
|
|
18
|
+
function featurize(text, nmax, dim) {
|
|
19
|
+
const t = text.toLowerCase().split(/\s+/).filter(Boolean).join(' ');
|
|
20
|
+
const cps = Array.from(t);
|
|
21
|
+
const counts = new Map();
|
|
22
|
+
for (let n = 1; n <= nmax; n++) {
|
|
23
|
+
for (let i = 0; i + n <= cps.length; i++) {
|
|
24
|
+
const gram = cps.slice(i, i + n).join('');
|
|
25
|
+
if (!gram.trim()) continue;
|
|
26
|
+
const b = fnv1a32(`${n}:${gram}`) % dim;
|
|
27
|
+
counts.set(b, (counts.get(b) || 0) + 1);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const k = Math.min(8, Math.floor(Math.log2(Buffer.byteLength(t, 'utf8') + 1)));
|
|
31
|
+
counts.set(fnv1a32(`len:${k}`) % dim, 1);
|
|
32
|
+
const feats = new Map();
|
|
33
|
+
let norm = 0;
|
|
34
|
+
for (const [b, c] of counts) { const v = Math.log1p(c); feats.set(b, v); norm += v * v; }
|
|
35
|
+
norm = Math.sqrt(norm);
|
|
36
|
+
for (const [b, v] of feats) feats.set(b, v / norm);
|
|
37
|
+
return feats;
|
|
38
|
+
}
|
|
39
|
+
function validSidecar(s) {
|
|
40
|
+
const isPow2 = n => Number.isInteger(n) && n >= 1024 && n <= 1 << 20 && (n & (n - 1)) === 0;
|
|
41
|
+
return s && typeof s === 'object' && !Array.isArray(s) && Object.keys(s).length === SIDE_KEYS.length && SIDE_KEYS.every(k => Object.hasOwn(s, k))
|
|
42
|
+
&& s.format === 'harness-ngram' && s.formatVersion === 1 && isPow2(s.dim) && Number.isInteger(s.nmax) && s.nmax >= 1 && s.nmax <= 4
|
|
43
|
+
&& s.hash === 'fnv1a32' && Array.isArray(s.catalog) && s.catalog.length >= 2 && new Set(s.catalog).size === s.catalog.length
|
|
44
|
+
&& s.catalog.every(id => typeof id === 'string' && /^[a-z0-9._-]{1,80}$/.test(id))
|
|
45
|
+
&& Array.isArray(s.bias) && s.bias.length === s.catalog.length && s.bias.every(Number.isFinite)
|
|
46
|
+
&& s.metadata && typeof s.metadata === 'object' && !Array.isArray(s.metadata);
|
|
47
|
+
}
|
|
48
|
+
// Loads and verifies the artifact once per process; any mismatch throws provider-config.
|
|
49
|
+
function loadModel(manifest) {
|
|
50
|
+
const key = `${manifest.checkpoint}|${manifest.weightsSha256}|${manifest.configSha256}`;
|
|
51
|
+
if (cache.has(key)) return cache.get(key);
|
|
52
|
+
const sidecarPath = manifest.checkpoint.replace(/\.bin$/, '.json');
|
|
53
|
+
let side; let bin;
|
|
54
|
+
try {
|
|
55
|
+
const raw = fs.readFileSync(sidecarPath);
|
|
56
|
+
if (raw.length > 65536 || sha(raw) !== manifest.configSha256) throw configError();
|
|
57
|
+
side = JSON.parse(raw.toString('utf8'));
|
|
58
|
+
bin = fs.readFileSync(manifest.checkpoint);
|
|
59
|
+
} catch (_) { throw configError(); }
|
|
60
|
+
if (sha(bin) !== manifest.weightsSha256 || !validSidecar(side) || bin.length !== side.dim * side.catalog.length * 4) throw configError();
|
|
61
|
+
const W = new Float32Array(side.dim * side.catalog.length);
|
|
62
|
+
for (let i = 0; i < W.length; i++) W[i] = bin.readFloatLE(i * 4);
|
|
63
|
+
const model = { dim: side.dim, nmax: side.nmax, catalog: side.catalog, bias: side.bias, W };
|
|
64
|
+
cache.set(key, model);
|
|
65
|
+
return model;
|
|
66
|
+
}
|
|
67
|
+
function score(request, manifest) {
|
|
68
|
+
const model = loadModel(manifest);
|
|
69
|
+
const C = model.catalog.length;
|
|
70
|
+
if (request.options.length !== C || request.options.some((o, i) => o.id !== model.catalog[i])) throw configError();
|
|
71
|
+
const logits = model.bias.slice();
|
|
72
|
+
for (const [b, v] of featurize(request.context, model.nmax, model.dim)) {
|
|
73
|
+
for (let c = 0; c < C; c++) logits[c] += v * model.W[b * C + c];
|
|
74
|
+
}
|
|
75
|
+
const max = Math.max(...logits);
|
|
76
|
+
const exps = logits.map(z => Math.exp(z - max));
|
|
77
|
+
const sum = exps.reduce((s, x) => s + x, 0);
|
|
78
|
+
return {
|
|
79
|
+
schemaVersion: 1, requestHash: request.requestHash, catalogHash: request.catalogHash,
|
|
80
|
+
model: { id: manifest.modelId, revision: manifest.revision, domain: manifest.domain },
|
|
81
|
+
scores: request.options.map((o, i) => ({ id: o.id, probability: exps[i] / sum })),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
module.exports = { fnv1a32, featurize, loadModel, score };
|
|
@@ -17,15 +17,18 @@ const validAcceptance = a => exact(a, ['minConfidence', 'minMargin']) && inRange
|
|
|
17
17
|
const withAcceptance = (result, manifest) => (result && result.status === 'scored' && manifest.acceptance
|
|
18
18
|
? { ...result, acceptance: { ...manifest.acceptance } } : result);
|
|
19
19
|
function validateManifest(m) {
|
|
20
|
-
|
|
20
|
+
// The in-process ngram transport needs no Python and loads a .bin; the others run the CUA-S1 adapter.
|
|
21
|
+
const ngram = !!m && m.transport === 'ngram';
|
|
22
|
+
const required = ['schemaVersion', ...(ngram ? [] : ['python']), 'checkpoint', 'weightsSha256', 'configSha256', 'modelId', 'revision', 'domain'];
|
|
23
|
+
const strings = ['modelId', 'revision', 'domain', ...(ngram && !Object.hasOwn(m, 'python') ? [] : ['python'])];
|
|
21
24
|
if (!m || typeof m !== 'object' || Array.isArray(m) || required.some(k => !Object.hasOwn(m, k))
|
|
22
|
-
|| Object.keys(m).some(k => ![...required, 'timeoutMs', 'transport', 'idleTimeoutMs', 'acceptance'].includes(k)) || m.schemaVersion !== 1
|
|
25
|
+
|| Object.keys(m).some(k => ![...required, 'python', 'timeoutMs', 'transport', 'idleTimeoutMs', 'acceptance'].includes(k)) || m.schemaVersion !== 1
|
|
23
26
|
|| (m.acceptance !== undefined && !validAcceptance(m.acceptance))
|
|
24
|
-
||
|
|
25
|
-
|| typeof m.checkpoint !== 'string' || !path.isAbsolute(m.checkpoint) || path.extname(m.checkpoint) !== '.safetensors'
|
|
27
|
+
|| strings.some(k => typeof m[k] !== 'string' || !m[k].trim() || m[k].length > 4096 || m[k].includes('\0'))
|
|
28
|
+
|| typeof m.checkpoint !== 'string' || !path.isAbsolute(m.checkpoint) || path.extname(m.checkpoint) !== (ngram ? '.bin' : '.safetensors')
|
|
26
29
|
|| ['weightsSha256', 'configSha256'].some(k => typeof m[k] !== 'string' || !/^[a-f0-9]{64}$/.test(m[k]))
|
|
27
30
|
|| (m.timeoutMs !== undefined && (!Number.isInteger(m.timeoutMs) || m.timeoutMs < 1 || m.timeoutMs > 10000))
|
|
28
|
-
|| (m.transport !== undefined && !['oneshot', 'resident'].includes(m.transport))
|
|
31
|
+
|| (m.transport !== undefined && !['oneshot', 'resident', 'ngram'].includes(m.transport))
|
|
29
32
|
|| (m.idleTimeoutMs !== undefined && (!Number.isInteger(m.idleTimeoutMs) || m.idleTimeoutMs < 60000 || m.idleTimeoutMs > 14400000))
|
|
30
33
|
|| (m.modelId === 'cua-ai/cua-s1-forms' && m.domain !== 'forms-v1')) throw new TypeError('invalid-manifest');
|
|
31
34
|
return true;
|
|
@@ -57,15 +60,22 @@ function score(request, manifestPath) {
|
|
|
57
60
|
validateRequest(request);
|
|
58
61
|
let manifest;
|
|
59
62
|
try { manifest = readManifest(manifestPath); } catch (_) { return unavailable('provider-config'); }
|
|
63
|
+
if (manifest.transport === 'ngram') return withAcceptance(inProcess(request, manifest), manifest);
|
|
60
64
|
if (manifest.transport === 'resident') return withAcceptance(require('./resident').score({ ...request }, manifest, manifestPath), manifest);
|
|
61
65
|
return withAcceptance(oneShot(request, manifest), manifest);
|
|
62
66
|
}
|
|
67
|
+
// The ngram transport scores in this process; an artifact mismatch is a configuration error, never a score.
|
|
68
|
+
function inProcess(request, manifest) {
|
|
69
|
+
try { return { status: 'scored', response: require('./ngram').score({ ...request }, manifest) }; }
|
|
70
|
+
catch (_) { return unavailable('provider-config'); }
|
|
71
|
+
}
|
|
63
72
|
// Async callers (the hook entry) reach a resident server without the sync worker bridge.
|
|
64
73
|
// One-shot has no server to overlap with, so it runs the same child synchronously.
|
|
65
74
|
async function scoreAsync(request, manifestPath) {
|
|
66
75
|
validateRequest(request);
|
|
67
76
|
let manifest;
|
|
68
77
|
try { manifest = readManifest(manifestPath); } catch (_) { return unavailable('provider-config'); }
|
|
78
|
+
if (manifest.transport === 'ngram') return withAcceptance(inProcess(request, manifest), manifest);
|
|
69
79
|
if (manifest.transport === 'resident') return withAcceptance(await require('./resident').scoreAsync({ ...request }, manifest, manifestPath), manifest);
|
|
70
80
|
return withAcceptance(oneShot(request, manifest), manifest);
|
|
71
81
|
}
|
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:03c78df6-955e-5903-b3d9-620c6be8e2d4",
|
|
6
6
|
"version": 1,
|
|
7
7
|
"metadata": {
|
|
8
|
-
"timestamp": "2026-09-
|
|
8
|
+
"timestamp": "2026-09-28T01:49:53.842Z",
|
|
9
9
|
"tools": [
|
|
10
10
|
{
|
|
11
11
|
"vendor": "Harness Everything",
|
|
12
12
|
"name": "generate-sbom.js",
|
|
13
|
-
"version": "0.
|
|
13
|
+
"version": "0.29.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.29.0",
|
|
19
19
|
"name": "harness-everything",
|
|
20
|
-
"version": "0.
|
|
21
|
-
"purl": "pkg:npm/harness-everything@0.
|
|
20
|
+
"version": "0.29.0",
|
|
21
|
+
"purl": "pkg:npm/harness-everything@0.29.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.29.0",
|
|
2003
2003
|
"dependsOn": [
|
|
2004
2004
|
"pkg:npm/%40commitlint/cli@19.8.1",
|
|
2005
2005
|
"pkg:npm/%40commitlint/config-conventional@19.8.1",
|
|
@@ -13,10 +13,15 @@ async function run(corpus, manifest) {
|
|
|
13
13
|
validateCorpus(corpus);
|
|
14
14
|
let config = null;
|
|
15
15
|
try { config = readManifest(manifest); } catch (_) { /* Missing provider remains an explicit unavailable measurement. */ }
|
|
16
|
-
// Resident runs are measured only after readiness
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
const
|
|
16
|
+
// Resident runs are measured only after readiness and ngram scores in process after one verified load,
|
|
17
|
+
// so their samples are warm; one-shot samples are cold.
|
|
18
|
+
const isResident = config?.transport === 'resident';
|
|
19
|
+
const isNgram = config?.transport === 'ngram';
|
|
20
|
+
const warm = isResident || isNgram;
|
|
21
|
+
const wasRunning = isResident && resident.status(config, manifest).running;
|
|
22
|
+
const ready = isResident && resident.ensureReady(config, manifest, 60000);
|
|
23
|
+
let artifactVerified = false;
|
|
24
|
+
if (isNgram) { try { require('../harness-everything/scripts/system-one/ngram').loadModel(config); artifactVerified = true; } catch (_) { /* recorded below */ } }
|
|
20
25
|
const records = [];
|
|
21
26
|
const originalMode = process.env.HARNESS_SYSTEM_ONE_MODE;
|
|
22
27
|
const originalLog = console.log;
|
|
@@ -37,7 +42,7 @@ async function run(corpus, manifest) {
|
|
|
37
42
|
records.push({ id: c.id, baseline: tier === 'unclassified' ? null : tier, runs });
|
|
38
43
|
}
|
|
39
44
|
} finally {
|
|
40
|
-
if (
|
|
45
|
+
if (isResident && !wasRunning) resident.stop(config, manifest);
|
|
41
46
|
console.log = originalLog;
|
|
42
47
|
if (originalMode === undefined) delete process.env.HARNESS_SYSTEM_ONE_MODE;
|
|
43
48
|
else process.env.HARNESS_SYSTEM_ONE_MODE = originalMode;
|
|
@@ -47,11 +52,13 @@ async function run(corpus, manifest) {
|
|
|
47
52
|
const m = JSON.parse(fs.readFileSync(manifest, 'utf8'));
|
|
48
53
|
artifact = { declaredModelId: m.modelId, declaredRevision: m.revision, weightsSha256: m.weightsSha256, configSha256: m.configSha256 };
|
|
49
54
|
} catch (_) { /* Missing provider remains an explicit unavailable measurement. */ }
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
55
|
+
// The ngram transport has no Python package to probe; its provenance is the hash-verified artifact.
|
|
56
|
+
const source = isNgram ? { status: 'recorded', transport: 'ngram', artifactVerified } : provenance(manifest);
|
|
57
|
+
const kind = isNgram ? 'offline-ngram' : isResident ? 'offline-resident' : 'offline-one-shot';
|
|
58
|
+
return { ...evaluate(corpus, records, source), evidence: { kind, artifact, source,
|
|
59
|
+
residentReady: isResident ? ready : null,
|
|
53
60
|
environment: { cpu: os.cpus()[0]?.model || 'unknown', os: `${os.platform()} ${os.release()} ${os.arch()}`, node: process.version,
|
|
54
|
-
python: source.status === 'recorded' ? source.provenance.python : null, threads: 1 },
|
|
61
|
+
python: source.status === 'recorded' && source.provenance ? source.provenance.python : null, threads: 1 },
|
|
55
62
|
limitations: ['No independently verified holdout review', ...(warm ? [] : ['No warm inference measurement']), 'No live-host or policy evidence'] }, records };
|
|
56
63
|
}
|
|
57
64
|
if (require.main === module) {
|
|
@@ -13,7 +13,7 @@ function decideRow(probs, { minConfidence, minMargin }) {
|
|
|
13
13
|
if (margin === 0 || top[0] < minConfidence || margin < minMargin || IDS[top[1]] === 'unclassified') return null;
|
|
14
14
|
return IDS[top[1]];
|
|
15
15
|
}
|
|
16
|
-
function calibrate(rows, { minPrecision = 0.
|
|
16
|
+
function calibrate(rows, { minPrecision = 0.85 } = {}) {
|
|
17
17
|
let best = null;
|
|
18
18
|
for (let c = 50; c <= 99; c++) {
|
|
19
19
|
for (let m = 0; m <= 90; m += 5) {
|