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/approvals.py
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
"""First-class owner approvals for model file writes.
|
|
2
|
+
|
|
3
|
+
Every pending write is an approval card rebuilt from journal state; approving
|
|
4
|
+
re-reads the proposal and refuses when the digest differs from the one shown.
|
|
5
|
+
There is no auto-approve: each card needs an explicit owner decision.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import difflib
|
|
11
|
+
from dataclasses import dataclass, replace
|
|
12
|
+
from enum import Enum
|
|
13
|
+
|
|
14
|
+
PREVIEW_LINES = 12
|
|
15
|
+
DECISIONS_MAX = 10
|
|
16
|
+
OWNER = "local owner"
|
|
17
|
+
CARD_TITLE = "Approval required"
|
|
18
|
+
_DECISION_KINDS = {"effect.approved": "Approved", "effect.denied": "Denied"}
|
|
19
|
+
# `effect.denied` with `cancelled_by` (src/effect_delivery/store.rs) is the engine
|
|
20
|
+
# withdrawing a parked edit because its turn was cancelled, not a denial: say so.
|
|
21
|
+
CANCELLED_VERDICT = "Cancelled"
|
|
22
|
+
TURN_CANCELLED = "turn cancelled"
|
|
23
|
+
_LEGACY_KINDS = {
|
|
24
|
+
"approval.requested": "Approval requested",
|
|
25
|
+
"approval.resolved": "Approval resolved",
|
|
26
|
+
"approval.closed": "Approval closed",
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def pending_ids(view: dict) -> list[str]:
|
|
32
|
+
"""Effect ids from `owner_view.pending_effects`, entries or legacy bare ids."""
|
|
33
|
+
return [e if isinstance(e, str) else e["effect_id"] for e in view["pending_effects"]]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def pending_tools(view: dict) -> dict[str, str]:
|
|
37
|
+
"""Daemon tool labels by effect id; older daemons sent the placeholder `file`."""
|
|
38
|
+
return {
|
|
39
|
+
e["effect_id"]: e["tool"]
|
|
40
|
+
for e in view["pending_effects"]
|
|
41
|
+
if isinstance(e, dict) and e.get("tool") not in (None, "file")
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def pending_actions(view: dict) -> dict[str, str]:
|
|
46
|
+
"""Daemon file actions (`create`/`replace`) by effect id, from `file_actions`.
|
|
47
|
+
|
|
48
|
+
This is authoritative: the preview's `before_content` is only recorded for
|
|
49
|
+
owner/turn edits, so a model `replace_file` has none and must not read as create.
|
|
50
|
+
"""
|
|
51
|
+
return {
|
|
52
|
+
e["effect_id"]: e["action"]
|
|
53
|
+
for e in view["pending_effects"]
|
|
54
|
+
if isinstance(e, dict) and e.get("action") in ("create", "replace")
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
class ApprovalKey(Enum):
|
|
58
|
+
APPROVE = "a"
|
|
59
|
+
DENY = "d"
|
|
60
|
+
VIEW = "v"
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class ApprovalStale(ValueError):
|
|
64
|
+
"""The proposal changed after the owner saw it; the new card must be re-shown."""
|
|
65
|
+
|
|
66
|
+
code = "approval_stale"
|
|
67
|
+
|
|
68
|
+
def __init__(self, card: "ApprovalCard", shown: str):
|
|
69
|
+
super().__init__(
|
|
70
|
+
f"Edit {card.effect} changed since it was shown "
|
|
71
|
+
f"(shown {shown[:12]}, now {card.digest[:12]}); review it again"
|
|
72
|
+
)
|
|
73
|
+
self.card = card
|
|
74
|
+
self.shown = shown
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class ApprovalsUnavailable(RuntimeError):
|
|
78
|
+
"""The daemon could not serve the approval queue; other surfaces keep working."""
|
|
79
|
+
|
|
80
|
+
code = "approvals_unavailable"
|
|
81
|
+
|
|
82
|
+
def __init__(self, cause: BaseException):
|
|
83
|
+
super().__init__(f"Approvals unavailable · {type(cause).__name__}: {cause}")
|
|
84
|
+
self.cause = cause
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@dataclass(frozen=True, slots=True)
|
|
88
|
+
class ApprovalCard:
|
|
89
|
+
effect: str
|
|
90
|
+
path: str
|
|
91
|
+
digest: str
|
|
92
|
+
phase: str
|
|
93
|
+
content: str
|
|
94
|
+
before: str | None
|
|
95
|
+
source_tool: str | None = None
|
|
96
|
+
source_action: str | None = None
|
|
97
|
+
|
|
98
|
+
@classmethod
|
|
99
|
+
def from_preview(
|
|
100
|
+
cls,
|
|
101
|
+
effect: str,
|
|
102
|
+
data: dict,
|
|
103
|
+
source_tool: str | None = None,
|
|
104
|
+
source_action: str | None = None,
|
|
105
|
+
) -> "ApprovalCard":
|
|
106
|
+
return cls(
|
|
107
|
+
effect=effect,
|
|
108
|
+
path=data["name"],
|
|
109
|
+
digest=data["digest"],
|
|
110
|
+
phase=data["phase"],
|
|
111
|
+
content=data["content"],
|
|
112
|
+
before=data["before_content"],
|
|
113
|
+
source_tool=source_tool,
|
|
114
|
+
source_action=source_action,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
@property
|
|
118
|
+
def creates(self) -> bool:
|
|
119
|
+
if self.source_action:
|
|
120
|
+
return self.source_action == "create"
|
|
121
|
+
return self.before is None
|
|
122
|
+
|
|
123
|
+
@property
|
|
124
|
+
def tool(self) -> str:
|
|
125
|
+
if self.source_tool:
|
|
126
|
+
return self.source_tool
|
|
127
|
+
return "create_file" if self.creates else "replace_file"
|
|
128
|
+
|
|
129
|
+
@property
|
|
130
|
+
def size(self) -> str:
|
|
131
|
+
after = len(self.content.encode())
|
|
132
|
+
if self.before is None:
|
|
133
|
+
return f"{after} B"
|
|
134
|
+
return f"{len(self.before.encode())}→{after} B"
|
|
135
|
+
|
|
136
|
+
def body(self) -> list[str]:
|
|
137
|
+
"""The complete preview: new file lines, or a unified diff before→after."""
|
|
138
|
+
if self.before is None:
|
|
139
|
+
return self.content.splitlines()
|
|
140
|
+
return list(
|
|
141
|
+
difflib.unified_diff(
|
|
142
|
+
self.before.splitlines(),
|
|
143
|
+
self.content.splitlines(),
|
|
144
|
+
fromfile=f"{self.path} (before)",
|
|
145
|
+
tofile=f"{self.path} (proposed)",
|
|
146
|
+
lineterm="",
|
|
147
|
+
)
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _clip(line: str, width: int) -> str:
|
|
152
|
+
return line if len(line) <= width else line[: max(width - 1, 0)] + "…"
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def render_card(
|
|
156
|
+
card: ApprovalCard,
|
|
157
|
+
width: int,
|
|
158
|
+
height: int,
|
|
159
|
+
*,
|
|
160
|
+
position: tuple[int, int] = (1, 1),
|
|
161
|
+
full: bool = False,
|
|
162
|
+
) -> list[str]:
|
|
163
|
+
"""Render CARD into at most HEIGHT rows of at most WIDTH columns."""
|
|
164
|
+
index, total = position
|
|
165
|
+
action = "create" if card.creates else "replace"
|
|
166
|
+
header = [
|
|
167
|
+
f"{CARD_TITLE} · {card.tool} · {action} · {index}/{total}",
|
|
168
|
+
f"{card.path} · {card.size}",
|
|
169
|
+
f"{card.effect} · {card.digest[:12]}",
|
|
170
|
+
]
|
|
171
|
+
hint = "a approve · d deny · v full diff"
|
|
172
|
+
room = max(height - len(header) - 1, 0)
|
|
173
|
+
lines = card.body()
|
|
174
|
+
if not full:
|
|
175
|
+
room = min(room, PREVIEW_LINES)
|
|
176
|
+
shown = lines if len(lines) <= room else lines[: max(room - 1, 0)]
|
|
177
|
+
if len(shown) < len(lines):
|
|
178
|
+
shown = [*shown, f"… {len(lines) - len(shown)} more lines · v to view full diff"]
|
|
179
|
+
rows = [*header, *shown, hint][: max(height, 0)]
|
|
180
|
+
if height and rows[-1] != hint:
|
|
181
|
+
rows[-1] = hint
|
|
182
|
+
return [_clip(row, width) for row in rows]
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
class ApprovalQueue:
|
|
186
|
+
"""Pending cards in journal order, rebuilt from the daemon on every sync."""
|
|
187
|
+
|
|
188
|
+
def __init__(self) -> None:
|
|
189
|
+
self.cards: list[ApprovalCard] = []
|
|
190
|
+
self.full = False
|
|
191
|
+
|
|
192
|
+
def sync(self, client) -> None:
|
|
193
|
+
"""Rebuild the queue; raise ApprovalsUnavailable and keep the old cards on failure."""
|
|
194
|
+
try:
|
|
195
|
+
view = client.send("owner_view")
|
|
196
|
+
tools, actions = pending_tools(view), pending_actions(view)
|
|
197
|
+
cards = []
|
|
198
|
+
for effect in pending_ids(view):
|
|
199
|
+
data = client.send("preview", effect=effect)
|
|
200
|
+
if data["phase"] in ("proposed", "approved"):
|
|
201
|
+
cards.append(ApprovalCard.from_preview(
|
|
202
|
+
effect, data, tools.get(effect), actions.get(effect)))
|
|
203
|
+
except (OSError, ValueError, KeyError, TypeError) as error:
|
|
204
|
+
raise ApprovalsUnavailable(error) from error
|
|
205
|
+
self.cards = cards
|
|
206
|
+
self.full = False
|
|
207
|
+
|
|
208
|
+
@property
|
|
209
|
+
def focused(self) -> ApprovalCard | None:
|
|
210
|
+
return self.cards[0] if self.cards else None
|
|
211
|
+
|
|
212
|
+
@property
|
|
213
|
+
def status(self) -> str:
|
|
214
|
+
if not self.cards:
|
|
215
|
+
return ""
|
|
216
|
+
return f"waiting for your approval (1 of {len(self.cards)})"
|
|
217
|
+
|
|
218
|
+
def render(self, width: int, height: int) -> list[str]:
|
|
219
|
+
card = self.focused
|
|
220
|
+
if card is None:
|
|
221
|
+
return []
|
|
222
|
+
return render_card(
|
|
223
|
+
card, width, height, position=(1, len(self.cards)), full=self.full
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
def handle_key(self, client, key: str) -> str | None:
|
|
227
|
+
"""Apply a card key; return a status line, or None when the key is not ours."""
|
|
228
|
+
card = self.focused
|
|
229
|
+
if card is None:
|
|
230
|
+
return None
|
|
231
|
+
try:
|
|
232
|
+
choice = ApprovalKey(key)
|
|
233
|
+
except ValueError:
|
|
234
|
+
return None
|
|
235
|
+
if choice is ApprovalKey.VIEW:
|
|
236
|
+
self.full = not self.full
|
|
237
|
+
return None
|
|
238
|
+
try:
|
|
239
|
+
if choice is ApprovalKey.APPROVE:
|
|
240
|
+
message = approve(client, card.effect, card.digest)
|
|
241
|
+
else:
|
|
242
|
+
message = deny(client, card.effect, card.digest)
|
|
243
|
+
except ApprovalStale as stale:
|
|
244
|
+
# The preview alone cannot say create vs replace; keep the daemon's labels.
|
|
245
|
+
self.cards[0] = replace(
|
|
246
|
+
stale.card, source_tool=card.source_tool, source_action=card.source_action
|
|
247
|
+
)
|
|
248
|
+
self.full = False
|
|
249
|
+
return str(stale)
|
|
250
|
+
self.cards.pop(0)
|
|
251
|
+
self.full = False
|
|
252
|
+
return message
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def _current(client, effect: str, shown: str) -> ApprovalCard:
|
|
256
|
+
card = ApprovalCard.from_preview(effect, client.send("preview", effect=effect))
|
|
257
|
+
if card.digest != shown:
|
|
258
|
+
raise ApprovalStale(card, shown)
|
|
259
|
+
return card
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def approve(client, effect: str, shown: str) -> str:
|
|
263
|
+
"""Approve EFFECT only if its digest still matches SHOWN, then apply it."""
|
|
264
|
+
card = _current(client, effect, shown)
|
|
265
|
+
client.send("approve", effect=effect, digest=shown)
|
|
266
|
+
client.send("execute", effect=effect)
|
|
267
|
+
return f"Approved · {card.path} · by {OWNER}"
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def deny(client, effect: str, shown: str) -> str:
|
|
271
|
+
card = _current(client, effect, shown)
|
|
272
|
+
client.send("deny", effect=effect, digest=shown)
|
|
273
|
+
return f"Denied · {card.path} · by {OWNER}"
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def resolve_target(client, words: list[str]) -> tuple[str, str]:
|
|
277
|
+
"""Resolve `[EFFECT] [DIGEST]` against the pending queue."""
|
|
278
|
+
if len(words) == 2:
|
|
279
|
+
return words[0], words[1]
|
|
280
|
+
pending = pending_ids(client.send("owner_view"))
|
|
281
|
+
if len(words) == 1 and words[0] in pending:
|
|
282
|
+
effect = words[0]
|
|
283
|
+
elif len(words) == 1 and len(pending) == 1:
|
|
284
|
+
return pending[0], words[0]
|
|
285
|
+
elif not words and pending:
|
|
286
|
+
effect = pending[0]
|
|
287
|
+
else:
|
|
288
|
+
raise ValueError("Usage: /approve [EFFECT] [DIGEST] · see /approvals")
|
|
289
|
+
data = client.send("preview", effect=effect)
|
|
290
|
+
return effect, data["digest"]
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
@dataclass(frozen=True, slots=True)
|
|
294
|
+
class Decision:
|
|
295
|
+
verdict: str
|
|
296
|
+
effect: str
|
|
297
|
+
path: str
|
|
298
|
+
at: str | None
|
|
299
|
+
actor: str
|
|
300
|
+
# Set when the effect was withdrawn by a turn cancel (`cancelled_by` turn id).
|
|
301
|
+
cancelled_by: str | None = None
|
|
302
|
+
|
|
303
|
+
def detail(self) -> str:
|
|
304
|
+
"""Everything after the verdict: `path · by actor[ · at]`, or
|
|
305
|
+
`path · turn cancelled[ · at]` for an edit withdrawn by a turn cancel."""
|
|
306
|
+
when = f" · {self.at}" if self.at else ""
|
|
307
|
+
cause = TURN_CANCELLED if self.cancelled_by else f"by {self.actor}"
|
|
308
|
+
return f"{self.path} · {cause}{when}"
|
|
309
|
+
|
|
310
|
+
def line(self) -> str:
|
|
311
|
+
return f"{self.verdict} · {self.detail()}"
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
DECISION_EVENT_KINDS = frozenset(_DECISION_KINDS) | frozenset(_LEGACY_KINDS)
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def decision(event, targets: dict[str, str]) -> Decision | None:
|
|
318
|
+
"""The owner decision EVENT records, or None; remembers proposal targets in TARGETS.
|
|
319
|
+
|
|
320
|
+
Daemon decisions may carry `{actor, at, digest, path}`; when absent the path
|
|
321
|
+
falls back to the proposal's target and the time is omitted.
|
|
322
|
+
"""
|
|
323
|
+
kind = event.get("kind")
|
|
324
|
+
data = event.get("payload") or event.get("data") or {}
|
|
325
|
+
effect = data.get("effect")
|
|
326
|
+
if kind == "effect.proposed" and effect and data.get("target"):
|
|
327
|
+
targets[effect] = data["target"]
|
|
328
|
+
if kind in _DECISION_KINDS:
|
|
329
|
+
cancelled_by = data.get("cancelled_by") if kind == "effect.denied" else None
|
|
330
|
+
return Decision(
|
|
331
|
+
verdict=CANCELLED_VERDICT if cancelled_by else _DECISION_KINDS[kind],
|
|
332
|
+
effect=effect or "",
|
|
333
|
+
path=data.get("path") or data.get("target") or targets.get(effect, effect or ""),
|
|
334
|
+
at=data.get("at") or event.get("at"),
|
|
335
|
+
actor=_actor(data.get("actor")) or OWNER,
|
|
336
|
+
cancelled_by=cancelled_by,
|
|
337
|
+
)
|
|
338
|
+
if kind in _LEGACY_KINDS:
|
|
339
|
+
return Decision(
|
|
340
|
+
verdict=_LEGACY_KINDS[kind] + " (read-only)",
|
|
341
|
+
effect=effect or "",
|
|
342
|
+
path=data.get("method") or effect or "",
|
|
343
|
+
at=event.get("at"),
|
|
344
|
+
actor=data.get("actor") or "codex",
|
|
345
|
+
)
|
|
346
|
+
return None
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
def _actor(actor: str | None) -> str | None:
|
|
350
|
+
"""Wire actor ids read as people: `local_owner` → `local owner`."""
|
|
351
|
+
return actor.replace("_", " ") if actor else None
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
def decisions(events, targets: dict[str, str] | None = None) -> list[Decision]:
|
|
355
|
+
"""Owner decisions in journal order, including read-only Codex-era approvals."""
|
|
356
|
+
targets = dict(targets or {})
|
|
357
|
+
return [found for event in events if (found := decision(event, targets))]
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
def listing(client, events=()) -> dict:
|
|
361
|
+
"""Pending cards plus recent decisions, as plain data for text or JSON."""
|
|
362
|
+
queue = ApprovalQueue()
|
|
363
|
+
queue.sync(client)
|
|
364
|
+
return {
|
|
365
|
+
"pending": [
|
|
366
|
+
{
|
|
367
|
+
"effect": card.effect,
|
|
368
|
+
"tool": card.tool,
|
|
369
|
+
"path": card.path,
|
|
370
|
+
"action": "create" if card.creates else "replace",
|
|
371
|
+
"size": card.size,
|
|
372
|
+
"digest": card.digest,
|
|
373
|
+
"phase": card.phase,
|
|
374
|
+
}
|
|
375
|
+
for card in queue.cards
|
|
376
|
+
],
|
|
377
|
+
"decisions": [
|
|
378
|
+
{"verdict": d.verdict, "effect": d.effect, "path": d.path, "at": d.at, "actor": d.actor,
|
|
379
|
+
"cancelled_by": d.cancelled_by}
|
|
380
|
+
for d in decisions(events)[-DECISIONS_MAX:]
|
|
381
|
+
],
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
def format_listing(data: dict) -> str:
|
|
386
|
+
lines = [f"Pending approvals ({len(data['pending'])})"]
|
|
387
|
+
lines += [
|
|
388
|
+
f" {item['effect']} · {item['tool']} · {item['path']} · {item['size']} · {item['digest'][:12]}"
|
|
389
|
+
for item in data["pending"]
|
|
390
|
+
] or [" none"]
|
|
391
|
+
lines.append("Recent decisions")
|
|
392
|
+
lines += [
|
|
393
|
+
" " + Decision(d["verdict"], d["effect"], d["path"], d["at"], d["actor"],
|
|
394
|
+
d.get("cancelled_by")).line()
|
|
395
|
+
for d in data["decisions"]
|
|
396
|
+
] or [" none"]
|
|
397
|
+
return "\n".join(lines)
|
synth_code/blobs.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""Read run-scoped content using bounded pages and verify its durable reference."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
|
|
7
|
+
__all__ = ["read_blob"]
|
|
8
|
+
|
|
9
|
+
_PAGE_BYTES = 32_768
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def read_blob(client, reference: dict) -> bytes:
|
|
13
|
+
size = reference["bytes"]
|
|
14
|
+
digest = reference["sha256"]
|
|
15
|
+
if type(size) is not int or size < 0 or not isinstance(digest, str):
|
|
16
|
+
raise ValueError("Invalid blob reference")
|
|
17
|
+
body = bytearray()
|
|
18
|
+
while True:
|
|
19
|
+
offset = len(body)
|
|
20
|
+
page = client.send("read_blob", sha256=digest, offset=offset, limit=_PAGE_BYTES)
|
|
21
|
+
if page["bytes"] != size or page["offset"] != offset:
|
|
22
|
+
raise ValueError("Blob page disagrees with its reference")
|
|
23
|
+
part = bytes.fromhex(page["hex"])
|
|
24
|
+
if len(part) != min(_PAGE_BYTES, size - offset):
|
|
25
|
+
raise ValueError("Incomplete blob page")
|
|
26
|
+
body.extend(part)
|
|
27
|
+
if len(body) == size:
|
|
28
|
+
break
|
|
29
|
+
if hashlib.sha256(body).hexdigest() != digest:
|
|
30
|
+
raise ValueError("Blob content digest mismatch")
|
|
31
|
+
return bytes(body)
|