synth-code 0.0.1__py3-none-macosx_15_0_arm64.whl
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.
- synth_code/__init__.py +0 -0
- synth_code/account.py +551 -0
- synth_code/account_http.py +86 -0
- synth_code/account_refusal.py +80 -0
- synth_code/accounting.py +148 -0
- synth_code/activity_grouping.py +149 -0
- synth_code/agent_panels.py +127 -0
- synth_code/approvals.py +397 -0
- synth_code/blobs.py +31 -0
- synth_code/cli.py +734 -0
- synth_code/client.py +413 -0
- synth_code/composer_delivery.py +139 -0
- synth_code/conversation.py +949 -0
- synth_code/daemon.py +34 -0
- synth_code/edition.py +306 -0
- synth_code/enrollment.py +304 -0
- synth_code/file_edit_facts.py +10 -0
- synth_code/freeze.py +234 -0
- synth_code/grant.py +59 -0
- synth_code/history.py +140 -0
- synth_code/history_generated.py +219 -0
- synth_code/history_wire.py +166 -0
- synth_code/image_input.py +109 -0
- synth_code/image_preview.py +105 -0
- synth_code/legacy_history.py +161 -0
- synth_code/live_turns.py +171 -0
- synth_code/model_picker.py +311 -0
- synth_code/native/manifest.json +1 -0
- synth_code/native/synth-code-runtime +0 -0
- synth_code/native.py +95 -0
- synth_code/oauth.py +284 -0
- synth_code/operator.py +116 -0
- synth_code/pack_source.py +65 -0
- synth_code/panel_request.py +291 -0
- synth_code/panels.py +40 -0
- synth_code/plugin_host.py +459 -0
- synth_code/protocol.py +35 -0
- synth_code/provider.py +313 -0
- synth_code/provider_fault.py +173 -0
- synth_code/provider_frames.py +571 -0
- synth_code/recommendation.py +324 -0
- synth_code/report.py +72 -0
- synth_code/research_events.py +44 -0
- synth_code/research_trace.py +449 -0
- synth_code/rex_view.py +58 -0
- synth_code/runtime_refusal.py +108 -0
- synth_code/schema/budgets.json +17 -0
- synth_code/schema/history-v2.json +1002 -0
- synth_code/session.py +291 -0
- synth_code/shoal.py +564 -0
- synth_code/side_panel.py +309 -0
- synth_code/skills.py +269 -0
- synth_code/slash.py +425 -0
- synth_code/source_view.py +135 -0
- synth_code/starter.json +13 -0
- synth_code/stdio.py +75 -0
- synth_code/stream.py +142 -0
- synth_code/subscriptions.py +267 -0
- synth_code/synth_authority.py +362 -0
- synth_code/synth_extra.py +32 -0
- synth_code/terminal.py +817 -0
- synth_code/terminal_journal.py +284 -0
- synth_code/terminal_layout.py +643 -0
- synth_code/terminal_surfaces.py +470 -0
- synth_code/terminal_viewport.py +125 -0
- synth_code/tool_render.py +86 -0
- synth_code/transcript_frames.py +212 -0
- synth_code/transcript_placement.py +63 -0
- synth_code/transcript_rows.py +456 -0
- synth_code/transport.py +243 -0
- synth_code/v001_history.py +468 -0
- synth_code/view.py +854 -0
- synth_code/views/__init__.py +93 -0
- synth_code/views/charts.py +196 -0
- synth_code/views/curses_adapter.py +116 -0
- synth_code/views/engine.py +170 -0
- synth_code/views/model.py +226 -0
- synth_code/views/primitives.py +270 -0
- synth_code/views/tiling.py +124 -0
- synth_code-0.0.1.dist-info/METADATA +50 -0
- synth_code-0.0.1.dist-info/RECORD +110 -0
- synth_code-0.0.1.dist-info/WHEEL +5 -0
- synth_code-0.0.1.dist-info/entry_points.txt +6 -0
- synth_code-0.0.1.dist-info/licenses/temper/LICENSE-APACHE +190 -0
- synth_code-0.0.1.dist-info/licenses/temper/LICENSE-MIT +21 -0
- synth_code-0.0.1.dist-info/licenses/temper/SOURCE.json +433 -0
- synth_code-0.0.1.dist-info/top_level.txt +2 -0
- synth_code_plugins/_sdk/__init__.py +19 -0
- synth_code_plugins/_sdk/callback_wire.py +240 -0
- synth_code_plugins/_sdk/callbacks.py +317 -0
- synth_code_plugins/_sdk/compliance.py +51 -0
- synth_code_plugins/_sdk/contracts.py +236 -0
- synth_code_plugins/_sdk/discovery.py +75 -0
- synth_code_plugins/_sdk/job_binding.py +71 -0
- synth_code_plugins/_sdk/lifecycle.py +50 -0
- synth_code_plugins/_sdk/lifecycle_generated.py +15 -0
- synth_code_plugins/_sdk/manifest.py +269 -0
- synth_code_plugins/_sdk/pack.py +332 -0
- synth_code_plugins/_sdk/push.py +98 -0
- synth_code_plugins/_sdk/records.py +26 -0
- synth_code_plugins/_sdk/registry.py +491 -0
- synth_code_plugins/_sdk/schemas.py +210 -0
- synth_code_plugins/_sdk/sources.py +230 -0
- synth_code_plugins/_sdk/surfaces.py +54 -0
- synth_code_plugins/_sdk/tools.py +172 -0
- synth_code_plugins/_sdk/worker_memory.py +49 -0
- synth_code_plugins/core/SKILL.md +6 -0
- synth_code_plugins/core/__init__.py +21 -0
- synth_code_plugins/core/plugin.toml +44 -0
- synth_code_plugins/core/source.py +18 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
"""Revision-bound experiment recommendations from committed public pair evidence."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
import math
|
|
8
|
+
import re
|
|
9
|
+
|
|
10
|
+
from .client import Client
|
|
11
|
+
from .history import events, paired_grade_events
|
|
12
|
+
from .session import latest, revise
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"choose_experiment",
|
|
16
|
+
"current_preference",
|
|
17
|
+
"recommend_next",
|
|
18
|
+
"recommendation_lines",
|
|
19
|
+
"set_preference",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
PREFERENCE = "experiment-evidence-order"
|
|
23
|
+
PREFERENCE_KIND = "pressure.correction"
|
|
24
|
+
DECISION_KIND = "pressure.decision"
|
|
25
|
+
DECISION_PREFIX = "next-experiment-"
|
|
26
|
+
INSTRUCTIONS = {
|
|
27
|
+
"default": "Use the default evidence order. Lead with the largest absolute paired score changes.",
|
|
28
|
+
"regressions-first": (
|
|
29
|
+
"Lead experiment recommendations with losing seeds. Show the most negative "
|
|
30
|
+
"paired deltas first, and cite this active preference revision."
|
|
31
|
+
),
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def set_preference(
|
|
36
|
+
client: Client,
|
|
37
|
+
mode: str,
|
|
38
|
+
*,
|
|
39
|
+
operation: str,
|
|
40
|
+
expected: int | None = None,
|
|
41
|
+
cause: int = 1,
|
|
42
|
+
note: str | None = None,
|
|
43
|
+
) -> dict:
|
|
44
|
+
"""Record, supersede, or clear this investigation's evidence-order correction."""
|
|
45
|
+
_validate_run(client)
|
|
46
|
+
if mode == "losing-seeds-first":
|
|
47
|
+
mode = "regressions-first"
|
|
48
|
+
if mode not in INSTRUCTIONS:
|
|
49
|
+
raise ValueError("Choose regressions-first or default")
|
|
50
|
+
if not re.fullmatch(r"[A-Za-z0-9_-]{1,96}", operation):
|
|
51
|
+
raise ValueError("Invalid preference operation ID")
|
|
52
|
+
if note is not None and (not note.strip() or len(note.encode()) > 500):
|
|
53
|
+
raise ValueError("Use a preference note of 1–500 UTF-8 bytes")
|
|
54
|
+
correction = {"mode": mode, "instruction": INSTRUCTIONS[mode], "note": note}
|
|
55
|
+
text = _canonical(correction | {"operation": operation})
|
|
56
|
+
if expected is None:
|
|
57
|
+
expected = 0
|
|
58
|
+
# Recover the original compare-and-set revision if this operation already committed.
|
|
59
|
+
for event in _preference_history(client):
|
|
60
|
+
data = event["payload"]
|
|
61
|
+
expected = data["revision"]
|
|
62
|
+
if json.loads(data["summary"])["operation"] == operation:
|
|
63
|
+
expected -= 1
|
|
64
|
+
break
|
|
65
|
+
receipt = revise(
|
|
66
|
+
client, PREFERENCE_KIND, client.run, PREFERENCE, expected, text, operation, cause
|
|
67
|
+
)
|
|
68
|
+
return receipt | correction
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def current_preference(client: Client) -> dict:
|
|
72
|
+
"""Return the active correction and the durable event that established it."""
|
|
73
|
+
_validate_run(client)
|
|
74
|
+
preference = {
|
|
75
|
+
"scope": client.run,
|
|
76
|
+
"document": PREFERENCE,
|
|
77
|
+
"revision": 0,
|
|
78
|
+
"event": None,
|
|
79
|
+
"mode": "default",
|
|
80
|
+
"note": None,
|
|
81
|
+
}
|
|
82
|
+
for event in _preference_history(client):
|
|
83
|
+
data = event["payload"]
|
|
84
|
+
correction = json.loads(data["summary"])
|
|
85
|
+
mode = correction["mode"]
|
|
86
|
+
if mode not in INSTRUCTIONS:
|
|
87
|
+
raise ValueError("Invalid experiment evidence-order correction")
|
|
88
|
+
preference.update(
|
|
89
|
+
revision=data["revision"], event=event["seq"], mode=mode, note=correction.get("note")
|
|
90
|
+
)
|
|
91
|
+
return preference
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def recommend_next(client: Client, turn_id: str) -> dict:
|
|
95
|
+
"""Rank a turn's committed public pairs and suggest one bounded next experiment."""
|
|
96
|
+
pairs = [_evidence(event) for event in paired_grade_events(client, turn_id)]
|
|
97
|
+
if not pairs:
|
|
98
|
+
raise ValueError(f"No committed paired grades for turn {turn_id!r}")
|
|
99
|
+
if len({row["seed"] for row in pairs}) != len(pairs):
|
|
100
|
+
raise ValueError(f"Multiple paired grades match a seed for turn {turn_id!r}")
|
|
101
|
+
if len({row["metric"] for row in pairs}) != 1:
|
|
102
|
+
raise ValueError(f"Paired grades use different metrics for turn {turn_id!r}")
|
|
103
|
+
preference = current_preference(client)
|
|
104
|
+
regressions_first = preference["mode"] == "regressions-first"
|
|
105
|
+
ranked = sorted(pairs, key=lambda row: _rank(row, regressions_first))
|
|
106
|
+
experiment = _next_experiment(ranked[0])
|
|
107
|
+
review = {
|
|
108
|
+
"run": client.run,
|
|
109
|
+
"turn": turn_id,
|
|
110
|
+
"preference": preference,
|
|
111
|
+
"evidence": ranked,
|
|
112
|
+
"next_experiment": experiment,
|
|
113
|
+
}
|
|
114
|
+
choice, results = _selection_and_results(client, turn_id)
|
|
115
|
+
return review | {
|
|
116
|
+
"basis": hashlib.sha256(_canonical(review).encode()).hexdigest(),
|
|
117
|
+
"summary": (
|
|
118
|
+
f"{_describe(ranked[0])} {experiment['action']} {_preference_citation(preference)}"
|
|
119
|
+
),
|
|
120
|
+
"choice": choice,
|
|
121
|
+
"results": results,
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def recommendation_lines(report: dict) -> list[str]:
|
|
126
|
+
"""Present the leading evidence, action, active correction and any recorded choice."""
|
|
127
|
+
lines = [_describe(row) for row in report["evidence"][:5]]
|
|
128
|
+
remaining = len(report["evidence"]) - len(lines)
|
|
129
|
+
if remaining:
|
|
130
|
+
lines.append(f"{remaining} more paired seeds.")
|
|
131
|
+
lines.extend(
|
|
132
|
+
(
|
|
133
|
+
report["next_experiment"]["action"],
|
|
134
|
+
_preference_citation(report["preference"]),
|
|
135
|
+
)
|
|
136
|
+
)
|
|
137
|
+
choice = report["choice"]
|
|
138
|
+
if choice is not None:
|
|
139
|
+
lines.append(
|
|
140
|
+
f"Chosen seed {choice['seed']} (event {choice['event']}). {choice['reason']}"
|
|
141
|
+
)
|
|
142
|
+
for result in report.get("results", []):
|
|
143
|
+
experiment = result["experiment"]
|
|
144
|
+
value = experiment["value"]
|
|
145
|
+
measured = "" if value is None else f" · {experiment['metric']} {value:g}"
|
|
146
|
+
lines.append(f"Result #{result['event']} · {experiment['outcome']}{measured}")
|
|
147
|
+
lines.append(experiment["conditions"])
|
|
148
|
+
if experiment["artifact_sha256"]:
|
|
149
|
+
lines.append(f"Evidence SHA-256 {experiment['artifact_sha256']}")
|
|
150
|
+
return lines
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def choose_experiment(
|
|
154
|
+
client: Client,
|
|
155
|
+
turn_id: str,
|
|
156
|
+
seed: int,
|
|
157
|
+
reason: str,
|
|
158
|
+
*,
|
|
159
|
+
operation: str,
|
|
160
|
+
expected_basis: str | None = None,
|
|
161
|
+
) -> dict:
|
|
162
|
+
"""Commit the owner's selected seed with its evidence and preference provenance."""
|
|
163
|
+
_validate_run(client)
|
|
164
|
+
if type(seed) is not int or seed < 0:
|
|
165
|
+
raise ValueError("Use a nonnegative integer seed")
|
|
166
|
+
reason = reason.strip()
|
|
167
|
+
if not reason or len(reason.encode()) > 1000:
|
|
168
|
+
raise ValueError("Use a reason of 1–1000 UTF-8 bytes")
|
|
169
|
+
if not re.fullmatch(r"[A-Za-z0-9_-]{1,96}", operation):
|
|
170
|
+
raise ValueError("Invalid experiment selection operation ID")
|
|
171
|
+
document = DECISION_PREFIX + hashlib.sha256(operation.encode()).hexdigest()
|
|
172
|
+
previous = latest(client, client.run, document)
|
|
173
|
+
if previous is not None:
|
|
174
|
+
choice = json.loads(previous["text"])
|
|
175
|
+
if (choice["turn"], choice["seed"], choice["reason"]) != (turn_id, seed, reason):
|
|
176
|
+
raise ValueError("Experiment selection operation already has different input")
|
|
177
|
+
if choice["expected_basis"] != expected_basis:
|
|
178
|
+
raise ValueError("Experiment selection operation already has a different basis")
|
|
179
|
+
return _selection_result(choice, previous["event"], previous["revision"], document)
|
|
180
|
+
review = recommend_next(client, turn_id)
|
|
181
|
+
if expected_basis is not None and expected_basis != review["basis"]:
|
|
182
|
+
raise ValueError(
|
|
183
|
+
"Experiment evidence or preference changed. Review the recommendation again."
|
|
184
|
+
)
|
|
185
|
+
selected = next((row for row in review["evidence"] if row["seed"] == seed), None)
|
|
186
|
+
if selected is None:
|
|
187
|
+
raise ValueError(f"Seed {seed} has no paired evidence for turn {turn_id!r}")
|
|
188
|
+
# The runtime sends a bounded document preview to the next agent turn.
|
|
189
|
+
# Keep the operator's reason and selected seed ahead of the provenance hashes.
|
|
190
|
+
choice = {"seed": seed, "reason": reason, **_next_experiment(selected)} | {
|
|
191
|
+
"turn": turn_id,
|
|
192
|
+
"evidence": selected,
|
|
193
|
+
"preference": review["preference"],
|
|
194
|
+
"basis": review["basis"],
|
|
195
|
+
"expected_basis": expected_basis,
|
|
196
|
+
}
|
|
197
|
+
receipt = revise(
|
|
198
|
+
client,
|
|
199
|
+
DECISION_KIND,
|
|
200
|
+
client.run,
|
|
201
|
+
document,
|
|
202
|
+
0,
|
|
203
|
+
json.dumps(choice, ensure_ascii=False, separators=(",", ":"), allow_nan=False),
|
|
204
|
+
operation,
|
|
205
|
+
selected["event"],
|
|
206
|
+
)
|
|
207
|
+
return _selection_result(choice, receipt["seq"], receipt["revision"], document)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def _selection_result(choice: dict, event: int, revision: int, document: str) -> dict:
|
|
211
|
+
result = {key: value for key, value in choice.items() if key != "expected_basis"}
|
|
212
|
+
return result | {"event": event, "revision": revision, "document": document}
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def _selection_and_results(
|
|
216
|
+
client: Client, turn_id: str
|
|
217
|
+
) -> tuple[dict | None, list[dict]]:
|
|
218
|
+
selected = None
|
|
219
|
+
results = {}
|
|
220
|
+
for event in events(client):
|
|
221
|
+
data = event["payload"]
|
|
222
|
+
if data.get("scope") != client.run:
|
|
223
|
+
continue
|
|
224
|
+
document = data.get("document", "")
|
|
225
|
+
if event["kind"] == "experiment.trial":
|
|
226
|
+
# A revision can correct a result or move it to another decision.
|
|
227
|
+
results.pop(document, None)
|
|
228
|
+
experiment = data.get("experiment")
|
|
229
|
+
if (
|
|
230
|
+
selected
|
|
231
|
+
and event["cause"] == selected["event"]
|
|
232
|
+
and experiment
|
|
233
|
+
and selected["event"] in experiment["source_events"]
|
|
234
|
+
):
|
|
235
|
+
results[document] = {
|
|
236
|
+
"event": event["seq"],
|
|
237
|
+
"document": document,
|
|
238
|
+
"revision": data["revision"],
|
|
239
|
+
"experiment": experiment,
|
|
240
|
+
}
|
|
241
|
+
continue
|
|
242
|
+
if event["kind"] != DECISION_KIND or not document.startswith(DECISION_PREFIX):
|
|
243
|
+
continue
|
|
244
|
+
choice = json.loads(data["summary"])
|
|
245
|
+
if choice["turn"] == turn_id:
|
|
246
|
+
selected = _selection_result(
|
|
247
|
+
choice, event["seq"], data["revision"], document
|
|
248
|
+
)
|
|
249
|
+
results.clear()
|
|
250
|
+
return selected, list(results.values())
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def _preference_citation(preference: dict) -> str:
|
|
254
|
+
revision = preference["revision"]
|
|
255
|
+
if not revision:
|
|
256
|
+
return "Evidence order follows the investigation default."
|
|
257
|
+
return (
|
|
258
|
+
f"Evidence order follows {preference['mode']}, "
|
|
259
|
+
f"preference revision {revision} (event {preference['event']})."
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def _preference_history(client: Client):
|
|
264
|
+
for event in events(client):
|
|
265
|
+
if event["kind"] != PREFERENCE_KIND:
|
|
266
|
+
continue
|
|
267
|
+
data = event["payload"]
|
|
268
|
+
if data.get("scope") == client.run and data.get("document") == PREFERENCE:
|
|
269
|
+
yield event
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
def _validate_run(client: Client) -> None:
|
|
273
|
+
if client.run == "workspace":
|
|
274
|
+
raise ValueError("Experiment preferences require a named investigation")
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def _canonical(body: dict) -> str:
|
|
278
|
+
return json.dumps(
|
|
279
|
+
body, sort_keys=True, separators=(",", ":"), ensure_ascii=False, allow_nan=False
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def _evidence(event: dict) -> dict:
|
|
284
|
+
pair = event["payload"]["pair"]
|
|
285
|
+
baseline, candidate = pair["baseline"], pair["candidate"]
|
|
286
|
+
delta = None
|
|
287
|
+
if pair["disposition"] == "scored" and baseline is not None and candidate is not None:
|
|
288
|
+
change = candidate - baseline
|
|
289
|
+
if math.isfinite(change):
|
|
290
|
+
delta = change
|
|
291
|
+
return pair | {"event": event["seq"], "delta": delta}
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def _rank(row: dict, regressions_first: bool) -> tuple:
|
|
295
|
+
delta = row["delta"]
|
|
296
|
+
if delta is None:
|
|
297
|
+
return (2, 0, row["seed"], row["event"])
|
|
298
|
+
if regressions_first and delta < 0:
|
|
299
|
+
return (0, delta, row["seed"], row["event"])
|
|
300
|
+
return (1, -abs(delta), row["seed"], row["event"])
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
def _next_experiment(row: dict) -> dict:
|
|
304
|
+
seed = row["seed"]
|
|
305
|
+
delta = row["delta"]
|
|
306
|
+
if delta is None:
|
|
307
|
+
action = f"Restore comparable measurements on public seed {seed}."
|
|
308
|
+
elif delta < 0:
|
|
309
|
+
action = f"Replay public seed {seed} against both policies and inspect their first divergent decision."
|
|
310
|
+
elif delta > 0:
|
|
311
|
+
action = f"Replicate the gain from public seed {seed} on another matched public seed."
|
|
312
|
+
else:
|
|
313
|
+
action = f"Repeat public seed {seed} against both policies to check the tie."
|
|
314
|
+
return {"seed": seed, "action": action, "grade_event": row["event"]}
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def _describe(row: dict) -> str:
|
|
318
|
+
seed, delta = row["seed"], row["delta"]
|
|
319
|
+
if delta is None:
|
|
320
|
+
return f"Seed {seed} has no comparable paired score (event {row['event']})."
|
|
321
|
+
return (
|
|
322
|
+
f"Seed {seed} moved from {row['baseline']:g} to {row['candidate']:g} "
|
|
323
|
+
f"({delta:+g} {row['metric']}, event {row['event']})."
|
|
324
|
+
)
|
synth_code/report.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""Generate a cold research view with durable run and event links."""
|
|
2
|
+
|
|
3
|
+
import html
|
|
4
|
+
import json
|
|
5
|
+
|
|
6
|
+
from . import approvals
|
|
7
|
+
from .panels import comparison
|
|
8
|
+
from .research_events import research_event
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def report(events):
|
|
12
|
+
if not events:
|
|
13
|
+
raise ValueError("empty history")
|
|
14
|
+
events = [research_event(event) for event in events]
|
|
15
|
+
run = events[0]["run"]
|
|
16
|
+
rows = []
|
|
17
|
+
targets: dict[str, str] = {}
|
|
18
|
+
for event in events:
|
|
19
|
+
payload = event["payload"]
|
|
20
|
+
decision = approvals.decision(event, targets)
|
|
21
|
+
body = decision.line() if decision else payload.get("summary")
|
|
22
|
+
if event["kind"] == "experiment.paired_grade":
|
|
23
|
+
pair = payload["pair"]
|
|
24
|
+
score = lambda value: "not scored" if value is None else str(value)
|
|
25
|
+
body = (
|
|
26
|
+
f"Seed {pair['seed']} · {pair['metric']} · {pair['split']} · "
|
|
27
|
+
f"{score(pair['baseline'])} → {score(pair['candidate'])} · {pair['disposition']}"
|
|
28
|
+
)
|
|
29
|
+
body = (
|
|
30
|
+
str(body) if body is not None else json.dumps(payload, ensure_ascii=False)
|
|
31
|
+
)
|
|
32
|
+
refs = {"cause": event["cause"]} | {
|
|
33
|
+
k: payload[k] for k in ("grade", "constraint") if k in payload
|
|
34
|
+
}
|
|
35
|
+
links = " ".join(
|
|
36
|
+
f'<a href="#event-{v}">{k} {v}</a>'
|
|
37
|
+
for k, v in refs.items()
|
|
38
|
+
if type(v) is int and v > 0
|
|
39
|
+
)
|
|
40
|
+
rows.append(
|
|
41
|
+
f'<article id="event-{event["seq"]}"><header>{event["seq"]} · {html.escape(event["kind"])}</header>'
|
|
42
|
+
f"<p>{html.escape(body)}</p>{links}</article>"
|
|
43
|
+
)
|
|
44
|
+
visual = events[-1]["payload"].get("visual")
|
|
45
|
+
if visual == "measurement_status":
|
|
46
|
+
counts = {}
|
|
47
|
+
for e in events:
|
|
48
|
+
if e["kind"] == "experiment.paired_grade":
|
|
49
|
+
state = e["payload"]["pair"]["disposition"]
|
|
50
|
+
counts[state] = counts.get(state, 0) + 1
|
|
51
|
+
overview = (
|
|
52
|
+
"<section><h2>Measurements</h2><dl>"
|
|
53
|
+
+ "".join(
|
|
54
|
+
f"<dt>{html.escape(k)}</dt><dd>{v}</dd>"
|
|
55
|
+
for k, v in sorted(counts.items())
|
|
56
|
+
)
|
|
57
|
+
+ "</dl></section>"
|
|
58
|
+
)
|
|
59
|
+
elif visual == "decision_note":
|
|
60
|
+
chosen = events[-1]["payload"]
|
|
61
|
+
overview = f'<section><h2>Decision</h2><p>{html.escape(str(chosen.get("choice") or "Review recommendation"))}</p><a href="#event-{chosen.get("grade", 0)}">Grade {chosen.get("grade", 0)}</a></section>'
|
|
62
|
+
else:
|
|
63
|
+
overview = comparison(events)
|
|
64
|
+
return (
|
|
65
|
+
'<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width">'
|
|
66
|
+
"<style>body{font:16px system-ui;max-width:62rem;margin:3rem auto;padding:1rem;background:#171614;color:#eee}"
|
|
67
|
+
"table{border-collapse:collapse;font-variant-numeric:tabular-nums}td,th{padding:.35rem .8rem;text-align:left}article{padding:1rem 0;border-top:1px solid #59534d;overflow-wrap:anywhere}header{font:14px monospace}"
|
|
68
|
+
"a{color:#ffac75;margin-right:1em}article:target{border-left:4px solid #fd6600;padding-left:1em}</style>"
|
|
69
|
+
f"<title>Run {html.escape(run)}</title><h1>Run {html.escape(run)}</h1>"
|
|
70
|
+
+ overview
|
|
71
|
+
+ "".join(rows)
|
|
72
|
+
)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Project registered native facts into the product's research readers."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from .protocol import Event
|
|
6
|
+
|
|
7
|
+
__all__ = ["research_event"]
|
|
8
|
+
|
|
9
|
+
# The public journal preserves native source envelopes and sequence numbers.
|
|
10
|
+
# Research readers also support the product kinds written before registration.
|
|
11
|
+
_RESEARCH_KINDS = {
|
|
12
|
+
("artifacts", "artifacts.publication.recorded"): "artifacts.publication",
|
|
13
|
+
("experiment", "experiment.observation.recorded"): "experiment.observation",
|
|
14
|
+
("experiment", "experiment.paired_grade.recorded"): "experiment.paired_grade",
|
|
15
|
+
("research", "research.decision.recorded"): "core.decision",
|
|
16
|
+
("research", "research.panel.revised"): "research.panel.revised",
|
|
17
|
+
("research", "research.policy.selected"): "research.policy.selected",
|
|
18
|
+
("research", "research.recommendation.recorded"): "side.recommendation",
|
|
19
|
+
("tanha", "tanha.constraint.recorded"): "tanha.constraint",
|
|
20
|
+
("tanha", "tanha.constraint.revised"): "tanha.constraint.revised",
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def research_event(event: Event) -> Event:
|
|
25
|
+
if event["kind"] != "source.fact":
|
|
26
|
+
return event
|
|
27
|
+
|
|
28
|
+
envelope = event["payload"]
|
|
29
|
+
dialect, kind = envelope.get("dialect"), envelope.get("kind")
|
|
30
|
+
if not isinstance(dialect, str) or not isinstance(kind, str):
|
|
31
|
+
return event
|
|
32
|
+
if (
|
|
33
|
+
envelope.get("source") != f"native-{dialect}"
|
|
34
|
+
or type(envelope.get("dialect_version")) is not int
|
|
35
|
+
or envelope["dialect_version"] != 1
|
|
36
|
+
):
|
|
37
|
+
return event
|
|
38
|
+
public_kind = _RESEARCH_KINDS.get((dialect, kind))
|
|
39
|
+
if public_kind is None:
|
|
40
|
+
return event
|
|
41
|
+
body = envelope.get("payload")
|
|
42
|
+
if not isinstance(body, dict):
|
|
43
|
+
raise ConnectionError(f"Invalid {kind} payload at event {event['seq']}")
|
|
44
|
+
return {**event, "kind": public_kind, "payload": body}
|