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,236 @@
|
|
|
1
|
+
"""Engine-independent declarations for the engine-v2 plugin fixture boundary."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from enum import StrEnum
|
|
7
|
+
from typing import TypeAlias
|
|
8
|
+
|
|
9
|
+
__all__ = (
|
|
10
|
+
"MAX_CONTEXT_CHARS",
|
|
11
|
+
"MAX_PAYLOAD_BYTES",
|
|
12
|
+
"SYNTH_API",
|
|
13
|
+
"Activation",
|
|
14
|
+
"ApprovalTier",
|
|
15
|
+
"ContractError",
|
|
16
|
+
"CursorSpec",
|
|
17
|
+
"Density",
|
|
18
|
+
"EntrypointSpec",
|
|
19
|
+
"Health",
|
|
20
|
+
"JsonObject",
|
|
21
|
+
"JsonValue",
|
|
22
|
+
"Lifecycle",
|
|
23
|
+
"Manifest",
|
|
24
|
+
"PanelSpec",
|
|
25
|
+
"Permission",
|
|
26
|
+
"Pin",
|
|
27
|
+
"PrimitiveKind",
|
|
28
|
+
"Refusal",
|
|
29
|
+
"RefusalCode",
|
|
30
|
+
"SourceBounds",
|
|
31
|
+
"SourceSpec",
|
|
32
|
+
"ToolReceipt",
|
|
33
|
+
"ToolSpec",
|
|
34
|
+
"ToolVerb",
|
|
35
|
+
"Transport",
|
|
36
|
+
"ViewSpec",
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
JsonValue: TypeAlias = "None | bool | int | float | str | list[JsonValue] | dict[str, JsonValue]"
|
|
40
|
+
JsonObject: TypeAlias = dict[str, JsonValue]
|
|
41
|
+
|
|
42
|
+
SYNTH_API = 1
|
|
43
|
+
MAX_PAYLOAD_BYTES = 1024 * 1024
|
|
44
|
+
MAX_CONTEXT_CHARS = 512
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class Activation(StrEnum):
|
|
48
|
+
ALWAYS = "always"
|
|
49
|
+
WORKSPACE_DETECT = "workspace_detect"
|
|
50
|
+
EXPLICIT = "explicit"
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class Permission(StrEnum):
|
|
54
|
+
UNIX_SOCKET = "unix_socket"
|
|
55
|
+
NETWORK = "network"
|
|
56
|
+
SUBPROCESS = "subprocess"
|
|
57
|
+
WORKSPACE_READ = "workspace_read"
|
|
58
|
+
PAID_SPEND = "paid_spend"
|
|
59
|
+
UI_SLOTS = "ui_slots"
|
|
60
|
+
REX_SPLITS = "rex_splits"
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class Lifecycle(StrEnum):
|
|
64
|
+
DISCOVERED = "discovered"
|
|
65
|
+
VALIDATED = "validated"
|
|
66
|
+
MOUNTED = "mounted"
|
|
67
|
+
ACTIVE = "active"
|
|
68
|
+
DEGRADED = "degraded"
|
|
69
|
+
UNMOUNTED = "unmounted"
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class Health(StrEnum):
|
|
73
|
+
CONNECTED = "connected"
|
|
74
|
+
STALE = "stale"
|
|
75
|
+
IN_DOUBT = "in_doubt"
|
|
76
|
+
UNAVAILABLE = "unavailable"
|
|
77
|
+
ERROR = "error"
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class Transport(StrEnum):
|
|
81
|
+
LATEST_VALUE = "latest_value"
|
|
82
|
+
OFFSET_APPEND = "offset_append"
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class Density(StrEnum):
|
|
86
|
+
COMPACT = "compact"
|
|
87
|
+
STANDARD = "standard"
|
|
88
|
+
FULL = "full"
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class PrimitiveKind(StrEnum):
|
|
92
|
+
PILL = "pill"
|
|
93
|
+
PROGRESS = "progress"
|
|
94
|
+
METRICS = "metrics"
|
|
95
|
+
TABLE = "table"
|
|
96
|
+
SERIES = "series"
|
|
97
|
+
HEATMAP = "heatmap"
|
|
98
|
+
SCATTER = "scatter"
|
|
99
|
+
DIFF = "diff"
|
|
100
|
+
LOG_TAIL = "log_tail"
|
|
101
|
+
CARD = "card"
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class ApprovalTier(StrEnum):
|
|
105
|
+
READ = "read"
|
|
106
|
+
MUTATE = "mutate"
|
|
107
|
+
PAID_SPEND = "paid_spend"
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
class RefusalCode(StrEnum):
|
|
111
|
+
MANIFEST_INVALID = "manifest_invalid"
|
|
112
|
+
API_VERSION = "api_version"
|
|
113
|
+
DIALECT_UNKNOWN = "dialect_unknown"
|
|
114
|
+
DIALECT_VERSION = "dialect_version"
|
|
115
|
+
SCHEMA_INVALID = "schema_invalid"
|
|
116
|
+
PAYLOAD_INVALID = "payload_invalid"
|
|
117
|
+
PAYLOAD_TOO_LARGE = "payload_too_large"
|
|
118
|
+
OFFSET_MISMATCH = "offset_mismatch"
|
|
119
|
+
SEQUENCE_STALE = "sequence_stale"
|
|
120
|
+
DUPLICATE_PLUGIN = "duplicate_plugin"
|
|
121
|
+
NOT_FOUND = "not_found"
|
|
122
|
+
INACTIVE = "inactive"
|
|
123
|
+
PERMISSION_DENIED = "permission_denied"
|
|
124
|
+
APPROVAL_REQUIRED = "approval_required"
|
|
125
|
+
CALLBACK_FAILED = "callback_failed"
|
|
126
|
+
CALLBACK_TIMEOUT = "callback_timeout"
|
|
127
|
+
CALLBACK_CANCELLED = "callback_cancelled"
|
|
128
|
+
CALLBACK_BUSY = "callback_busy"
|
|
129
|
+
CALLBACK_BUDGET = "callback_budget"
|
|
130
|
+
CALLBACK_REAP_FAILED = "callback_reap_failed"
|
|
131
|
+
OUTPUT_INVALID = "output_invalid"
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
@dataclass(frozen=True, slots=True)
|
|
135
|
+
class Refusal:
|
|
136
|
+
code: RefusalCode
|
|
137
|
+
plugin: str
|
|
138
|
+
subject: str
|
|
139
|
+
detail: str
|
|
140
|
+
expected: str | int | None = None
|
|
141
|
+
actual: str | int | None = None
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
class ContractError(ValueError):
|
|
145
|
+
def __init__(self, refusal: Refusal) -> None:
|
|
146
|
+
self.refusal = refusal
|
|
147
|
+
super().__init__(
|
|
148
|
+
f"{refusal.code.value} for {refusal.plugin}/{refusal.subject}: {refusal.detail}"
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
@dataclass(frozen=True, slots=True)
|
|
153
|
+
class SourceBounds:
|
|
154
|
+
max_payload_bytes: int
|
|
155
|
+
max_tail_bytes: int | None
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
@dataclass(frozen=True, slots=True)
|
|
159
|
+
class SourceSpec:
|
|
160
|
+
id: str
|
|
161
|
+
dialect: str
|
|
162
|
+
dialect_version: int
|
|
163
|
+
schema_ref: str
|
|
164
|
+
transport: Transport
|
|
165
|
+
bounds: SourceBounds
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
@dataclass(frozen=True, slots=True)
|
|
169
|
+
class PanelSpec:
|
|
170
|
+
id: str
|
|
171
|
+
sources: tuple[str, ...]
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
@dataclass(frozen=True, slots=True)
|
|
175
|
+
class CursorSpec:
|
|
176
|
+
id: str
|
|
177
|
+
schema_ref: str
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
@dataclass(frozen=True, slots=True)
|
|
181
|
+
class ViewSpec:
|
|
182
|
+
id: str
|
|
183
|
+
panel: str
|
|
184
|
+
density: Density
|
|
185
|
+
primitive: PrimitiveKind
|
|
186
|
+
emits: tuple[str, ...]
|
|
187
|
+
consumes: tuple[str, ...]
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
@dataclass(frozen=True, slots=True)
|
|
191
|
+
class ToolVerb:
|
|
192
|
+
id: str
|
|
193
|
+
approval: ApprovalTier
|
|
194
|
+
input_schema_ref: str
|
|
195
|
+
output_schema_ref: str
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
@dataclass(frozen=True, slots=True)
|
|
199
|
+
class ToolSpec:
|
|
200
|
+
name: str
|
|
201
|
+
verbs: tuple[ToolVerb, ...]
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
@dataclass(frozen=True, slots=True)
|
|
205
|
+
class EntrypointSpec:
|
|
206
|
+
skill: str | None
|
|
207
|
+
context: str | None
|
|
208
|
+
renderer: str | None
|
|
209
|
+
tool: str | None
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
@dataclass(frozen=True, slots=True)
|
|
213
|
+
class Manifest:
|
|
214
|
+
id: str
|
|
215
|
+
version: str
|
|
216
|
+
synth_api: int
|
|
217
|
+
activation: Activation
|
|
218
|
+
permissions: frozenset[Permission]
|
|
219
|
+
entrypoints: EntrypointSpec
|
|
220
|
+
sources: tuple[SourceSpec, ...]
|
|
221
|
+
panels: tuple[PanelSpec, ...]
|
|
222
|
+
cursors: tuple[CursorSpec, ...]
|
|
223
|
+
views: tuple[ViewSpec, ...]
|
|
224
|
+
tool: ToolSpec | None
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
@dataclass(frozen=True, slots=True)
|
|
228
|
+
class Pin:
|
|
229
|
+
source_id: str
|
|
230
|
+
view_id: str
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
@dataclass(frozen=True, slots=True)
|
|
234
|
+
class ToolReceipt:
|
|
235
|
+
result: JsonObject
|
|
236
|
+
pin: Pin | None = None
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""Entry points supplied by the Synth Code wheel or its source checkout."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import tomllib
|
|
6
|
+
from collections.abc import Iterator
|
|
7
|
+
from importlib.metadata import (
|
|
8
|
+
EntryPoint,
|
|
9
|
+
PackageNotFoundError,
|
|
10
|
+
distribution,
|
|
11
|
+
entry_points,
|
|
12
|
+
)
|
|
13
|
+
from itertools import islice
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
|
|
16
|
+
_PACK_LIMIT = 16
|
|
17
|
+
_DISTRIBUTION = "synth-code"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class BundledEntriesMissing(LookupError):
|
|
21
|
+
"""No synth-code distribution on sys.path declares the requested entry-point group.
|
|
22
|
+
|
|
23
|
+
The usual cause is stale metadata (for example an ignored ``synth_code.egg-info``
|
|
24
|
+
in a source checkout) earlier on ``sys.path`` than the installed wheel's
|
|
25
|
+
``dist-info``; ``resolved`` names the metadata the import system actually found.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
def __init__(self, group: str, resolved: str) -> None:
|
|
29
|
+
self.group = group
|
|
30
|
+
self.resolved = resolved
|
|
31
|
+
super().__init__(
|
|
32
|
+
f"bundled_entries_missing: no {_DISTRIBUTION} distribution provides entry-point "
|
|
33
|
+
f"group {group!r}; distribution({_DISTRIBUTION!r}) resolved to {resolved}"
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def bundled_entries(group: str) -> Iterator[EntryPoint]:
|
|
38
|
+
checkout = Path(__file__).resolve().parents[2] / "pyproject.toml"
|
|
39
|
+
# The adjacent manifest is available to the development launcher and the test harness.
|
|
40
|
+
if checkout.is_file():
|
|
41
|
+
yield from checkout_entries(checkout, group)
|
|
42
|
+
return
|
|
43
|
+
yield from installed_entries(group)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def checkout_entries(manifest: Path, group: str) -> Iterator[EntryPoint]:
|
|
47
|
+
with manifest.open("rb") as stream:
|
|
48
|
+
groups = tomllib.load(stream)["project"].get("entry-points", {})
|
|
49
|
+
declared = groups.get(group)
|
|
50
|
+
if not declared:
|
|
51
|
+
raise BundledEntriesMissing(group, str(manifest))
|
|
52
|
+
for name, target in islice(declared.items(), _PACK_LIMIT):
|
|
53
|
+
yield EntryPoint(name, target, group)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def installed_entries(group: str) -> Iterator[EntryPoint]:
|
|
57
|
+
"""Yield the group's entry points from installed synth-code metadata, or refuse."""
|
|
58
|
+
found = [
|
|
59
|
+
point
|
|
60
|
+
for point in islice(entry_points(group=group), _PACK_LIMIT)
|
|
61
|
+
if point.dist is not None
|
|
62
|
+
and point.dist.metadata["Name"].lower() == _DISTRIBUTION
|
|
63
|
+
]
|
|
64
|
+
if not found:
|
|
65
|
+
raise BundledEntriesMissing(group, _resolved_metadata())
|
|
66
|
+
yield from found
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _resolved_metadata() -> str:
|
|
70
|
+
try:
|
|
71
|
+
dist = distribution(_DISTRIBUTION)
|
|
72
|
+
except PackageNotFoundError:
|
|
73
|
+
return "no installed distribution"
|
|
74
|
+
located = getattr(dist, "_path", None)
|
|
75
|
+
return str(located) if located is not None else repr(dist)
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""Publish a stable typed pin for a backend job observed after an authorized launch."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
from .contracts import Pin
|
|
8
|
+
|
|
9
|
+
_ATTEMPTS_MAX = 4
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(frozen=True, slots=True)
|
|
13
|
+
class JobAnchor:
|
|
14
|
+
run: str
|
|
15
|
+
turn: str
|
|
16
|
+
tool_id: str
|
|
17
|
+
|
|
18
|
+
def __post_init__(self) -> None:
|
|
19
|
+
for identity in (self.run, self.turn, self.tool_id):
|
|
20
|
+
if not isinstance(identity, str) or not 0 < len(identity) <= 128:
|
|
21
|
+
raise ValueError(
|
|
22
|
+
"A job anchor requires a bounded run, turn, and tool identity"
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def install(gateway, anchor: JobAnchor, pin: Pin) -> None:
|
|
27
|
+
"""Preserve workspace layout while admitting the exact source and native tool tuple."""
|
|
28
|
+
binding = {
|
|
29
|
+
"run": anchor.run,
|
|
30
|
+
"turn": anchor.turn,
|
|
31
|
+
"tool_id": anchor.tool_id,
|
|
32
|
+
"source_id": pin.source_id,
|
|
33
|
+
"view_id": pin.view_id,
|
|
34
|
+
}
|
|
35
|
+
for _ in range(_ATTEMPTS_MAX):
|
|
36
|
+
state = gateway.send("ui_manage", action="observe", args={})
|
|
37
|
+
if not isinstance(state, dict) or type(state.get("revision")) is not int:
|
|
38
|
+
raise ValueError("Invalid layout observation for plugin job pin")
|
|
39
|
+
layout = state["layout"]
|
|
40
|
+
pins = layout["pins"]
|
|
41
|
+
if binding in pins:
|
|
42
|
+
return
|
|
43
|
+
if any(
|
|
44
|
+
all(
|
|
45
|
+
existing.get(field) == binding[field]
|
|
46
|
+
for field in ("run", "turn", "tool_id")
|
|
47
|
+
)
|
|
48
|
+
for existing in pins
|
|
49
|
+
):
|
|
50
|
+
raise ValueError("The native tool already has a different source pin")
|
|
51
|
+
try:
|
|
52
|
+
gateway.send(
|
|
53
|
+
"ui_manage",
|
|
54
|
+
action="author",
|
|
55
|
+
args={
|
|
56
|
+
"expected_revision": state["revision"],
|
|
57
|
+
"layout": {**layout, "pins": [*pins, binding]},
|
|
58
|
+
},
|
|
59
|
+
)
|
|
60
|
+
except ValueError as error:
|
|
61
|
+
refusal = getattr(error, "refusal", None)
|
|
62
|
+
if (
|
|
63
|
+
not isinstance(refusal, dict)
|
|
64
|
+
or refusal.get("code") != "view_revision_conflict"
|
|
65
|
+
):
|
|
66
|
+
raise
|
|
67
|
+
else:
|
|
68
|
+
return
|
|
69
|
+
raise ValueError(
|
|
70
|
+
"Workspace layout changed before the plugin job pin could be bound"
|
|
71
|
+
)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Apply the Temper plugin lifecycle at SDK activation boundaries."""
|
|
2
|
+
|
|
3
|
+
from enum import StrEnum
|
|
4
|
+
|
|
5
|
+
from .contracts import Lifecycle
|
|
6
|
+
from .lifecycle_generated import TRANSITIONS
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Action(StrEnum):
|
|
10
|
+
VALIDATE = "validate"
|
|
11
|
+
MOUNT = "mount"
|
|
12
|
+
ACTIVATE = "activate"
|
|
13
|
+
DEGRADE = "degrade"
|
|
14
|
+
RECOVER = "recover"
|
|
15
|
+
UNMOUNT = "unmount"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class TransitionRefused(ValueError):
|
|
19
|
+
def __init__(self, phase: Lifecycle, action: Action) -> None:
|
|
20
|
+
super().__init__(f"Plugin lifecycle refuses {action.value} from {phase.value}")
|
|
21
|
+
self.phase = phase
|
|
22
|
+
self.action = action
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class PluginLifecycle:
|
|
26
|
+
def __init__(self) -> None:
|
|
27
|
+
self._phase = Lifecycle.DISCOVERED
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
def phase(self) -> Lifecycle:
|
|
31
|
+
return self._phase
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def serving(self) -> bool:
|
|
35
|
+
return self._phase in (Lifecycle.ACTIVE, Lifecycle.DEGRADED)
|
|
36
|
+
|
|
37
|
+
def permits(self, action: Action) -> bool:
|
|
38
|
+
return (self._phase.value, action.value) in TRANSITIONS
|
|
39
|
+
|
|
40
|
+
def advance(self, action: Action) -> None:
|
|
41
|
+
target = TRANSITIONS.get((self._phase.value, action.value))
|
|
42
|
+
if target is None:
|
|
43
|
+
raise TransitionRefused(self._phase, action)
|
|
44
|
+
self._phase = Lifecycle(target)
|
|
45
|
+
|
|
46
|
+
def observe_health(self, *, degraded: bool) -> None:
|
|
47
|
+
if degraded and self._phase is Lifecycle.ACTIVE:
|
|
48
|
+
self.advance(Action.DEGRADE)
|
|
49
|
+
elif not degraded and self._phase is Lifecycle.DEGRADED:
|
|
50
|
+
self.advance(Action.RECOVER)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Generated from specs/plugin.ioa.toml by scripts/generate_plugin_lifecycle.py."""
|
|
2
|
+
|
|
3
|
+
TRANSITIONS = {
|
|
4
|
+
("active", "degrade"): "degraded",
|
|
5
|
+
("active", "unmount"): "unmounted",
|
|
6
|
+
("degraded", "recover"): "active",
|
|
7
|
+
("degraded", "unmount"): "unmounted",
|
|
8
|
+
("discovered", "validate"): "validated",
|
|
9
|
+
("mounted", "activate"): "active",
|
|
10
|
+
("mounted", "unmount"): "unmounted",
|
|
11
|
+
("unmounted", "mount"): "mounted",
|
|
12
|
+
("unmounted", "unmount"): "unmounted",
|
|
13
|
+
("validated", "mount"): "mounted",
|
|
14
|
+
("validated", "unmount"): "unmounted",
|
|
15
|
+
}
|