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.
Files changed (110) hide show
  1. synth_code/__init__.py +0 -0
  2. synth_code/account.py +551 -0
  3. synth_code/account_http.py +86 -0
  4. synth_code/account_refusal.py +80 -0
  5. synth_code/accounting.py +148 -0
  6. synth_code/activity_grouping.py +149 -0
  7. synth_code/agent_panels.py +127 -0
  8. synth_code/approvals.py +397 -0
  9. synth_code/blobs.py +31 -0
  10. synth_code/cli.py +734 -0
  11. synth_code/client.py +413 -0
  12. synth_code/composer_delivery.py +139 -0
  13. synth_code/conversation.py +949 -0
  14. synth_code/daemon.py +34 -0
  15. synth_code/edition.py +306 -0
  16. synth_code/enrollment.py +304 -0
  17. synth_code/file_edit_facts.py +10 -0
  18. synth_code/freeze.py +234 -0
  19. synth_code/grant.py +59 -0
  20. synth_code/history.py +140 -0
  21. synth_code/history_generated.py +219 -0
  22. synth_code/history_wire.py +166 -0
  23. synth_code/image_input.py +109 -0
  24. synth_code/image_preview.py +105 -0
  25. synth_code/legacy_history.py +161 -0
  26. synth_code/live_turns.py +171 -0
  27. synth_code/model_picker.py +311 -0
  28. synth_code/native/manifest.json +1 -0
  29. synth_code/native/synth-code-runtime +0 -0
  30. synth_code/native.py +95 -0
  31. synth_code/oauth.py +284 -0
  32. synth_code/operator.py +116 -0
  33. synth_code/pack_source.py +65 -0
  34. synth_code/panel_request.py +291 -0
  35. synth_code/panels.py +40 -0
  36. synth_code/plugin_host.py +459 -0
  37. synth_code/protocol.py +35 -0
  38. synth_code/provider.py +313 -0
  39. synth_code/provider_fault.py +173 -0
  40. synth_code/provider_frames.py +571 -0
  41. synth_code/recommendation.py +324 -0
  42. synth_code/report.py +72 -0
  43. synth_code/research_events.py +44 -0
  44. synth_code/research_trace.py +449 -0
  45. synth_code/rex_view.py +58 -0
  46. synth_code/runtime_refusal.py +108 -0
  47. synth_code/schema/budgets.json +17 -0
  48. synth_code/schema/history-v2.json +1002 -0
  49. synth_code/session.py +291 -0
  50. synth_code/shoal.py +564 -0
  51. synth_code/side_panel.py +309 -0
  52. synth_code/skills.py +269 -0
  53. synth_code/slash.py +425 -0
  54. synth_code/source_view.py +135 -0
  55. synth_code/starter.json +13 -0
  56. synth_code/stdio.py +75 -0
  57. synth_code/stream.py +142 -0
  58. synth_code/subscriptions.py +267 -0
  59. synth_code/synth_authority.py +362 -0
  60. synth_code/synth_extra.py +32 -0
  61. synth_code/terminal.py +817 -0
  62. synth_code/terminal_journal.py +284 -0
  63. synth_code/terminal_layout.py +643 -0
  64. synth_code/terminal_surfaces.py +470 -0
  65. synth_code/terminal_viewport.py +125 -0
  66. synth_code/tool_render.py +86 -0
  67. synth_code/transcript_frames.py +212 -0
  68. synth_code/transcript_placement.py +63 -0
  69. synth_code/transcript_rows.py +456 -0
  70. synth_code/transport.py +243 -0
  71. synth_code/v001_history.py +468 -0
  72. synth_code/view.py +854 -0
  73. synth_code/views/__init__.py +93 -0
  74. synth_code/views/charts.py +196 -0
  75. synth_code/views/curses_adapter.py +116 -0
  76. synth_code/views/engine.py +170 -0
  77. synth_code/views/model.py +226 -0
  78. synth_code/views/primitives.py +270 -0
  79. synth_code/views/tiling.py +124 -0
  80. synth_code-0.0.1.dist-info/METADATA +50 -0
  81. synth_code-0.0.1.dist-info/RECORD +110 -0
  82. synth_code-0.0.1.dist-info/WHEEL +5 -0
  83. synth_code-0.0.1.dist-info/entry_points.txt +6 -0
  84. synth_code-0.0.1.dist-info/licenses/temper/LICENSE-APACHE +190 -0
  85. synth_code-0.0.1.dist-info/licenses/temper/LICENSE-MIT +21 -0
  86. synth_code-0.0.1.dist-info/licenses/temper/SOURCE.json +433 -0
  87. synth_code-0.0.1.dist-info/top_level.txt +2 -0
  88. synth_code_plugins/_sdk/__init__.py +19 -0
  89. synth_code_plugins/_sdk/callback_wire.py +240 -0
  90. synth_code_plugins/_sdk/callbacks.py +317 -0
  91. synth_code_plugins/_sdk/compliance.py +51 -0
  92. synth_code_plugins/_sdk/contracts.py +236 -0
  93. synth_code_plugins/_sdk/discovery.py +75 -0
  94. synth_code_plugins/_sdk/job_binding.py +71 -0
  95. synth_code_plugins/_sdk/lifecycle.py +50 -0
  96. synth_code_plugins/_sdk/lifecycle_generated.py +15 -0
  97. synth_code_plugins/_sdk/manifest.py +269 -0
  98. synth_code_plugins/_sdk/pack.py +332 -0
  99. synth_code_plugins/_sdk/push.py +98 -0
  100. synth_code_plugins/_sdk/records.py +26 -0
  101. synth_code_plugins/_sdk/registry.py +491 -0
  102. synth_code_plugins/_sdk/schemas.py +210 -0
  103. synth_code_plugins/_sdk/sources.py +230 -0
  104. synth_code_plugins/_sdk/surfaces.py +54 -0
  105. synth_code_plugins/_sdk/tools.py +172 -0
  106. synth_code_plugins/_sdk/worker_memory.py +49 -0
  107. synth_code_plugins/core/SKILL.md +6 -0
  108. synth_code_plugins/core/__init__.py +21 -0
  109. synth_code_plugins/core/plugin.toml +44 -0
  110. synth_code_plugins/core/source.py +18 -0
