harness-everything 0.51.0 → 0.53.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 +54 -0
- 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/benchmarks/results/live-host/opencode-2026-11-15-workspace/README.md +7 -0
- package/benchmarks/results/live-host/opencode-2026-11-15-workspace/live-workspace-probe.js +16 -0
- package/benchmarks/results/live-host/opencode-2026-11-15-workspace/live-workspace-trace-2026-11-15.jsonl +4 -0
- package/ci/mechanism-2am-observations-session-import.test.js +4 -1
- package/ci/mechanism-2n-opencode-plugin.test.js +1 -1
- package/ci/mechanism-2p-opencode-v2-entrypoint.test.js +18 -3
- package/ci/mechanism-338-opencode-async.test.js +20 -3
- package/ci/mechanism-34-observations.test.js +127 -23
- package/ci/mechanism-341-opencode-lane.test.js +7 -1
- package/ci/mechanism-349-ci-change-scope.test.js +260 -0
- package/ci/mechanism-397-cycle-import.test.js +399 -0
- package/ci/mechanism-397-host-acceptance.test.js +119 -0
- package/ci/mechanism-397-opencode-observations.test.js +1922 -0
- package/ci/mechanism-handoff-file.test.js +121 -0
- package/ci/mechanism-system-one-contract.test.js +9 -2
- package/ci/mechanism-system-one-curves.test.js +223 -0
- package/ci/mechanism-system-one-cycle.test.js +1204 -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/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/governed-index.md +2 -0
- package/docs/platform-capabilities.md +13 -6
- package/docs/routing.md +2 -2
- package/docs/system-one-cycle.md +77 -0
- package/docs/system-one-observations.md +43 -11
- 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/observations.js +48 -7
- package/opencode-plugin/README.md +22 -8
- package/opencode-plugin/index.mjs +424 -44
- 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/hooks/scripts/lib/observations.js +48 -7
- 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 +472 -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 +67 -0
- package/scripts/system-one-cycle/common.js +175 -0
- package/scripts/system-one-cycle/engines.js +62 -0
- package/scripts/system-one-cycle/evaluate.js +73 -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 +136 -0
- package/scripts/system-one-observations-export.js +58 -6
- package/scripts/system-one-observations-import-store.js +128 -0
- package/scripts/system-one-observations-review.js +4 -5
- package/scripts/system-one-train.py +117 -61
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
|
-
"""Train the System One harness-routing-v1
|
|
2
|
+
"""Train the System One harness-routing-v1 scorer (docs/system-one-training.md).
|
|
3
3
|
|
|
4
4
|
Run with the System One venv Python (torch + pinned cua_s1). Data handling is stdlib-only so it is
|
|
5
5
|
tested without torch; torch and cua_s1 are imported only inside train().
|
|
@@ -14,6 +14,13 @@ import sys
|
|
|
14
14
|
sys.dont_write_bytecode = True
|
|
15
15
|
REPO = Path(__file__).resolve().parents[1]
|
|
16
16
|
DEFAULT_HOLDOUT = REPO / 'benchmarks' / 'fixtures' / 'system-one-holdout.json'
|
|
17
|
+
DEFAULT_INTENT_HOLDOUT = REPO / 'benchmarks' / 'fixtures' / 'system-one-intent-holdout.json'
|
|
18
|
+
TIER_IDS = ('tier1', 'tier2', 'tier3')
|
|
19
|
+
OPTION_TOKENS = 96
|
|
20
|
+
# Whole-forward-pass budget: prompt tokens plus one pass over every option, per example. Attention memory
|
|
21
|
+
# grows with the square of the sequence length, so a large budget packs many long prompts into one batch
|
|
22
|
+
# and OOMs the 6 GB guard; 16,384 keeps the observed peak near 1.0-1.7 GB.
|
|
23
|
+
TOKEN_BUDGET = 16384
|
|
17
24
|
|
|
18
25
|
|
|
19
26
|
def load_jsonl(path):
|
|
@@ -25,50 +32,87 @@ def sha256_file(path):
|
|
|
25
32
|
|
|
26
33
|
|
|
27
34
|
def catalog_from_holdout(path):
|
|
28
|
-
"""
|
|
35
|
+
"""Read the fixed option catalog from the evaluation corpus."""
|
|
29
36
|
corpus = json.loads(Path(path).read_text(encoding='utf-8'))
|
|
30
37
|
return [{'id': o['id'], 'text': o['text']} for o in corpus['cases'][0]['request']['options']]
|
|
31
38
|
|
|
32
39
|
|
|
33
|
-
def
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
def catalog_for(task, holdout=None):
|
|
41
|
+
if task == 'validity':
|
|
42
|
+
return [{'id': 'invalid', 'text': 'Needs previous conversation context to understand; the current text alone is insufficient.'}]
|
|
43
|
+
if task not in ('intent', 'tier'):
|
|
44
|
+
raise ValueError(f'unknown task: {task!r}')
|
|
45
|
+
path = holdout or (DEFAULT_INTENT_HOLDOUT if task == 'intent' else DEFAULT_HOLDOUT)
|
|
46
|
+
catalog = catalog_from_holdout(path)
|
|
47
|
+
if task == 'tier':
|
|
48
|
+
catalog = [option for option in catalog if option['id'] in TIER_IDS]
|
|
49
|
+
if tuple(option['id'] for option in catalog) != TIER_IDS:
|
|
50
|
+
raise ValueError('tier holdout must define tier1, tier2, and tier3')
|
|
51
|
+
return catalog
|
|
39
52
|
|
|
40
53
|
|
|
41
|
-
def join(prompts, labels
|
|
42
|
-
"""
|
|
43
|
-
|
|
54
|
+
def join(prompts, labels):
|
|
55
|
+
"""Join prompt text to its label row; duplicate label ids are an error."""
|
|
56
|
+
by_id = {}
|
|
44
57
|
for row in labels:
|
|
45
|
-
if row['id'] in
|
|
58
|
+
if row['id'] in by_id:
|
|
46
59
|
raise ValueError(f'duplicate label for {row["id"]}')
|
|
47
|
-
|
|
48
|
-
for
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
for
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
by_id[row['id']] = row
|
|
61
|
+
return [{**p, **by_id[p['id']]} for p in prompts if p['id'] in by_id]
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def eligible_rows(rows, task):
|
|
65
|
+
return rows if task == 'validity' else [row for row in rows if row['gold'] is not None]
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def build_targets(row, catalog, task, target='label'):
|
|
69
|
+
ids = [option['id'] for option in catalog]
|
|
70
|
+
if task == 'validity':
|
|
71
|
+
if row['gold'] is not None and row['gold'] not in TIER_IDS:
|
|
72
|
+
raise ValueError(f'unknown tier gold label: {row["gold"]!r}')
|
|
73
|
+
return [float(row['gold'] is None)]
|
|
74
|
+
if row['gold'] is None:
|
|
75
|
+
raise ValueError(f'null gold is not eligible for {task}')
|
|
76
|
+
if task == 'tier':
|
|
77
|
+
if row['gold'] not in ids:
|
|
78
|
+
raise ValueError(f'unknown gold label: {row["gold"]!r}')
|
|
79
|
+
return [float(option == row['gold']) for option in ids]
|
|
80
|
+
if task != 'intent':
|
|
81
|
+
raise ValueError(f'unknown task: {task!r}')
|
|
82
|
+
if target == 'scores':
|
|
83
|
+
scores = row.get('scores') or {}
|
|
84
|
+
values = [float(scores.get(option, 0.0)) for option in ids]
|
|
85
|
+
if any(not 0.0 <= value <= 1.0 for value in values):
|
|
86
|
+
raise ValueError('intent scores must be between 0 and 1')
|
|
87
|
+
return values
|
|
88
|
+
if target != 'label':
|
|
89
|
+
raise ValueError(f'unknown target: {target!r}')
|
|
90
|
+
positive = {row['gold'], *row.get('secondary', [])}
|
|
91
|
+
if not positive.issubset(ids):
|
|
92
|
+
raise ValueError(f'unknown intent label: {sorted(positive - set(ids))!r}')
|
|
93
|
+
return [float(option in positive) for option in ids]
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def target_gold(row, task):
|
|
97
|
+
return ('invalid' if row['gold'] is None else 'actionable') if task == 'validity' else row['gold']
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def validation_record(row, catalog, probabilities, task):
|
|
101
|
+
return {'id': row['id'], 'gold': target_gold(row, task),
|
|
102
|
+
'scores': dict(zip((option['id'] for option in catalog), probabilities))}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def make_batches(lengths, token_budget, n_options, option_tokens):
|
|
106
|
+
"""Length-bucketed batches: each batch's size times its longest item's forward-pass cost
|
|
107
|
+
(prompt tokens plus one pass over every option) stays within the whole-pass budget."""
|
|
108
|
+
costs = [length + n_options * option_tokens for length in lengths]
|
|
109
|
+
order = sorted(range(len(costs)), key=lambda i: (costs[i], i))
|
|
66
110
|
batches, current, longest = [], [], 0
|
|
67
111
|
for i in order:
|
|
68
|
-
longest_if_added = max(longest,
|
|
112
|
+
longest_if_added = max(longest, costs[i])
|
|
69
113
|
if current and (len(current) + 1) * longest_if_added > token_budget:
|
|
70
114
|
batches.append(current)
|
|
71
|
-
current, longest_if_added = [],
|
|
115
|
+
current, longest_if_added = [], costs[i]
|
|
72
116
|
current.append(i)
|
|
73
117
|
longest = longest_if_added
|
|
74
118
|
if current:
|
|
@@ -84,28 +128,32 @@ def train(args):
|
|
|
84
128
|
torch.manual_seed(args.seed)
|
|
85
129
|
torch.set_num_threads(max(1, args.threads))
|
|
86
130
|
data_dir = Path(args.data_dir)
|
|
87
|
-
catalog =
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
131
|
+
catalog = catalog_for(args.task, args.holdout)
|
|
132
|
+
labels_file = ('labels-intent-scores.jsonl' if args.target == 'scores' else 'labels-intent.jsonl') \
|
|
133
|
+
if args.task == 'intent' else 'labels.jsonl'
|
|
134
|
+
examples = eligible_rows(join(load_jsonl(data_dir / 'prompts.jsonl'), load_jsonl(data_dir / labels_file)), args.task)
|
|
91
135
|
options = tuple(o['text'] for o in catalog)
|
|
92
136
|
split = {name: [e for e in examples if e['split'] == name] for name in ('train', 'validation')}
|
|
93
137
|
config = {'encoder': 'tinyx', 'width': 128, 'rank': 128, 'layers': 2, 'heads': 4, 'dropout': 0.1,
|
|
94
|
-
'context_tokens': args.context_tokens, 'option_tokens':
|
|
138
|
+
'context_tokens': args.context_tokens, 'option_tokens': OPTION_TOKENS}
|
|
95
139
|
model, collator = make_system(config, 'cpu')
|
|
96
140
|
|
|
97
141
|
def to_examples(rows):
|
|
98
|
-
|
|
142
|
+
examples = []
|
|
143
|
+
for row in rows:
|
|
144
|
+
targets = build_targets(row, catalog, args.task, args.target)
|
|
145
|
+
examples.append(ChoiceExample(context=row['text'], options=options, label=targets.index(max(targets))))
|
|
146
|
+
return examples
|
|
99
147
|
|
|
100
148
|
def lengths(rows):
|
|
101
149
|
return [min(len(r['text'].encode('utf-8')), args.context_tokens) or 1 for r in rows]
|
|
102
150
|
|
|
103
151
|
train_x, val_x = to_examples(split['train']), to_examples(split['validation'])
|
|
104
|
-
|
|
105
|
-
|
|
152
|
+
train_targets = torch.tensor([build_targets(r, catalog, args.task, args.target) for r in split['train']], dtype=torch.float)
|
|
153
|
+
val_targets = torch.tensor([build_targets(r, catalog, args.task, args.target) for r in split['validation']], dtype=torch.float)
|
|
154
|
+
train_batches = make_batches(lengths(split['train']), args.token_budget, len(catalog), config['option_tokens'])
|
|
155
|
+
val_batches = make_batches(lengths(split['validation']), args.token_budget, len(catalog), config['option_tokens'])
|
|
106
156
|
optimizer = torch.optim.AdamW(model.parameters(), lr=args.lr, weight_decay=0.01)
|
|
107
|
-
# Class balance counters the tier2-heavy labels; validation NLL stays unweighted so epochs remain comparable.
|
|
108
|
-
weight = torch.tensor(class_weights([e.label for e in train_x], len(catalog)), dtype=torch.float) if args.balance else None
|
|
109
157
|
|
|
110
158
|
def evaluate():
|
|
111
159
|
model.eval()
|
|
@@ -114,9 +162,10 @@ def train(args):
|
|
|
114
162
|
for batch in val_batches:
|
|
115
163
|
tensors = collator([val_x[i] for i in batch])
|
|
116
164
|
logits = model(tensors)
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
165
|
+
targets = val_targets[batch]
|
|
166
|
+
nll += torch.nn.functional.binary_cross_entropy_with_logits(logits, targets, reduction='sum').item()
|
|
167
|
+
p = logits.sigmoid()
|
|
168
|
+
correct += ((p >= 0.5) == targets.bool()).all(dim=-1).sum().item()
|
|
120
169
|
for row, i in enumerate(batch):
|
|
121
170
|
probs[i] = p[row].tolist()
|
|
122
171
|
n = max(1, len(val_x))
|
|
@@ -129,35 +178,36 @@ def train(args):
|
|
|
129
178
|
random.shuffle(order)
|
|
130
179
|
total = 0.0
|
|
131
180
|
for b in order:
|
|
132
|
-
|
|
133
|
-
|
|
181
|
+
batch = train_batches[b]
|
|
182
|
+
tensors = collator([train_x[i] for i in batch])
|
|
183
|
+
loss = torch.nn.functional.binary_cross_entropy_with_logits(model(tensors), train_targets[batch])
|
|
134
184
|
optimizer.zero_grad()
|
|
135
185
|
loss.backward()
|
|
136
186
|
torch.nn.utils.clip_grad_norm_(model.parameters(), 1.0)
|
|
137
187
|
optimizer.step()
|
|
138
|
-
total += loss.item() * len(
|
|
188
|
+
total += loss.item() * len(batch)
|
|
139
189
|
metrics, probs = evaluate()
|
|
140
190
|
history.append({'epoch': epoch, 'trainLoss': total / max(1, len(train_x)), **metrics})
|
|
141
191
|
print(json.dumps(history[-1]), flush=True)
|
|
142
192
|
if best is None or metrics['nll'] < best['metrics']['nll']:
|
|
143
|
-
best = {'epoch': epoch, 'metrics': metrics, '
|
|
193
|
+
best = {'epoch': epoch, 'metrics': metrics, 'scores': probs,
|
|
144
194
|
'state': {k: v.detach().clone() for k, v in model.state_dict().items()}}
|
|
145
195
|
|
|
146
196
|
model.load_state_dict(best['state'])
|
|
147
197
|
out = Path(args.out)
|
|
148
198
|
out.mkdir(parents=True, exist_ok=True)
|
|
149
|
-
datasets = {name: sha256_file(data_dir / name) for name in ('prompts.jsonl',
|
|
150
|
-
if overrides_path.exists():
|
|
151
|
-
datasets['owner-overrides.jsonl'] = sha256_file(overrides_path)
|
|
199
|
+
datasets = {name: sha256_file(data_dir / name) for name in ('prompts.jsonl', labels_file)}
|
|
152
200
|
metadata = {'domain': 'harness-routing-v1', 'bestEpoch': best['epoch'], 'validation': best['metrics'],
|
|
153
|
-
'datasets': datasets, 'seed': args.seed, 'catalog': [o['id'] for o in catalog]
|
|
201
|
+
'datasets': datasets, 'seed': args.seed, 'catalog': [o['id'] for o in catalog],
|
|
202
|
+
'task': args.task, 'target': args.target, 'loss': 'binary_cross_entropy'}
|
|
154
203
|
save_checkpoint(out / 'harness-routing-v1.safetensors', model, config, metadata)
|
|
155
204
|
with (out / 'val-scores.jsonl').open('w', encoding='utf-8') as fh:
|
|
156
|
-
for row,
|
|
157
|
-
fh.write(json.dumps(
|
|
205
|
+
for row, scores in zip(split['validation'], best['scores']):
|
|
206
|
+
fh.write(json.dumps(validation_record(row, catalog, scores, args.task)) + '\n')
|
|
158
207
|
counts = {name: len(rows) for name, rows in split.items()}
|
|
159
208
|
report = {'schemaVersion': 1, 'config': config, 'counts': counts, 'bestEpoch': best['epoch'], 'history': history,
|
|
160
|
-
'datasets': datasets, 'seed': args.seed
|
|
209
|
+
'datasets': datasets, 'seed': args.seed, 'task': args.task, 'target': args.target,
|
|
210
|
+
'catalog': [o['id'] for o in catalog]}
|
|
161
211
|
(out / 'train-report.json').write_text(json.dumps(report, indent=2) + '\n', encoding='utf-8')
|
|
162
212
|
print(json.dumps({'counts': counts, 'bestEpoch': best['epoch'], 'validation': best['metrics']}))
|
|
163
213
|
|
|
@@ -166,15 +216,21 @@ def main(argv=None):
|
|
|
166
216
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
167
217
|
parser.add_argument('--data-dir', required=True)
|
|
168
218
|
parser.add_argument('--out', required=True)
|
|
169
|
-
parser.add_argument('--holdout',
|
|
219
|
+
parser.add_argument('--holdout', help='fixed option catalog source (defaults to the task holdout)')
|
|
170
220
|
parser.add_argument('--epochs', type=int, default=12)
|
|
171
221
|
parser.add_argument('--lr', type=float, default=1e-3)
|
|
172
222
|
parser.add_argument('--seed', type=int, default=7)
|
|
173
223
|
parser.add_argument('--threads', type=int, default=4)
|
|
174
224
|
parser.add_argument('--context-tokens', type=int, default=1024)
|
|
175
|
-
parser.add_argument('--token-budget', type=int, default=
|
|
176
|
-
|
|
177
|
-
|
|
225
|
+
parser.add_argument('--token-budget', type=int, default=TOKEN_BUDGET,
|
|
226
|
+
help='whole-forward-pass tokens per batch (prompt plus every option)')
|
|
227
|
+
parser.add_argument('--task', choices=['validity', 'intent', 'tier'], default='tier')
|
|
228
|
+
parser.add_argument('--target', choices=['label', 'scores'], default='label',
|
|
229
|
+
help='scores: per-intent soft labels from labels-intent-scores.jsonl (intent only)')
|
|
230
|
+
args = parser.parse_args(argv)
|
|
231
|
+
if args.target == 'scores' and args.task != 'intent':
|
|
232
|
+
parser.error('--target scores needs --task intent')
|
|
233
|
+
train(args)
|
|
178
234
|
|
|
179
235
|
|
|
180
236
|
if __name__ == '__main__':
|