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
synth_code/slash.py
ADDED
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
"""Command discovery and local journal overlays for the attached terminal."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
8
|
+
|
|
9
|
+
from .client import Client, Rejected
|
|
10
|
+
from .edition import AutoApproveUnavailable, Edition, auto_approve_available, command_available
|
|
11
|
+
from .history_wire import input_text, message_text
|
|
12
|
+
from . import approvals, history
|
|
13
|
+
from .operator import format_preview
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"Command",
|
|
17
|
+
"compact",
|
|
18
|
+
"composition_result",
|
|
19
|
+
"menu",
|
|
20
|
+
"overlay",
|
|
21
|
+
"public_role",
|
|
22
|
+
"resolve",
|
|
23
|
+
"resume_menu",
|
|
24
|
+
"run_names",
|
|
25
|
+
"settings_apply",
|
|
26
|
+
"study_result",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass(frozen=True, slots=True)
|
|
31
|
+
class _Spec:
|
|
32
|
+
name: str
|
|
33
|
+
arguments: str
|
|
34
|
+
description: str
|
|
35
|
+
aliases: tuple[str, ...] = ()
|
|
36
|
+
# Arguments the single-agent public edition offers, where they differ from beta's.
|
|
37
|
+
public_arguments: str | None = None
|
|
38
|
+
|
|
39
|
+
def usage(self, name: str, edition: Edition = Edition.BETA) -> str:
|
|
40
|
+
arguments = self.arguments
|
|
41
|
+
if edition is Edition.PUBLIC and self.public_arguments is not None:
|
|
42
|
+
arguments = self.public_arguments
|
|
43
|
+
return f"/{name} {arguments}" if arguments else f"/{name}"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
_COMMANDS = (
|
|
47
|
+
_Spec("help", "", "Show commands", ("commands", "?")),
|
|
48
|
+
_Spec("exit", "", "Detach from this run", ("quit", "detach")),
|
|
49
|
+
_Spec("status", "", "Show run phase and journal cursor"),
|
|
50
|
+
_Spec("model", "[AGENT [MODEL [EFFORT]]]", "Choose a model for a live agent"),
|
|
51
|
+
_Spec(
|
|
52
|
+
"service-tier",
|
|
53
|
+
"[standard|fast|ultrafast]",
|
|
54
|
+
"Choose the active model's service tier",
|
|
55
|
+
),
|
|
56
|
+
_Spec(
|
|
57
|
+
"permissions",
|
|
58
|
+
"[manual|yolo]",
|
|
59
|
+
"Inspect or set workspace permissions",
|
|
60
|
+
("mode",),
|
|
61
|
+
),
|
|
62
|
+
_Spec("yolo", "", "Allow workspace writes for the core agent"),
|
|
63
|
+
_Spec("providers", "[set PROVIDER ROLE]", "Inspect accounts and assign providers"),
|
|
64
|
+
_Spec("login", "[status|synth|synth device]", "Check or connect your Synth account"),
|
|
65
|
+
_Spec("layout", "[ACTION]", "Manage mounted views"),
|
|
66
|
+
_Spec("subagents", "[open|close]", "Inspect delegated agents"),
|
|
67
|
+
_Spec("sideagents", "[open|close]", "Show or hide side agents", ("side",)),
|
|
68
|
+
_Spec("mcp", "[side]", "Open the side-agent panel"),
|
|
69
|
+
_Spec("sidebar", "", "Toggle the side-agent Temper inspector"),
|
|
70
|
+
_Spec("agents", "", "Show agents and delegated work"),
|
|
71
|
+
_Spec("context", "", "Show the active profile and latest checkpoint"),
|
|
72
|
+
_Spec("compact", "", "Checkpoint recent conversation excerpts"),
|
|
73
|
+
_Spec("settings-apply", "[ROLE]", "Apply a queued model change now"),
|
|
74
|
+
_Spec("version", "", "Show the installed Synth Code version"),
|
|
75
|
+
_Spec("new", "[RUN]", "Open a new run", ("clear",)),
|
|
76
|
+
_Spec("resume", "[RUN]", "List or open recorded runs"),
|
|
77
|
+
_Spec("trace", "", "Open the journal timeline"),
|
|
78
|
+
_Spec("back", "", "Return to the conversation"),
|
|
79
|
+
_Spec("diff", "[EFFECT]", "Review a pending edit"),
|
|
80
|
+
_Spec("event", "SEQ", "Inspect a journal event"),
|
|
81
|
+
_Spec("cause", "", "Inspect the selected event’s cause"),
|
|
82
|
+
_Spec("grade", "", "Inspect the selected panel’s grade"),
|
|
83
|
+
_Spec("constraint", "", "Inspect the selected panel’s constraint"),
|
|
84
|
+
_Spec("explain", "TURN [--seed SEED]", "Trace a turn or paired seed"),
|
|
85
|
+
_Spec("recommend", "TURN", "Rank paired evidence and suggest an experiment"),
|
|
86
|
+
_Spec("preference", "[MODE] [--note TEXT]", "Show or revise evidence order"),
|
|
87
|
+
_Spec("choose", "TURN SEED REASON", "Record the next experiment"),
|
|
88
|
+
_Spec("study", "SPEC STAGE [ROUND]", "Seed, propose, or grade a study"),
|
|
89
|
+
_Spec("trial", "", "Compare public evidence"),
|
|
90
|
+
_Spec("panel", "SEQ", "Open a decision panel"),
|
|
91
|
+
_Spec("ask", "agent|side-agent MESSAGE", "Ask a role", public_arguments="agent MESSAGE"),
|
|
92
|
+
_Spec("edit", "FILE REQUEST", "Propose a file edit"),
|
|
93
|
+
_Spec("create", "FILE REQUEST", "Propose a new file"),
|
|
94
|
+
_Spec("review", "EFFECT", "Inspect an edit receipt"),
|
|
95
|
+
_Spec("approve", "[EFFECT] [DIGEST]", "Approve and apply a matching edit"),
|
|
96
|
+
_Spec("deny", "[EFFECT] [DIGEST]", "Deny a matching edit"),
|
|
97
|
+
_Spec("approvals", "", "List pending approvals and recent decisions"),
|
|
98
|
+
_Spec("steer", "[TURN] MESSAGE", "Steer the current turn"),
|
|
99
|
+
_Spec("cancel", "[TURN]", "Cancel the current turn"),
|
|
100
|
+
_Spec("checkpoint", "SEQ SUMMARY", "Record a context checkpoint"),
|
|
101
|
+
_Spec("composition", "", "Show active capabilities"),
|
|
102
|
+
_Spec("skills", "[ACTION [NAME]]", "List or configure skills"),
|
|
103
|
+
_Spec("note", "KIND SCOPE ID REVISION TEXT", "Revise a document"),
|
|
104
|
+
_Spec("profile", "FILE", "Load a profile"),
|
|
105
|
+
_Spec("publish", "NOTEBOOK SEQ", "Publish a notebook at a journal cursor"),
|
|
106
|
+
)
|
|
107
|
+
_LOOKUP = {name: spec for spec in _COMMANDS for name in (spec.name, *spec.aliases)}
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
@dataclass(frozen=True, slots=True)
|
|
111
|
+
class Command:
|
|
112
|
+
name: str
|
|
113
|
+
rest: str
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def resolve(draft: str, edition: Edition = Edition.BETA) -> Command:
|
|
117
|
+
"""Resolve a slash spelling to its canonical command and argument text."""
|
|
118
|
+
words = draft.split(maxsplit=1)
|
|
119
|
+
if not words or not words[0].startswith("/"):
|
|
120
|
+
raise ValueError("Expected a slash command")
|
|
121
|
+
token = words[0][1:]
|
|
122
|
+
spec = _LOOKUP.get(token)
|
|
123
|
+
if spec is None or not command_available(spec.name, edition):
|
|
124
|
+
raise ValueError(f"Unknown command /{token}. See /help.")
|
|
125
|
+
rest = words[1].strip() if len(words) == 2 else ""
|
|
126
|
+
if rest and not spec.arguments:
|
|
127
|
+
raise ValueError(f"Usage: {spec.usage(spec.name, edition)}")
|
|
128
|
+
if spec.name == "event":
|
|
129
|
+
if not (rest.isascii() and rest.isdecimal()):
|
|
130
|
+
raise ValueError(f"Usage: {spec.usage(spec.name, edition)}")
|
|
131
|
+
if not rest.lstrip("0"):
|
|
132
|
+
raise ValueError("Event sequence must be positive")
|
|
133
|
+
if spec.name in ("new", "resume") and rest and not _identifier(rest):
|
|
134
|
+
raise ValueError(f"Usage: {spec.usage(spec.name, edition)}")
|
|
135
|
+
return Command(spec.name, rest)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def composition_result(receipt: dict) -> str:
|
|
139
|
+
plugins = ", ".join(plugin["name"] for plugin in receipt["plugins"])
|
|
140
|
+
capabilities = [
|
|
141
|
+
f"{item['name']} {item['major']}.{item['minor']}" for item in receipt["capabilities"]
|
|
142
|
+
]
|
|
143
|
+
return "\n".join(
|
|
144
|
+
[
|
|
145
|
+
"Active composition",
|
|
146
|
+
f"Profile {receipt['profile'] or 'None'}",
|
|
147
|
+
f"Plugins {plugins or 'None'}",
|
|
148
|
+
"Capabilities",
|
|
149
|
+
*(capabilities or ["None"]),
|
|
150
|
+
]
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def study_result(receipt: dict) -> str:
|
|
155
|
+
if "measured" in receipt:
|
|
156
|
+
grade = receipt["measured"]
|
|
157
|
+
title = f"Study baseline · {receipt['game']} · {receipt['split']}"
|
|
158
|
+
evidence = [
|
|
159
|
+
f"Policy {receipt['policy_sha256']}",
|
|
160
|
+
f"Summary {receipt['summary_sha256']}",
|
|
161
|
+
]
|
|
162
|
+
else:
|
|
163
|
+
grade = receipt["grade"]
|
|
164
|
+
title = "Study grade"
|
|
165
|
+
evidence = [f"Journal event #{receipt['seq']}", f"Policy {receipt['policy']}"]
|
|
166
|
+
return "\n".join(
|
|
167
|
+
[title, f"{grade['metric']} {grade['value']} · {grade['coverage']} scored", *evidence]
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def public_role(role: str | None) -> str:
|
|
172
|
+
"""Label built-in roles without treating unclassified actors as subagents."""
|
|
173
|
+
return {
|
|
174
|
+
None: "Core",
|
|
175
|
+
"core": "Core",
|
|
176
|
+
"agent": "Core",
|
|
177
|
+
"side": "Side",
|
|
178
|
+
"side-agent": "Side",
|
|
179
|
+
"side_agent": "Side",
|
|
180
|
+
"owner": "You",
|
|
181
|
+
}.get(role, role)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
PERMISSION_MODES = (
|
|
185
|
+
("manual", "Manual · Approve proposed file edits"),
|
|
186
|
+
("yolo", "YOLO · Write and run commands in the workspace"),
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def permission_modes(edition: Edition) -> tuple[tuple[str, str], ...]:
|
|
191
|
+
"""Picker rows for EDITION; editions without auto-approve never offer YOLO."""
|
|
192
|
+
if auto_approve_available(edition):
|
|
193
|
+
return PERMISSION_MODES
|
|
194
|
+
return tuple(row for row in PERMISSION_MODES if row[0] != "yolo")
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def permissions(client, profile, revision, mode):
|
|
198
|
+
if mode not in {"manual", "yolo"}:
|
|
199
|
+
raise ValueError("Usage: /permissions [manual|yolo]")
|
|
200
|
+
if mode == "yolo" and not auto_approve_available(getattr(client, "edition", Edition.BETA)):
|
|
201
|
+
raise AutoApproveUnavailable()
|
|
202
|
+
if client.viewer is not None:
|
|
203
|
+
raise ValueError("Changing permissions requires the owner terminal")
|
|
204
|
+
if not revision:
|
|
205
|
+
raise ValueError("An active run profile is required")
|
|
206
|
+
updated = profile.copy()
|
|
207
|
+
if mode == "yolo":
|
|
208
|
+
updated["permissions"] = mode
|
|
209
|
+
else:
|
|
210
|
+
updated.pop("permissions", None)
|
|
211
|
+
try:
|
|
212
|
+
result = client.send("configure", profile=updated, expected_revision=revision)
|
|
213
|
+
except Rejected as error:
|
|
214
|
+
if mode == "yolo" and "unknown field `permissions`" in str(error):
|
|
215
|
+
raise ValueError("YOLO requires an updated Synth Code runtime") from error
|
|
216
|
+
raise
|
|
217
|
+
if not result["active"]:
|
|
218
|
+
raise ValueError("Permission change was not activated")
|
|
219
|
+
return "Permissions · " + ("YOLO" if mode == "yolo" else "Manual")
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def binding_detail(binding, model=None, effort=None, tier=None, *, show_provider=True):
|
|
223
|
+
if binding == "inkling-2-mini":
|
|
224
|
+
model_detail = " ".join(filter(None, (model or binding, tier)))
|
|
225
|
+
return f"Synth / {model_detail}" if show_provider else model_detail
|
|
226
|
+
return binding if show_provider else (model or "")
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def role_bindings(profile):
|
|
230
|
+
return [f"{public_role(role)} · {binding_detail(profile[role])}" for role in ("core", "side")]
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def _identifier(value: str) -> bool:
|
|
234
|
+
return re.fullmatch(r"[A-Za-z0-9_-]{1,96}", value) is not None
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def menu(prefix: str = "", edition: Edition = Edition.BETA) -> tuple[str, ...]:
|
|
238
|
+
"""Return menu rows for the slash draft, including discoverable aliases."""
|
|
239
|
+
token, *_ = prefix.split(maxsplit=1) or [""]
|
|
240
|
+
matches = []
|
|
241
|
+
for spec in _COMMANDS:
|
|
242
|
+
if not command_available(spec.name, edition):
|
|
243
|
+
continue
|
|
244
|
+
names = tuple(
|
|
245
|
+
name for name in (spec.name, *spec.aliases) if name.startswith(token.removeprefix("/"))
|
|
246
|
+
)
|
|
247
|
+
if names:
|
|
248
|
+
usage = " · ".join(spec.usage(name, edition) for name in names)
|
|
249
|
+
matches.append(f"{usage} {spec.description}")
|
|
250
|
+
return tuple(matches)
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def completions(draft, edition: Edition = Edition.BETA):
|
|
254
|
+
if not draft.startswith("/") or any(ch.isspace() for ch in draft):
|
|
255
|
+
return []
|
|
256
|
+
prefix = draft[1:]
|
|
257
|
+
choices = [
|
|
258
|
+
("/" + name, spec)
|
|
259
|
+
for name, spec in _LOOKUP.items()
|
|
260
|
+
if name.startswith(prefix)
|
|
261
|
+
and (prefix or name == spec.name)
|
|
262
|
+
and command_available(spec.name, edition)
|
|
263
|
+
]
|
|
264
|
+
return sorted(choices, key=lambda choice: (choice[0] != draft, choice[0]))
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def run_names(client: Client) -> tuple[str, ...]:
|
|
268
|
+
"""Read run IDs from the owning daemon in reverse creation order."""
|
|
269
|
+
return tuple(client.send("owner_view")["runs"])
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
def resume_menu(client: Client) -> str:
|
|
273
|
+
"""Show which recorded runs can be opened through /resume."""
|
|
274
|
+
rows = [f"{run} (current)" if run == client.run else run for run in run_names(client)]
|
|
275
|
+
return "\n".join(["Recorded runs", *(rows or ["No recorded runs"])])
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def _context(client: Client) -> tuple[list[str], list[str], list[str]]:
|
|
279
|
+
return _context_rows(client.run, client.send("owner_view"))
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def _context_rows(run, view) -> tuple[list[str], list[str], list[str]]:
|
|
283
|
+
status = [f"Run {run}", f"Phase {view['phase']}", f"Journal cursor {view['cursor']}"]
|
|
284
|
+
if (revision := view["profile_revision"]) is not None:
|
|
285
|
+
status.append(f"Profile {revision}")
|
|
286
|
+
models = role_bindings(view["profile"])
|
|
287
|
+
else:
|
|
288
|
+
status.append("Profile unconfigured")
|
|
289
|
+
models = ["Agent · unconfigured", "Side agent · unconfigured"]
|
|
290
|
+
checkpoint = view["checkpoint"]
|
|
291
|
+
checkpoint_lines = (
|
|
292
|
+
[
|
|
293
|
+
f"Checkpoint {checkpoint['id']} · #{checkpoint['seq']} · through #{checkpoint['through']}",
|
|
294
|
+
checkpoint["summary"],
|
|
295
|
+
]
|
|
296
|
+
if checkpoint is not None
|
|
297
|
+
else ["No checkpoint"]
|
|
298
|
+
)
|
|
299
|
+
return status, models, checkpoint_lines
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
_NODE_LABELS = {"core": "Core", "side": "Side agent", "subagent": "Subagent"}
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def _agents(client: Client) -> str:
|
|
306
|
+
view = client.send("owner_view")
|
|
307
|
+
_, bindings, _ = _context_rows(client.run, view)
|
|
308
|
+
nodes = view["nodes"]
|
|
309
|
+
lines = list(bindings)
|
|
310
|
+
if all(node["class"] != "subagent" for node in nodes):
|
|
311
|
+
lines.append("Subagents · none")
|
|
312
|
+
for node in nodes:
|
|
313
|
+
identity, parent, phase, node_class = (
|
|
314
|
+
node["id"],
|
|
315
|
+
node["parent"],
|
|
316
|
+
node["state"],
|
|
317
|
+
node["class"],
|
|
318
|
+
)
|
|
319
|
+
label = _NODE_LABELS[node_class]
|
|
320
|
+
if node_class == "side":
|
|
321
|
+
lines.append(f"{label} {identity} · {phase}")
|
|
322
|
+
else:
|
|
323
|
+
lines.append(f"{label} {identity} · parent {public_role(parent)} · {phase}")
|
|
324
|
+
return "\n".join(lines)
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
def _checkpoint_input(client: Client, operation: str) -> tuple[int, str]:
|
|
328
|
+
view = client.send("owner_view", checkpoint_id=operation)
|
|
329
|
+
if (previous := view["checkpoint"]) is not None:
|
|
330
|
+
return previous["through"], previous["summary"]
|
|
331
|
+
through = view["cursor"]
|
|
332
|
+
snapshot = client.snapshot(at=through)
|
|
333
|
+
excerpts = []
|
|
334
|
+
for row in reversed(snapshot["transcript"]):
|
|
335
|
+
if row["kind"] == "input":
|
|
336
|
+
role = "owner"
|
|
337
|
+
text = input_text(row["parts"])
|
|
338
|
+
elif row["kind"] == "message":
|
|
339
|
+
role = row["role"]
|
|
340
|
+
text = message_text(client, row)
|
|
341
|
+
else:
|
|
342
|
+
continue
|
|
343
|
+
if not text.strip():
|
|
344
|
+
continue
|
|
345
|
+
excerpt = f"#{row['seq']} {public_role(role)} · {' '.join(text.split())}".encode()
|
|
346
|
+
if len(excerpt) > 224:
|
|
347
|
+
excerpts.append(excerpt[:221].decode("utf-8", errors="ignore") + "…")
|
|
348
|
+
else:
|
|
349
|
+
excerpts.append(excerpt.decode())
|
|
350
|
+
if len(excerpts) == 8:
|
|
351
|
+
break
|
|
352
|
+
if not excerpts:
|
|
353
|
+
raise ValueError("No committed conversation to checkpoint")
|
|
354
|
+
return through, "\n".join(
|
|
355
|
+
[f"Recent conversation excerpts through #{through}", *reversed(excerpts)]
|
|
356
|
+
)
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
def compact(client: Client, operation: str) -> str:
|
|
360
|
+
"""Save a bounded extractive checkpoint at the committed conversation cursor."""
|
|
361
|
+
if not _identifier(operation):
|
|
362
|
+
raise ValueError("Invalid checkpoint operation")
|
|
363
|
+
through, summary = _checkpoint_input(client, operation)
|
|
364
|
+
receipt = client.send("checkpoint", id=operation, through=through, summary=summary)
|
|
365
|
+
return f"Checkpoint #{receipt['seq']} through #{receipt['through']}."
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
def settings_apply(client: Client, role: str) -> str:
|
|
369
|
+
"""Force ROLE's compaction boundary now and apply its queued model change."""
|
|
370
|
+
role = role or "core"
|
|
371
|
+
if not _identifier(role):
|
|
372
|
+
raise ValueError("Usage: /settings-apply [ROLE]")
|
|
373
|
+
receipt = client.send("set_settings_apply", role=role)
|
|
374
|
+
if receipt.get("seq") is None:
|
|
375
|
+
return f"No queued model change for {role}"
|
|
376
|
+
boundary = " at a fresh thread with a recap" if receipt.get("thread_released") else ""
|
|
377
|
+
return f"Applied queued model change for {role}{boundary} (#{receipt['seq']})"
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
def _diff(client: Client, effect: str) -> str:
|
|
381
|
+
if effect and not _identifier(effect):
|
|
382
|
+
raise ValueError("Usage: /diff [EFFECT]")
|
|
383
|
+
if not effect:
|
|
384
|
+
pending = approvals.pending_ids(client.send("owner_view"))
|
|
385
|
+
if not pending:
|
|
386
|
+
return "No pending edits"
|
|
387
|
+
if len(pending) > 1:
|
|
388
|
+
return "\n".join(["Pending edits", *(f"/diff {key}" for key in pending)])
|
|
389
|
+
effect = pending[0]
|
|
390
|
+
try:
|
|
391
|
+
data = client.send("preview", effect=effect)
|
|
392
|
+
except (FileNotFoundError, ConnectionRefusedError) as exc:
|
|
393
|
+
raise ValueError("Attach to the running daemon to review a pending edit") from exc
|
|
394
|
+
if data["phase"] not in ("proposed", "approved"):
|
|
395
|
+
raise ValueError(f"Edit {effect!r} is {data['phase']}")
|
|
396
|
+
return format_preview(data)
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
def overlay(command: Command, client: Client) -> str | None:
|
|
400
|
+
"""Render a local command, or defer to the terminal’s command handler."""
|
|
401
|
+
if command.name == "help":
|
|
402
|
+
return "\n".join(menu(edition=client.edition))
|
|
403
|
+
if command.name in ("status", "model", "context"):
|
|
404
|
+
status, models, checkpoint = _context(client)
|
|
405
|
+
if command.name == "model":
|
|
406
|
+
return "\n".join(["Role bindings", *models])
|
|
407
|
+
if command.name == "context":
|
|
408
|
+
return "\n".join([*status, *models, *checkpoint])
|
|
409
|
+
return "\n".join(status)
|
|
410
|
+
if command.name == "agents":
|
|
411
|
+
return _agents(client)
|
|
412
|
+
if command.name == "version":
|
|
413
|
+
try:
|
|
414
|
+
return f"Synth Code {version('synth-code')}"
|
|
415
|
+
except PackageNotFoundError as exc:
|
|
416
|
+
raise ValueError("Synth Code package metadata is unavailable") from exc
|
|
417
|
+
if command.name == "resume" and not command.rest:
|
|
418
|
+
return resume_menu(client)
|
|
419
|
+
if command.name == "diff":
|
|
420
|
+
return _diff(client, command.rest)
|
|
421
|
+
if command.name == "approvals":
|
|
422
|
+
return approvals.format_listing(approvals.listing(client, history.events(client)))
|
|
423
|
+
if command.name == "settings-apply":
|
|
424
|
+
return settings_apply(client, command.rest)
|
|
425
|
+
return None
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"""Read-only curses surface for a Rex pane granted one source and one view."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import curses
|
|
6
|
+
import sys
|
|
7
|
+
from time import monotonic
|
|
8
|
+
|
|
9
|
+
from .live_turns import submit
|
|
10
|
+
from .plugin_host import SurfaceHost
|
|
11
|
+
from .terminal_layout import _synchronized_update, palette
|
|
12
|
+
from .view import InputDecoder, TerminalInput, decode_batch, fit_cells, run_curses
|
|
13
|
+
from .views import Cursor, CursorBinding
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def open_source_view(client, source: str, view_id: str) -> None:
|
|
17
|
+
if client.viewer is None:
|
|
18
|
+
raise ValueError("A scoped viewer key is required")
|
|
19
|
+
state = client.send("source.snapshot", source=source, view_id=view_id)
|
|
20
|
+
host = SurfaceHost()
|
|
21
|
+
host.snapshot(state)
|
|
22
|
+
run_curses(_viewer, client, host, source, view_id, state, state_dir=client.state)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _viewer(screen, client, host, source, view_id, state):
|
|
26
|
+
inp = TerminalInput(sys.stdin.fileno())
|
|
27
|
+
try:
|
|
28
|
+
with client.subscribe(
|
|
29
|
+
after=state["cursor"],
|
|
30
|
+
source=(source, view_id),
|
|
31
|
+
wake=inp.wake,
|
|
32
|
+
) as subscription:
|
|
33
|
+
_render(
|
|
34
|
+
screen, inp, client, subscription, host, source, view_id, state["view"]
|
|
35
|
+
)
|
|
36
|
+
finally:
|
|
37
|
+
inp.close()
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _render(screen, inp, client, subscription, host, source, view_id, scoped):
|
|
41
|
+
decoder = InputDecoder()
|
|
42
|
+
styles = palette()
|
|
43
|
+
pending = None
|
|
44
|
+
hydrate = False
|
|
45
|
+
error = ""
|
|
46
|
+
last = None
|
|
47
|
+
while True:
|
|
48
|
+
for envelope in subscription.drain():
|
|
49
|
+
kind = envelope["type"]
|
|
50
|
+
if kind == "event":
|
|
51
|
+
host.event(envelope["event"])
|
|
52
|
+
elif kind == "live":
|
|
53
|
+
body = envelope["frame"]
|
|
54
|
+
if body["kind"] == "view.changed":
|
|
55
|
+
scoped = body["view"]
|
|
56
|
+
else:
|
|
57
|
+
host.live(body)
|
|
58
|
+
elif kind == "caught_up":
|
|
59
|
+
scoped = envelope.get("view", scoped)
|
|
60
|
+
error = ""
|
|
61
|
+
hydrate = True
|
|
62
|
+
elif kind in {"disconnected", "resyncing", "refused"}:
|
|
63
|
+
host.disconnected()
|
|
64
|
+
error = (
|
|
65
|
+
"Source access refused"
|
|
66
|
+
if kind == "refused"
|
|
67
|
+
else "Reconnecting source"
|
|
68
|
+
)
|
|
69
|
+
hydrate = False
|
|
70
|
+
if pending is not None and pending.done():
|
|
71
|
+
try:
|
|
72
|
+
host.snapshot(pending.result())
|
|
73
|
+
except (OSError, ValueError, KeyError, TypeError):
|
|
74
|
+
error = "Source snapshot unavailable"
|
|
75
|
+
pending = None
|
|
76
|
+
if hydrate and pending is None:
|
|
77
|
+
pending = submit(
|
|
78
|
+
client.send, "source.snapshot", source=source, view_id=view_id
|
|
79
|
+
)
|
|
80
|
+
pending.add_done_callback(lambda _: inp.wake())
|
|
81
|
+
hydrate = False
|
|
82
|
+
size = inp.window_size()
|
|
83
|
+
if size is not None and size != screen.getmaxyx():
|
|
84
|
+
curses.resize_term(*size)
|
|
85
|
+
height, width = screen.getmaxyx()
|
|
86
|
+
signature = height, width, host.generation, scoped, error
|
|
87
|
+
if signature != last:
|
|
88
|
+
_draw(screen, styles, host, source, view_id, scoped, height, width, error)
|
|
89
|
+
last = signature
|
|
90
|
+
inp.poll(decoder.timeout_ms(monotonic()))
|
|
91
|
+
events = (
|
|
92
|
+
decode_batch(inp, decoder, monotonic)
|
|
93
|
+
if inp.buf
|
|
94
|
+
else [(decoder.on_timeout(monotonic()), 0)]
|
|
95
|
+
)
|
|
96
|
+
if any(
|
|
97
|
+
kind in {"eof", "detach", "interrupt"} or key in (4, "q")
|
|
98
|
+
for kind, key in events
|
|
99
|
+
):
|
|
100
|
+
return
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _draw(screen, styles, host, source, view_id, scoped, height, width, error):
|
|
104
|
+
cursor = next(
|
|
105
|
+
(
|
|
106
|
+
mount["consumes"]
|
|
107
|
+
for mount in scoped.get("mounts", ())
|
|
108
|
+
if mount.get("consumes")
|
|
109
|
+
),
|
|
110
|
+
None,
|
|
111
|
+
)
|
|
112
|
+
binding = CursorBinding(cursor["channel"]) if cursor is not None else None
|
|
113
|
+
cursors = tuple(
|
|
114
|
+
Cursor(channel, key) for channel, key in scoped.get("cursors", {}).items()
|
|
115
|
+
)
|
|
116
|
+
columns = max(0, width - 3)
|
|
117
|
+
lines = host.single(
|
|
118
|
+
view_id,
|
|
119
|
+
source,
|
|
120
|
+
columns,
|
|
121
|
+
max(0, height - 2),
|
|
122
|
+
consumes=binding,
|
|
123
|
+
cursors=cursors,
|
|
124
|
+
)
|
|
125
|
+
screen.erase()
|
|
126
|
+
if columns and height >= 2:
|
|
127
|
+
screen.addstr(0, 1, fit_cells(view_id, columns), styles.get("brand", 0))
|
|
128
|
+
for row, line in enumerate(lines, 1):
|
|
129
|
+
screen.addstr(row, 1, line.text, styles.get(line.style.value, 0))
|
|
130
|
+
if error:
|
|
131
|
+
screen.addstr(
|
|
132
|
+
height - 1, 1, fit_cells(error, columns), styles.get("error", 0)
|
|
133
|
+
)
|
|
134
|
+
screen.noutrefresh()
|
|
135
|
+
_synchronized_update()
|
synth_code/starter.json
ADDED
synth_code/stdio.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""Interactive JSONL requests. Correlated frames may complete out of order."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
5
|
+
from subprocess import TimeoutExpired
|
|
6
|
+
from threading import Lock
|
|
7
|
+
|
|
8
|
+
MAX_FRAME = 65536
|
|
9
|
+
MAX_PENDING = 8
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def serve(client, source, sink):
|
|
13
|
+
lock = Lock()
|
|
14
|
+
pending = set()
|
|
15
|
+
|
|
16
|
+
def emit(reply):
|
|
17
|
+
sink.write(json.dumps(reply) + "\n")
|
|
18
|
+
sink.flush()
|
|
19
|
+
|
|
20
|
+
def execute(request_id, command):
|
|
21
|
+
try:
|
|
22
|
+
result = client.send(
|
|
23
|
+
command["op"], **{k: v for k, v in command.items() if k != "op"}
|
|
24
|
+
)
|
|
25
|
+
reply = {"ok": True, "result": result}
|
|
26
|
+
except (ValueError, TypeError, OSError, TimeoutExpired) as exc:
|
|
27
|
+
reply = {"ok": False, "error": str(exc)}
|
|
28
|
+
with lock:
|
|
29
|
+
if request_id is not None:
|
|
30
|
+
reply["id"] = request_id
|
|
31
|
+
pending.remove(request_id)
|
|
32
|
+
emit(reply)
|
|
33
|
+
|
|
34
|
+
with ThreadPoolExecutor(max_workers=MAX_PENDING) as workers:
|
|
35
|
+
while line := source.readline(MAX_FRAME + 1):
|
|
36
|
+
request_id = None
|
|
37
|
+
try:
|
|
38
|
+
if len(line) > MAX_FRAME:
|
|
39
|
+
while line and not line.endswith(b"\n"):
|
|
40
|
+
line = source.readline(MAX_FRAME + 1)
|
|
41
|
+
raise ValueError("Protocol frame too large")
|
|
42
|
+
frame = json.loads(line)
|
|
43
|
+
if not isinstance(frame, dict):
|
|
44
|
+
raise TypeError("Expected a protocol object")
|
|
45
|
+
if "id" in frame:
|
|
46
|
+
identity = frame["id"]
|
|
47
|
+
if not isinstance(identity, str) or not 1 <= len(identity) <= 128:
|
|
48
|
+
raise ValueError("Invalid request ID")
|
|
49
|
+
request_id = identity
|
|
50
|
+
if (
|
|
51
|
+
frame.get("run") != client.run
|
|
52
|
+
or frame.get("version") != client.version
|
|
53
|
+
):
|
|
54
|
+
raise ValueError("Stdio frame differs from attached run or version")
|
|
55
|
+
command = frame.get("command")
|
|
56
|
+
if not isinstance(command, dict) or not isinstance(
|
|
57
|
+
command.get("op"), str
|
|
58
|
+
):
|
|
59
|
+
raise TypeError("Expected a protocol command")
|
|
60
|
+
if request_id is None:
|
|
61
|
+
execute(None, command)
|
|
62
|
+
continue
|
|
63
|
+
with lock:
|
|
64
|
+
if request_id in pending:
|
|
65
|
+
raise ValueError("Request ID already in flight")
|
|
66
|
+
if len(pending) >= MAX_PENDING:
|
|
67
|
+
raise ValueError("Too many requests in flight")
|
|
68
|
+
pending.add(request_id)
|
|
69
|
+
workers.submit(execute, request_id, command)
|
|
70
|
+
except (TypeError, ValueError) as exc:
|
|
71
|
+
error = {"ok": False, "error": str(exc)}
|
|
72
|
+
if request_id is not None:
|
|
73
|
+
error["id"] = request_id
|
|
74
|
+
with lock:
|
|
75
|
+
emit(error)
|