@@ -0,0 +1,291 @@
1
+ """Run-scoped requests for the owner terminal."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import errno
7
+ import fcntl
8
+ import json
9
+ import os
10
+ import re
11
+ import stat
12
+ import sys
13
+ from collections.abc import Callable
14
+ from contextlib import contextmanager
15
+ from dataclasses import dataclass
16
+ from pathlib import Path
17
+ from tempfile import NamedTemporaryFile
18
+
19
+ from .client import Client
20
+
21
+ TOOL = "open_side_agent_panel"
22
+ HIDE_MONITOR = "hide_monitor"
23
+ STATE_ENV = "SYNTH_CODE_PANEL_STATE"
24
+ _PROTOCOLS = {"2024-11-05", "2025-03-26", "2025-06-18", "2025-11-25"}
25
+ _FRAME_LIMIT = 16384
26
+
27
+
28
+ class PanelUnavailable(ValueError):
29
+ """The attachment can read history, but cannot host a private view signal."""
30
+
31
+
32
+ def _paths(state, run):
33
+ if not re.fullmatch(r"[A-Za-z0-9_-]{1,96}", run):
34
+ raise ValueError("Invalid panel request run")
35
+ if state.is_symlink() or not state.is_dir() or state.stat().st_mode & 0o077:
36
+ raise PanelUnavailable("Panel requests require a private state directory")
37
+ directory = state / "panel-requests"
38
+ directory.mkdir(mode=0o700, exist_ok=True)
39
+ if directory.is_symlink() or directory.stat().st_mode & 0o077:
40
+ raise PanelUnavailable("Panel requests require a private signal directory")
41
+ return tuple(
42
+ directory / f"{run}.{suffix}" for suffix in ("guard", "lease", "pending")
43
+ )
44
+
45
+
46
+ @contextmanager
47
+ def _guard(path):
48
+ with os.fdopen(
49
+ os.open(path, os.O_CREAT | os.O_RDWR | os.O_NOFOLLOW, 0o600), "rb"
50
+ ) as guard:
51
+ fcntl.flock(guard, fcntl.LOCK_EX)
52
+ yield
53
+
54
+
55
+ def _consume(path):
56
+ try:
57
+ path.unlink()
58
+ except FileNotFoundError:
59
+ return False
60
+ return True
61
+
62
+
63
+ def _signal(path):
64
+ try:
65
+ descriptor = os.open(path, os.O_WRONLY | os.O_NONBLOCK | os.O_NOFOLLOW)
66
+ except OSError as error:
67
+ if error.errno in (errno.ENOENT, errno.ENXIO):
68
+ return
69
+ raise
70
+ with os.fdopen(descriptor, "wb", buffering=0) as signal:
71
+ if not stat.S_ISFIFO(os.fstat(descriptor).st_mode):
72
+ raise PanelUnavailable("Panel wakeup must be a FIFO")
73
+ try:
74
+ signal.write(b"w")
75
+ except (BlockingIOError, BrokenPipeError):
76
+ pass # A full FIFO is already readable, or the terminal detached.
77
+
78
+
79
+ @dataclass(frozen=True, slots=True)
80
+ class PanelRequests:
81
+ take: Callable[[], bool]
82
+ wake_fd: int | None = None
83
+
84
+ def __call__(self) -> bool:
85
+ return self.take()
86
+
87
+
88
+ @contextmanager
89
+ def panel_requests(client):
90
+ """Yield the request reader and its selectable owner wakeup descriptor."""
91
+ if client.viewer is not None:
92
+ yield PanelRequests(lambda: False)
93
+ return
94
+ try:
95
+ guard, lease, pending = _paths(client.state, client.run)
96
+ descriptor = os.open(lease, os.O_CREAT | os.O_RDWR | os.O_NOFOLLOW, 0o600)
97
+ except (PanelUnavailable, PermissionError):
98
+ yield PanelRequests(lambda: False)
99
+ return
100
+ with os.fdopen(descriptor, "rb") as attachment:
101
+ with _guard(guard):
102
+ try:
103
+ fcntl.flock(attachment, fcntl.LOCK_EX | fcntl.LOCK_NB)
104
+ except BlockingIOError:
105
+ active = False
106
+ else:
107
+ _consume(pending)
108
+ wake_path = guard.with_suffix(".wake")
109
+ try:
110
+ os.mkfifo(wake_path, 0o600)
111
+ except FileExistsError:
112
+ pass
113
+ wake_fd = os.open(wake_path, os.O_RDWR | os.O_NONBLOCK | os.O_NOFOLLOW)
114
+ if not stat.S_ISFIFO(os.fstat(wake_fd).st_mode):
115
+ os.close(wake_fd)
116
+ raise PanelUnavailable("Panel wakeup must be a FIFO")
117
+ active = True
118
+ if not active:
119
+ yield PanelRequests(lambda: False)
120
+ return
121
+
122
+ def poll():
123
+ with _guard(guard):
124
+ if not active:
125
+ return False
126
+ try:
127
+ while os.read(wake_fd, 256):
128
+ pass
129
+ except BlockingIOError:
130
+ pass
131
+ return _consume(pending)
132
+
133
+ try:
134
+ yield PanelRequests(poll, wake_fd)
135
+ finally:
136
+ with _guard(guard):
137
+ active = False
138
+ _consume(pending)
139
+ os.close(wake_fd)
140
+ fcntl.flock(attachment, fcntl.LOCK_UN)
141
+
142
+
143
+ def request_panel(state: Path, run: str) -> bool:
144
+ """Queue one open request for an already attached owner terminal."""
145
+ guard, lease, pending = _paths(state, run)
146
+ with _guard(guard):
147
+ try:
148
+ descriptor = os.open(lease, os.O_RDONLY | os.O_NOFOLLOW)
149
+ except FileNotFoundError:
150
+ return False
151
+ with os.fdopen(descriptor, "rb") as attachment:
152
+ try:
153
+ fcntl.flock(attachment, fcntl.LOCK_EX | fcntl.LOCK_NB)
154
+ except BlockingIOError:
155
+ pass
156
+ else:
157
+ return False
158
+ # The empty signal appears atomically. Repeated opens coalesce.
159
+ try:
160
+ descriptor = os.open(pending, os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o600)
161
+ except FileExistsError:
162
+ pass
163
+ else:
164
+ os.close(descriptor)
165
+ _signal(guard.with_suffix(".wake"))
166
+ return True
167
+
168
+
169
+ def hide_completed_monitor(state, run):
170
+ """Hide the settled monitor in the owner view at its recorded cursor."""
171
+ guard, _, _ = _paths(state, run)
172
+ marker = guard.with_suffix(".monitor-hidden")
173
+ with _guard(guard), Client(state, run) as client:
174
+ snapshot = client.send("snapshot")
175
+ event = snapshot["workflow_event"]
176
+ if event is None or event["payload"]["status"] is None:
177
+ return "No monitor is pinned.", False
178
+ if snapshot["workflow_settled"] is not True:
179
+ return "The monitor is still active.", True
180
+ with NamedTemporaryFile(mode="w", dir=marker.parent, delete=False) as pending:
181
+ temporary = Path(pending.name)
182
+ try:
183
+ pending.write(str(event["seq"]))
184
+ pending.close()
185
+ temporary.replace(marker)
186
+ finally:
187
+ temporary.unlink(missing_ok=True)
188
+ _signal(guard.with_suffix(".wake"))
189
+ return "Monitor hidden.", False
190
+
191
+
192
+ def visible_monitor(client, monitor):
193
+ if monitor is None or client.viewer is not None:
194
+ return monitor
195
+ marker = client.state / "panel-requests" / f"{client.run}.monitor-hidden"
196
+ try:
197
+ descriptor = os.open(marker, os.O_RDONLY | os.O_NOFOLLOW)
198
+ except FileNotFoundError:
199
+ return monitor
200
+ with os.fdopen(descriptor, "rb") as record:
201
+ return None if record.read(32) == str(monitor["seq"]).encode("ascii") else monitor
202
+
203
+
204
+ def _mcp_reply(request, state, run, *, hide_monitor=False):
205
+ method = request["method"]
206
+ params = request.get("params", {})
207
+ if method == "initialize":
208
+ protocol = params.get("protocolVersion")
209
+ return {
210
+ "protocolVersion": protocol if protocol in _PROTOCOLS else "2025-11-25",
211
+ "capabilities": {"tools": {}},
212
+ "serverInfo": {"name": "synth-view", "version": "0.0.1"},
213
+ }
214
+ if method == "ping":
215
+ return {}
216
+ if method == "tools/list":
217
+ schema = {"type": "object", "properties": {}, "additionalProperties": False}
218
+ tools = [
219
+ {
220
+ "name": TOOL,
221
+ "description": "Request opening the side-agent panel in the user's attached terminal for this run.",
222
+ "inputSchema": schema,
223
+ }
224
+ ]
225
+ if hide_monitor:
226
+ tools.append(
227
+ {
228
+ "name": HIDE_MONITOR,
229
+ "description": "Hide the completed monitor above the input in the owner terminal.",
230
+ "inputSchema": schema,
231
+ }
232
+ )
233
+ return {"tools": tools}
234
+ if method == "tools/call":
235
+ if (
236
+ hide_monitor
237
+ and params.get("name") == HIDE_MONITOR
238
+ and params.get("arguments", {}) == {}
239
+ ):
240
+ message, failed = hide_completed_monitor(state, run)
241
+ return {"content": [{"type": "text", "text": message}], "isError": failed}
242
+ if params.get("name") != TOOL or params.get("arguments", {}) != {}:
243
+ raise ValueError("Unknown tool or arguments")
244
+ queued = request_panel(state, run)
245
+ return {
246
+ "content": [
247
+ {
248
+ "type": "text",
249
+ "text": "Side-agent panel requested."
250
+ if queued
251
+ else "No terminal is attached to this run.",
252
+ }
253
+ ],
254
+ "isError": not queued,
255
+ }
256
+ raise LookupError("Method not found")
257
+
258
+
259
+ def main():
260
+ parser = argparse.ArgumentParser()
261
+ parser.add_argument("--hide-monitor", action="store_true")
262
+ parser.add_argument("state", type=Path)
263
+ parser.add_argument("run")
264
+ args = parser.parse_args()
265
+ while raw := sys.stdin.buffer.readline(_FRAME_LIMIT + 1):
266
+ if len(raw) > _FRAME_LIMIT:
267
+ raise ValueError("MCP request exceeds frame limit")
268
+ identity = None
269
+ try:
270
+ request = json.loads(raw)
271
+ if not isinstance(request, dict) or request.get("jsonrpc") != "2.0":
272
+ raise ValueError("Invalid JSON-RPC request")
273
+ if "id" not in request:
274
+ continue
275
+ identity = request["id"]
276
+ reply = {
277
+ "result": _mcp_reply(
278
+ request, args.state, args.run, hide_monitor=args.hide_monitor
279
+ )
280
+ }
281
+ except LookupError as error:
282
+ reply = {"error": {"code": -32601, "message": str(error)}}
283
+ except (ValueError, TypeError, AttributeError) as error:
284
+ reply = {"error": {"code": -32602, "message": str(error)}}
285
+ except OSError:
286
+ reply = {"error": {"code": -32603, "message": "Terminal request failed"}}
287
+ print(json.dumps({"jsonrpc": "2.0", "id": identity, **reply}), flush=True)
288
+
289
+
290
+ if __name__ == "__main__":
291
+ main()
synth_code/panels.py ADDED
@@ -0,0 +1,40 @@
1
+ """Accessible paired-seed view shared by local and hosted HTML artifacts."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from html import escape
6
+
7
+ from .research_events import research_event
8
+
9
+
10
+ def score(value):
11
+ return "not scored" if value is None else f"{value:g}"
12
+
13
+
14
+ def comparison(events):
15
+ groups = {}
16
+ for raw in events:
17
+ event = research_event(raw)
18
+ if event["kind"] == "experiment.paired_grade":
19
+ pair = event["payload"]["pair"]
20
+ key = tuple(
21
+ pair[k] for k in ("metric", "split", "baseline_hash", "candidate_hash")
22
+ )
23
+ groups.setdefault(key, {})[pair["seed"]] = (pair, event["seq"])
24
+ result = []
25
+ for (metric, split, baseline, candidate), rows in groups.items():
26
+ matched = [
27
+ p["candidate"] - p["baseline"]
28
+ for p, _ in rows.values()
29
+ if p["candidate"] is not None and p["baseline"] is not None
30
+ ]
31
+ delta = f"{sum(matched) / len(matched):+.2f}" if matched else "not scored"
32
+ result.append(
33
+ f"<section><h2>{escape(metric)} · {escape(split)}</h2><p>{len(matched)} / {len(rows)} paired · mean change {delta}</p><details><summary>Policies</summary><p>{escape(baseline)} → {escape(candidate)}</p></details><table><thead><tr><th>Seed</th><th>Baseline</th><th>Candidate</th><th>Outcome</th></tr></thead><tbody>"
34
+ )
35
+ for seed, (pair, seq) in sorted(rows.items()):
36
+ result.append(
37
+ f'<tr><td><a href="#event-{seq}">{seed}</a></td><td>{score(pair["baseline"])}</td><td>{score(pair["candidate"])}</td><td>{escape(pair["disposition"])}</td></tr>'
38
+ )
39
+ result.append("</tbody></table></section>")
40
+ return "".join(result)