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,93 @@
1
+ """Bounded display primitives, responsive tiling, and view frame rendering."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from .charts import Heatmap, Point, Scatter, Series
6
+ from .curses_adapter import (
7
+ CaptureRefused,
8
+ CursesGeometry,
9
+ Rect,
10
+ capture_slot,
11
+ paint_views,
12
+ )
13
+ from .engine import Renderer, ViewEngine
14
+ from .model import (
15
+ Capture,
16
+ Cursor,
17
+ CursorBinding,
18
+ Density,
19
+ Extent,
20
+ Health,
21
+ Layout,
22
+ Placement,
23
+ RenderedSlot,
24
+ Slot,
25
+ SlotFault,
26
+ Style,
27
+ StyledLine,
28
+ Tiling,
29
+ ViewFrame,
30
+ ViewMount,
31
+ Viewport,
32
+ )
33
+ from .primitives import (
34
+ Card,
35
+ Content,
36
+ Diff,
37
+ DiffKind,
38
+ DiffLine,
39
+ LogTail,
40
+ Metric,
41
+ Metrics,
42
+ Pill,
43
+ Progress,
44
+ RenderContext,
45
+ SourceSnapshot,
46
+ Table,
47
+ TableRow,
48
+ )
49
+
50
+ __all__ = [
51
+ "Capture",
52
+ "CaptureRefused",
53
+ "Card",
54
+ "Content",
55
+ "CursesGeometry",
56
+ "Cursor",
57
+ "CursorBinding",
58
+ "Density",
59
+ "Diff",
60
+ "DiffKind",
61
+ "DiffLine",
62
+ "Extent",
63
+ "Health",
64
+ "Heatmap",
65
+ "Layout",
66
+ "LogTail",
67
+ "Metric",
68
+ "Metrics",
69
+ "Pill",
70
+ "Placement",
71
+ "Point",
72
+ "Progress",
73
+ "Rect",
74
+ "RenderContext",
75
+ "RenderedSlot",
76
+ "Renderer",
77
+ "Scatter",
78
+ "Series",
79
+ "Slot",
80
+ "SlotFault",
81
+ "SourceSnapshot",
82
+ "Style",
83
+ "StyledLine",
84
+ "Table",
85
+ "TableRow",
86
+ "Tiling",
87
+ "ViewEngine",
88
+ "ViewFrame",
89
+ "ViewMount",
90
+ "Viewport",
91
+ "capture_slot",
92
+ "paint_views",
93
+ ]
@@ -0,0 +1,196 @@
1
+ """Text charts for bounded numerical source snapshots."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import math
6
+ from collections.abc import Iterator
7
+ from dataclasses import dataclass
8
+ from typing import TYPE_CHECKING, TypeVar
9
+
10
+ from .model import Density, Style, StyledLine
11
+
12
+ if TYPE_CHECKING:
13
+ from .primitives import RenderContext
14
+
15
+ __all__ = ["Heatmap", "Point", "Scatter", "Series", "render_chart"]
16
+
17
+ Number = float | int
18
+ Measurement = Number | None
19
+ T = TypeVar("T")
20
+
21
+ _MAX_POINTS = 4096
22
+ _MAX_GRID_SIDE = 64
23
+ _MAX_PLOT_COLUMNS = 64
24
+ _UNKNOWN = "·"
25
+
26
+
27
+ def _check_number(value: Measurement) -> None:
28
+ if value is None:
29
+ return
30
+ if type(value) is int and abs(value) <= 1 << 53:
31
+ return
32
+ if type(value) is float and math.isfinite(value):
33
+ return
34
+ raise ValueError("chart values must be absent, finite floats, or exact binary64 integers")
35
+
36
+
37
+ def _check_length(values: tuple[T, ...], maximum: int) -> None:
38
+ if len(values) > maximum:
39
+ raise ValueError(f"chart has {len(values)} items, maximum {maximum}")
40
+
41
+
42
+ @dataclass(frozen=True, slots=True)
43
+ class Series:
44
+ label: str
45
+ values: tuple[Measurement, ...]
46
+
47
+ def __post_init__(self) -> None:
48
+ _check_length(self.values, _MAX_POINTS)
49
+ for value in self.values:
50
+ _check_number(value)
51
+
52
+
53
+ @dataclass(frozen=True, slots=True)
54
+ class Heatmap:
55
+ label: str
56
+ cells: tuple[tuple[Measurement, ...], ...]
57
+
58
+ def __post_init__(self) -> None:
59
+ _check_length(self.cells, _MAX_GRID_SIDE)
60
+ if not self.cells:
61
+ return
62
+ width = len(self.cells[0])
63
+ for row in self.cells:
64
+ _check_length(row, _MAX_GRID_SIDE)
65
+ if len(row) != width:
66
+ raise ValueError(f"heatmap row has {len(row)} cells, expected {width}")
67
+ for value in row:
68
+ _check_number(value)
69
+
70
+
71
+ @dataclass(frozen=True, slots=True)
72
+ class Point:
73
+ x: Measurement
74
+ y: Measurement
75
+
76
+ def __post_init__(self) -> None:
77
+ _check_number(self.x)
78
+ _check_number(self.y)
79
+
80
+
81
+ @dataclass(frozen=True, slots=True)
82
+ class Scatter:
83
+ label: str
84
+ points: tuple[Point, ...]
85
+
86
+ def __post_init__(self) -> None:
87
+ _check_length(self.points, _MAX_POINTS)
88
+
89
+
90
+ @dataclass(frozen=True, slots=True)
91
+ class Scale:
92
+ low: Number
93
+ high: Number
94
+
95
+ def bucket(self, value: Number, upper: int) -> int:
96
+ if self.low == self.high:
97
+ return upper // 2
98
+ if value == self.high:
99
+ return upper
100
+ # For opposite-signed extremes, high - low may overflow.
101
+ norm = max(abs(self.low), abs(self.high))
102
+ low = self.low / norm
103
+ high = self.high / norm
104
+ normalized = value / norm
105
+ if high == low:
106
+ fraction = (value - self.low) / (self.high - self.low)
107
+ else:
108
+ fraction = (normalized - low) / (high - low)
109
+ return min(upper, max(0, int(fraction * upper)))
110
+
111
+
112
+ def _sample(values: tuple[T, ...], limit: int) -> tuple[T, ...]:
113
+ if len(values) <= limit:
114
+ return values
115
+ if limit == 1:
116
+ return values[-1:]
117
+ return tuple(values[index * (len(values) - 1) // (limit - 1)] for index in range(limit))
118
+
119
+
120
+ def _strip(values: tuple[Measurement, ...], glyphs: str, scale: Scale, columns: int) -> str:
121
+ return "".join(
122
+ _UNKNOWN if value is None else glyphs[scale.bucket(value, len(glyphs) - 1)]
123
+ for value in _sample(values, columns)
124
+ )
125
+
126
+
127
+ def _series(content: Series, context: RenderContext) -> Iterator[StyledLine]:
128
+ known = [value for value in content.values if value is not None]
129
+ if not known:
130
+ yield StyledLine("No measurements", Style.MUTED)
131
+ return
132
+ scale = Scale(min(known), max(known))
133
+ columns = min(context.columns, _MAX_PLOT_COLUMNS)
134
+ plot = _strip(content.values, "▁▂▃▄▅▆▇█", scale, columns)
135
+ if context.rows == 1:
136
+ yield StyledLine(plot)
137
+ return
138
+ yield StyledLine(content.label, Style.HEADING)
139
+ yield StyledLine(plot)
140
+ if context.density == Density.FULL:
141
+ yield StyledLine(f"{scale.low} … {scale.high}", Style.MUTED)
142
+
143
+
144
+ def _heatmap(content: Heatmap, context: RenderContext) -> Iterator[StyledLine]:
145
+ known = [value for row in content.cells for value in row if value is not None]
146
+ if not known:
147
+ yield StyledLine("No measurements", Style.MUTED)
148
+ return
149
+ scale = Scale(min(known), max(known))
150
+ columns = min(context.columns, _MAX_PLOT_COLUMNS)
151
+ rows = context.rows
152
+ if rows > 1:
153
+ yield StyledLine(content.label, Style.HEADING)
154
+ rows -= 1
155
+ for row in _sample(content.cells, rows):
156
+ yield StyledLine(_strip(row, "░▒▓█", scale, columns))
157
+
158
+
159
+ def _scatter(content: Scatter, context: RenderContext) -> Iterator[StyledLine]:
160
+ points = [
161
+ (point.x, point.y)
162
+ for point in content.points
163
+ if point.x is not None and point.y is not None
164
+ ]
165
+ if not points:
166
+ yield StyledLine("No measured points", Style.MUTED)
167
+ return
168
+ known = f"{len(points)}/{len(content.points)} points"
169
+ heading = f"{content.label[:128]} · {known}"
170
+ yield StyledLine(heading, Style.HEADING)
171
+ if context.rows == 1:
172
+ return
173
+ xs, ys = zip(*points, strict=True)
174
+ horizontal = Scale(min(xs), max(xs))
175
+ vertical = Scale(min(ys), max(ys))
176
+ height = context.rows - 1
177
+ width = min(context.columns, _MAX_PLOT_COLUMNS)
178
+ plot = [[" "] * width for _ in range(height)]
179
+ for x, y in points:
180
+ col = horizontal.bucket(x, width - 1)
181
+ row = height - 1 - vertical.bucket(y, height - 1)
182
+ plot[row][col] = "•"
183
+ for row in plot:
184
+ yield StyledLine("".join(row).rstrip())
185
+
186
+
187
+ def render_chart(
188
+ content: Series | Heatmap | Scatter, context: RenderContext
189
+ ) -> Iterator[StyledLine]:
190
+ match content:
191
+ case Series():
192
+ yield from _series(content, context)
193
+ case Heatmap():
194
+ yield from _heatmap(content, context)
195
+ case Scatter():
196
+ yield from _scatter(content, context)
@@ -0,0 +1,116 @@
1
+ """Feed a view frame into the terminal's existing synchronized frame painter."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Callable, Mapping
6
+ from dataclasses import dataclass
7
+ from itertools import combinations
8
+ from types import MappingProxyType
9
+
10
+ from .engine import ViewEngine
11
+ from .model import Capture, Extent, Layout, RenderedSlot, Slot, ViewFrame
12
+ from .primitives import SourceSnapshot
13
+
14
+ __all__ = ["CaptureRefused", "CursesGeometry", "Rect", "capture_slot", "paint_views"]
15
+
16
+ Painter = Callable[[int, int, str, int, str], None]
17
+
18
+
19
+ @dataclass(frozen=True, slots=True)
20
+ class Rect:
21
+ row: int
22
+ col: int
23
+ columns: int
24
+ rows: int
25
+
26
+ def __post_init__(self) -> None:
27
+ if min(self.row, self.col, self.columns, self.rows) < 0:
28
+ raise ValueError(f"screen rectangle has a negative coordinate or extent: {self}")
29
+
30
+ @property
31
+ def right(self) -> int:
32
+ return self.col + self.columns
33
+
34
+ @property
35
+ def bottom(self) -> int:
36
+ return self.row + self.rows
37
+
38
+ def overlaps(self, other: Rect) -> bool:
39
+ return min(self.right, other.right) > max(self.col, other.col) and min(
40
+ self.bottom, other.bottom
41
+ ) > max(self.row, other.row)
42
+
43
+
44
+ @dataclass(frozen=True, slots=True)
45
+ class CursesGeometry:
46
+ """Absolute screen cells allocated by the existing terminal layout.
47
+
48
+ The caller reserves all body text, composer, menu, and approval cells that
49
+ plugins must leave alone. Disabled plugin regions are absent from the map.
50
+ """
51
+
52
+ columns: int
53
+ rows: int
54
+ regions: Mapping[Slot, Rect]
55
+ protected: tuple[Rect, ...]
56
+
57
+ def __post_init__(self) -> None:
58
+ if self.columns <= 0 or self.rows <= 0:
59
+ raise ValueError(
60
+ f"screen must have positive dimensions, got {self.columns}×{self.rows}"
61
+ )
62
+ for rect in self.protected:
63
+ if rect.bottom > self.rows or rect.right > self.columns:
64
+ raise ValueError(f"protected region {rect} exceeds screen cells")
65
+ regions = dict(self.regions)
66
+ for slot, rect in regions.items():
67
+ margin = 2 if rect.bottom == self.rows and self.columns > 3 else 1
68
+ if rect.bottom > self.rows or rect.right > self.columns - margin:
69
+ raise ValueError(f"{slot} region {rect} exceeds writable screen cells")
70
+ if any(rect.overlaps(protected) for protected in self.protected):
71
+ raise ValueError(f"{slot} region {rect} overlaps protected screen cells")
72
+ for left, right in combinations(regions, 2):
73
+ if regions[left].overlaps(regions[right]):
74
+ raise ValueError(f"{left} and {right} regions overlap")
75
+ object.__setattr__(self, "regions", MappingProxyType(regions))
76
+
77
+
78
+ class CaptureRefused(ValueError):
79
+ """The requested cell slice has no exact capture binding."""
80
+
81
+
82
+ def capture_slot(frame: ViewFrame, slot: Slot, row: int, *, expected: Capture) -> RenderedSlot:
83
+ """Read rendered lines at a routed slot and row for a precise source revision."""
84
+ if frame.revision != expected.view_revision:
85
+ raise CaptureRefused(
86
+ f"expected view revision {expected.view_revision}, painted {frame.revision}"
87
+ )
88
+ for item in frame.slots:
89
+ if item.placement.slot != slot or item.placement.row != row:
90
+ continue
91
+ if item.capture != expected:
92
+ raise CaptureRefused(f"expected capture {expected}, painted {item.capture}")
93
+ return item
94
+ raise CaptureRefused(f"no painted view at {slot} row {row} for revision {frame.revision}")
95
+
96
+
97
+ def paint_views(
98
+ engine: ViewEngine,
99
+ layout: Layout,
100
+ sources: Mapping[str, SourceSnapshot],
101
+ geometry: CursesGeometry,
102
+ put: Painter,
103
+ ) -> ViewFrame:
104
+ """Queue bounded styled lines without changing focus, cursor, or refresh state."""
105
+ frame = engine.render_regions(
106
+ layout,
107
+ sources,
108
+ columns=geometry.columns,
109
+ regions={slot: Extent(rect.columns, rect.rows) for slot, rect in geometry.regions.items()},
110
+ )
111
+ for item in frame.slots:
112
+ placement = item.placement
113
+ rect = geometry.regions[placement.slot]
114
+ for offset, line in enumerate(item.lines, start=placement.row):
115
+ put(rect.row + offset, rect.col, line.text, placement.columns, line.style.value)
116
+ return frame
@@ -0,0 +1,170 @@
1
+ """Apply a layout and one pushed source snapshot to a surface viewport."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Callable, Iterable, Mapping
6
+ from itertools import islice
7
+
8
+ from ..view import fit_cells
9
+ from .model import (
10
+ Capture,
11
+ Extent,
12
+ Health,
13
+ Layout,
14
+ Placement,
15
+ RenderedSlot,
16
+ Slot,
17
+ SlotFault,
18
+ Style,
19
+ StyledLine,
20
+ ViewFrame,
21
+ ViewMount,
22
+ Viewport,
23
+ )
24
+ from .primitives import (
25
+ TEXT_SCAN_LIMIT,
26
+ Content,
27
+ RenderContext,
28
+ SourceSnapshot,
29
+ render_content,
30
+ )
31
+ from .tiling import Router, viewport_extents
32
+
33
+ __all__ = ["Renderer", "ViewEngine"]
34
+
35
+ Renderer = Callable[[Content, RenderContext], Iterable[StyledLine]]
36
+
37
+ MAX_LINE_CHARS = 512
38
+ _MAX_CHARS_PER_COLUMN = 4
39
+ _NO_DATA = StyledLine("No data", Style.MUTED)
40
+ _HEALTH_STYLE = {
41
+ Health.CONNECTED: Style.NORMAL,
42
+ Health.STALE: Style.WARNING,
43
+ Health.IN_DOUBT: Style.WARNING,
44
+ Health.UNAVAILABLE: Style.WARNING,
45
+ Health.ERROR: Style.ERROR,
46
+ }
47
+
48
+
49
+ def _fit(line: StyledLine, columns: int) -> StyledLine:
50
+ if not isinstance(line, StyledLine) or not isinstance(line.style, Style):
51
+ raise TypeError("renderer must yield StyledLine records with a valid Style")
52
+ if line.key is not None and not isinstance(line.key, str):
53
+ raise TypeError("renderer line key must be text or absent")
54
+ if not isinstance(line.text, str):
55
+ raise TypeError("renderer line text must be text")
56
+ chars = min(MAX_LINE_CHARS, columns * _MAX_CHARS_PER_COLUMN)
57
+ text = fit_cells(line.text[:TEXT_SCAN_LIMIT], columns)[:chars]
58
+ return StyledLine(text, line.style, line.key)
59
+
60
+
61
+ class ViewEngine:
62
+ """Stateless frame renderer. Plugins pass already-received typed content.
63
+
64
+ Optional renderers are synchronous, pure formatters. The source adapter owns
65
+ data acquisition, timeouts, and source health.
66
+ """
67
+
68
+ def __init__(self, renderers: Mapping[str, Renderer] | None = None) -> None:
69
+ self._renderers = {} if renderers is None else dict(renderers)
70
+
71
+ def render(
72
+ self, layout: Layout, viewport: Viewport, sources: Mapping[str, SourceSnapshot]
73
+ ) -> ViewFrame:
74
+ return self.render_regions(
75
+ layout, sources, columns=viewport.columns, regions=viewport_extents(viewport)
76
+ )
77
+
78
+ def render_regions(
79
+ self,
80
+ layout: Layout,
81
+ sources: Mapping[str, SourceSnapshot],
82
+ *,
83
+ columns: int,
84
+ regions: Mapping[Slot, Extent],
85
+ ) -> ViewFrame:
86
+ """Render to exact independent slot extents supplied by a surface adapter."""
87
+ router = Router(layout.tiling, columns, regions)
88
+ cursors = {cursor.channel: cursor.key for cursor in layout.cursors}
89
+ slots: list[RenderedSlot] = []
90
+ hidden: list[ViewMount] = []
91
+ for mount, placement in zip(layout.mounts, router.plan(layout.mounts), strict=True):
92
+ if placement is None:
93
+ hidden.append(mount)
94
+ continue
95
+ selected = cursors.get(mount.consumes.channel) if mount.consumes is not None else None
96
+ rendered = self._render_mount(
97
+ mount, placement, layout.revision, sources.get(mount.source_id), selected
98
+ )
99
+ slots.append(rendered)
100
+ return ViewFrame(layout.revision, tuple(slots), tuple(hidden))
101
+
102
+ def _render_mount(
103
+ self,
104
+ mount: ViewMount,
105
+ placement: Placement,
106
+ revision: int,
107
+ source: SourceSnapshot | None,
108
+ selected: str | None,
109
+ ) -> RenderedSlot:
110
+ capture = Capture(
111
+ revision,
112
+ source.seq if isinstance(source, SourceSnapshot) else None,
113
+ mount.view_id,
114
+ mount.source_id,
115
+ )
116
+ if source is None:
117
+ line = _fit(
118
+ StyledLine("[unavailable] Source missing", Style.WARNING), placement.columns
119
+ )
120
+ return RenderedSlot(
121
+ mount, placement, capture, (line,), Health.UNAVAILABLE, SlotFault.SOURCE_MISSING
122
+ )
123
+ if not isinstance(source, SourceSnapshot):
124
+ line = _fit(StyledLine("[error] Invalid source", Style.ERROR), placement.columns)
125
+ return RenderedSlot(
126
+ mount, placement, capture, (line,), Health.ERROR, SlotFault.SOURCE_INVALID
127
+ )
128
+ try:
129
+ lines = self._render_source(mount.view_id, placement, source, selected)
130
+ except Exception as error: # noqa: BLE001 - isolate arbitrary plugin renderers
131
+ # The fault belongs to this renderer invocation. Exception text can
132
+ # contain unbounded input or private source data.
133
+ reason = type(error).__name__[:64]
134
+ line = _fit(
135
+ StyledLine(f"[error] View failed ({reason})", Style.ERROR), placement.columns
136
+ )
137
+ return RenderedSlot(
138
+ mount, placement, capture, (line,), source.health, SlotFault.VIEW_FAILED
139
+ )
140
+ keys = tuple(line.key for line in lines if line.key is not None)
141
+ return RenderedSlot(mount, placement, capture, lines, source.health, selectable_keys=keys)
142
+
143
+ def _render_source(
144
+ self, view_id: str, placement: Placement, source: SourceSnapshot, selected: str | None
145
+ ) -> tuple[StyledLine, ...]:
146
+ badge = f"[{source.health.value}]"
147
+ style = _HEALTH_STYLE[source.health]
148
+ if source.health in (Health.UNAVAILABLE, Health.ERROR):
149
+ return (_fit(StyledLine(badge, style), placement.columns),)
150
+
151
+ degraded = source.health != Health.CONNECTED
152
+ own_badge_row = degraded and placement.rows > 1
153
+ rows = placement.rows - own_badge_row
154
+ context = RenderContext(placement.density, placement.columns, rows, selected)
155
+ renderer = self._renderers.get(view_id, render_content)
156
+ if source.content is None:
157
+ body = (_fit(_NO_DATA, placement.columns),)
158
+ else:
159
+ body = tuple(
160
+ _fit(line, placement.columns)
161
+ for line in islice(renderer(source.content, context), rows)
162
+ )
163
+ if not body:
164
+ body = (_fit(_NO_DATA, placement.columns),)
165
+ if own_badge_row:
166
+ return (_fit(StyledLine(badge, style), placement.columns), *body)
167
+ if degraded:
168
+ line = body[0]
169
+ return (_fit(StyledLine(f"{badge} {line.text}", style, line.key), placement.columns),)
170
+ return body