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
synth_code/session.py ADDED
@@ -0,0 +1,291 @@
1
+ """Workspace-bound session bootstrap and operator message operations."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import fcntl
6
+ import hashlib
7
+ import json
8
+ import os
9
+ import subprocess
10
+ import sys
11
+ import time
12
+ from pathlib import Path
13
+ from threading import Event
14
+ from uuid import uuid4
15
+
16
+ from . import edition, native
17
+ from .client import Client, Rejected
18
+
19
+
20
+ def state_for(workspace):
21
+ key = hashlib.sha256(os.fsencode(workspace.resolve(strict=True))).hexdigest()[:16]
22
+ return Path(os.environ.get("XDG_STATE_HOME", Path.home() / ".local/state")) / "synth-code" / key
23
+
24
+
25
+ def daemon_command():
26
+ return [Path(sys.executable).parent / "synth-code-daemon"]
27
+
28
+
29
+ def expected_runtime_sha256(state: Path) -> str:
30
+ """Identity of the runtime ``daemon_command`` launches; a launcher replaces both together."""
31
+ return native.installed_runtime().sha256
32
+
33
+
34
+ class RuntimeIdentityMismatch(Rejected):
35
+ """The daemon serving this state runs different native bytes than the installed runtime."""
36
+
37
+ def __init__(self, state: Path, expected: str, actual: object):
38
+ super().__init__(
39
+ f"runtime_identity_mismatch: daemon for {state} runs {actual}, installed runtime is "
40
+ f"{expected}; stop that daemon after its active work finishes",
41
+ refusal={
42
+ "code": "runtime_identity_mismatch",
43
+ "stage": "attach",
44
+ "retryable": False,
45
+ "failed_check": "daemon_runtime_sha256_matches_installed",
46
+ "expected": expected,
47
+ "actual": actual,
48
+ "ids": {"state": str(state)},
49
+ },
50
+ )
51
+
52
+
53
+ def check_runtime_identity(state: Path, status: dict, expected: str) -> None:
54
+ actual = status.get("runtimeSha256")
55
+ if actual != expected:
56
+ raise RuntimeIdentityMismatch(state, expected, actual)
57
+
58
+
59
+ def connect(client, target, profile):
60
+ target = target.resolve(strict=True)
61
+ client.state.mkdir(mode=0o700, parents=True, exist_ok=True)
62
+ expected_runtime = expected_runtime_sha256(client.state)
63
+
64
+ def describe():
65
+ status = client.send("describe")
66
+ if Path(status["target"]).resolve() != target:
67
+ raise ValueError("State belongs to a different workspace")
68
+ check_runtime_identity(client.state, status, expected_runtime)
69
+
70
+ try:
71
+ describe()
72
+ except (FileNotFoundError, ConnectionRefusedError):
73
+ with (client.state / "daemon.log").open("ab") as log:
74
+ proc = subprocess.Popen(
75
+ [*daemon_command(), client.state, target],
76
+ stdin=subprocess.DEVNULL,
77
+ stdout=log,
78
+ stderr=log,
79
+ start_new_session=True,
80
+ )
81
+ _await_daemon(proc, describe, client.state)
82
+ client.send("start")
83
+ if client.send("snapshot")["profile"] is None:
84
+ client.send("configure", profile=profile)
85
+
86
+
87
+ DAEMON_STARTUP_TIMEOUT_SECONDS = 5.0
88
+ DAEMON_CONNECT_RETRY_SECONDS = 0.05
89
+
90
+
91
+ def _writer_held(state):
92
+ """Report whether a live daemon holds this state's writer lock."""
93
+ try:
94
+ descriptor = os.open(state / "writer.lock", os.O_RDONLY)
95
+ except FileNotFoundError:
96
+ return False
97
+ try:
98
+ fcntl.flock(descriptor, fcntl.LOCK_EX | fcntl.LOCK_NB)
99
+ except BlockingIOError:
100
+ return True
101
+ finally:
102
+ os.close(descriptor)
103
+ return False
104
+
105
+
106
+ def _await_daemon(proc, describe, state):
107
+ """Wait for a freshly spawned daemon to accept connections, or for startup to fail.
108
+
109
+ The daemon publishes no readiness signal, so the socket probe is the only
110
+ readiness source. Between probes the wait blocks on the spawned daemon: its
111
+ exit ends the wait at once unless a sibling daemon (spawned by a concurrent
112
+ client) holds the writer lock and is still starting.
113
+ """
114
+ deadline = time.monotonic() + DAEMON_STARTUP_TIMEOUT_SECONDS
115
+ while True:
116
+ try:
117
+ describe()
118
+ return
119
+ except (FileNotFoundError, ConnectionRefusedError):
120
+ remaining = deadline - time.monotonic()
121
+ if remaining <= 0:
122
+ break
123
+ interval = min(DAEMON_CONNECT_RETRY_SECONDS, remaining)
124
+ if proc.poll() is None:
125
+ try:
126
+ proc.wait(timeout=interval)
127
+ except subprocess.TimeoutExpired:
128
+ pass
129
+ elif _writer_held(state):
130
+ # No handle on the sibling daemon; its socket is the only signal.
131
+ time.sleep(interval)
132
+ else:
133
+ break
134
+ raise RuntimeError(
135
+ f"Daemon startup failed, exit {proc.poll()}. See {state / 'daemon.log'}"
136
+ )
137
+
138
+
139
+ _SAVED_ROLE_NAMES = {"horst": "core", "hengis": "side"}
140
+
141
+
142
+ def saved_role(role):
143
+ return _SAVED_ROLE_NAMES.get(role, role)
144
+
145
+
146
+ def saved_profile(config):
147
+ # Cold journal reads preserve the exact bytes of older profile revisions.
148
+ profile = json.loads(config)
149
+ for old, current in _SAVED_ROLE_NAMES.items():
150
+ if old in profile:
151
+ profile.setdefault(current, profile.pop(old))
152
+ return profile
153
+
154
+
155
+ def starter():
156
+ return json.loads(Path(__file__).with_name("starter.json").read_text())
157
+
158
+
159
+ USER_MESSAGE_BYTES_MAX = 2048
160
+ INPUT_COMPLETION_TIMEOUT_SECONDS = 910
161
+
162
+
163
+ def validate_message(text):
164
+ """Apply the runtime's user message size limit before submission."""
165
+ if not text.strip():
166
+ raise ValueError("Empty message")
167
+ size = len(text.encode("utf-8"))
168
+ if size > USER_MESSAGE_BYTES_MAX:
169
+ raise ValueError(f"Message is {size} UTF-8 bytes. Maximum is {USER_MESSAGE_BYTES_MAX}.")
170
+
171
+
172
+ def message(
173
+ client: Client, role: str, text: str, identity: str | None = None, *, cause: int | None = None
174
+ ) -> dict:
175
+ role = {"agent": "core", "side-agent": "side"}.get(role, role)
176
+ if role == "side" and not edition.feature_available(edition.Feature.MULTI_AGENT):
177
+ raise edition.EditionUnavailable(edition.Feature.MULTI_AGENT)
178
+ identity = identity or uuid4().hex
179
+ validate_message(text)
180
+ origin = {"cause_seq": cause} if cause is not None else {}
181
+ receipt = client.send(
182
+ "submit_input", id=identity, target=role, parts=[{"type": "text", "text": text}], **origin
183
+ )
184
+ return _await_input_result(client, identity, receipt["seq"])
185
+
186
+
187
+ def _await_input_result(client: Client, identity: str, after: int) -> dict:
188
+ result = _input_result(client, identity)
189
+ if result is not None:
190
+ return result
191
+
192
+ ready = Event()
193
+ deadline = time.monotonic() + INPUT_COMPLETION_TIMEOUT_SECONDS
194
+ # A side-agent command can share the terminal's Client, which already
195
+ # owns its subscription. A separate socket keeps both subscriptions live.
196
+ with (
197
+ Client(client.state, client.run, client.version) as listener,
198
+ listener.subscribe(after=after, wake=ready.set) as changes,
199
+ ):
200
+ while time.monotonic() < deadline:
201
+ ready.clear()
202
+ for frame in changes.drain():
203
+ if frame["type"] == "refused":
204
+ raise frame["error"]
205
+ if frame["type"] != "event":
206
+ continue
207
+ event = frame["event"]
208
+ completed = event["kind"] == "turn.finished" and event["turn"] == identity
209
+ refused = (
210
+ event["kind"] in {"input.withdrawn", "input.not_delivered", "input.quarantined"}
211
+ and event["payload"]["id"] == identity
212
+ )
213
+ if completed or refused:
214
+ result = _input_result(client, identity)
215
+ if result is None:
216
+ raise ConnectionError(f"Committed input {identity} has no terminal receipt")
217
+ return result
218
+ ready.wait(max(0, deadline - time.monotonic()))
219
+ result = _input_result(client, identity)
220
+ if result is not None:
221
+ return result
222
+ raise TimeoutError(
223
+ f"Input {identity} is pending after {INPUT_COMPLETION_TIMEOUT_SECONDS} seconds"
224
+ )
225
+
226
+
227
+ def _input_result(client: Client, identity: str) -> dict | None:
228
+ receipt = client.send("get_input_result", id=identity)
229
+ disposition = receipt["input"]
230
+ if disposition["status"] in {"withdrawn", "not_delivered", "quarantined"}:
231
+ status = disposition["status"]
232
+ raise Rejected(
233
+ f"Input {identity} {status}",
234
+ refusal={
235
+ "code": f"input_{status}",
236
+ "stage": "admission",
237
+ "retryable": False,
238
+ "failed_check": "input_admitted_or_pending",
239
+ "expected": "admitted_or_pending",
240
+ "actual": status,
241
+ "ids": {"run": client.run, "input": identity},
242
+ },
243
+ )
244
+ return receipt["result"]
245
+
246
+
247
+ def edit(client, identity, name, instruction, *, create=False, expected=None, cause=1):
248
+ """Propose a single explicitly selected target from Core's returned file text."""
249
+ if not instruction.strip() or len(instruction.encode()) > 1000:
250
+ raise ValueError("Use an edit instruction of 1–1000 bytes")
251
+ # Bind a retry to the originally admitted file and bytes, including after it changed.
252
+ claim = client.send(
253
+ "edit_request",
254
+ id=identity,
255
+ name=name,
256
+ instruction=instruction,
257
+ create=create,
258
+ expected=expected,
259
+ cause=cause,
260
+ )
261
+ turn = client.send("turn", id=identity, role="core", cause=claim["seq"])
262
+ if not turn.get("messages"):
263
+ return turn
264
+ if turn.get("proposal_error"):
265
+ raise ValueError(turn["proposal_error"])
266
+ proposal = client.send("preview", effect=identity)
267
+ if proposal["digest"] != turn["proposal"]["digest"]:
268
+ raise ValueError("Edit proposal identity changed")
269
+ return {k: proposal[k] for k in ("effect", "name", "content", "digest", "phase")} | {
270
+ "before": claim["before"]
271
+ }
272
+
273
+
274
+ def revise(client, kind, scope, key, expected, text, operation=None, cause=1):
275
+ return client.send(
276
+ "revise",
277
+ edit={
278
+ "kind": kind,
279
+ "scope": scope,
280
+ "id": key,
281
+ "expected": expected,
282
+ "text": text,
283
+ "operation": operation or uuid4().hex,
284
+ "cause": cause,
285
+ },
286
+ )
287
+
288
+
289
+ def latest(client, scope, key):
290
+ rows = client.send("documents", scope=scope, id=key)
291
+ return rows[0] if rows else None