zettcode-plugin-api 0.4.0__tar.gz

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.
@@ -0,0 +1,37 @@
1
+ **/.venv/
2
+ **/__pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ build/
6
+ dist/
7
+ .smoke/
8
+ .coverage
9
+ **/.pytest_cache/
10
+ **/.ruff_cache/
11
+ .zett-tool-output/
12
+ .env
13
+ .DS_Store
14
+
15
+ # viztracer writes its trace here by default.
16
+ /result.json
17
+
18
+ # The docs site: dependencies, build output, and VitePress' cache.
19
+ node_modules/
20
+ docs/.vitepress/dist/
21
+ docs/.vitepress/cache/
22
+ docs/.vitepress/.temp/
23
+
24
+ # The TypeScript client is built from its sources; only dist/ is published.
25
+ clients/typescript/dist/
26
+
27
+ # The gateway's page is built from clients/gateway into the package when a distribution is made (`make gateway-ui`);
28
+ # the build output is not kept in the repository. pyproject's `artifacts` puts it in the wheel all the same.
29
+ packages/zettcode-gateway/src/zettcode/gateway/static/
30
+
31
+ # The palette gallery is generated by `make palettes`: every widget painted in
32
+ # every palette, written by docs/scripts/palette_gallery.py. Regenerate it
33
+ # rather than committing a 2 MB copy that goes stale the moment a colour moves.
34
+ docs/internal/palettes.html
35
+
36
+ # The release order is generated from the pyproject.toml files (`make order`); it is not kept in git.
37
+ packages/order.txt
@@ -0,0 +1,21 @@
1
+ Metadata-Version: 2.5
2
+ Name: zettcode-plugin-api
3
+ Version: 0.4.0
4
+ Summary: The one package a ZettCode plugin depends on: the plugin surface, re-exported
5
+ Project-URL: Repository, https://github.com/Chang-LeHung/zettcode
6
+ Author: Chang-LeHung
7
+ License-Expression: MIT
8
+ Keywords: api,plugin,zettcode
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Classifier: Programming Language :: Python :: 3.15
16
+ Classifier: Typing :: Typed
17
+ Requires-Python: >=3.10
18
+ Requires-Dist: zettcode-engine
19
+ Requires-Dist: zettcode-tui
20
+ Provides-Extra: types
21
+ Requires-Dist: zettcode-sdk; extra == 'types'
@@ -0,0 +1,52 @@
1
+ [project]
2
+ name = "zettcode-plugin-api"
3
+ description = "The one package a ZettCode plugin depends on: the plugin surface, re-exported"
4
+ requires-python = ">=3.10"
5
+ dynamic = ["version"]
6
+ license = "MIT"
7
+ authors = [{name = "Chang-LeHung"}]
8
+ keywords = ["zettcode", "plugin", "api"]
9
+ classifiers = [
10
+ "Development Status :: 5 - Production/Stable",
11
+ "Programming Language :: Python :: 3.10",
12
+ "Programming Language :: Python :: 3.11",
13
+ "Programming Language :: Python :: 3.12",
14
+ "Programming Language :: Python :: 3.13",
15
+ "Programming Language :: Python :: 3.14",
16
+ "Programming Language :: Python :: 3.15",
17
+ "Typing :: Typed",
18
+ ]
19
+ dependencies = [
20
+ # The bottom of the graph a plugin lives in: the runtime it hooks into and the widgets it draws with. Never the
21
+ # application, never an implementation of what this package defines, and not the SDK -- see the extra below.
22
+ "zettcode-engine",
23
+ "zettcode-tui",
24
+ ]
25
+
26
+ [project.optional-dependencies]
27
+ # `host.client` is the SDK's client and a hook is handed its `Usage` and `ModelInfo`, so a plugin that is type-checked
28
+ # needs the SDK to resolve those names. Nothing is *imported* from it at run time (every one is a `TYPE_CHECKING`
29
+ # reference, and the contract's names all resolve with the SDK unimportable), so a plugin that only runs does not pull
30
+ # the broker's web stack in for it: it asks for this extra when it wants its types.
31
+ types = ["zettcode-sdk"]
32
+
33
+ [project.urls]
34
+ Repository = "https://github.com/Chang-LeHung/zettcode"
35
+
36
+ [build-system]
37
+ requires = ["hatchling"]
38
+ build-backend = "hatchling.build"
39
+
40
+ [tool.hatch.version]
41
+ # One version for the whole repository: the engine ships the file.
42
+ path = "../zettcode-engine/src/zettcode/version.py"
43
+
44
+ [tool.hatch.build.targets.wheel]
45
+ packages = ["src/zettcode"]
46
+
47
+ [tool.hatch.build.targets.sdist]
48
+ include = ["/src", "/pyproject.toml"]
49
+
50
+ [tool.pytest.ini_options]
51
+ testpaths = ["tests"]
52
+ asyncio_mode = "auto"
@@ -0,0 +1,330 @@
1
+ """What a plugin imports: the contract, and the one dependency it needs.
2
+
3
+ A ZettCode plugin is a class published under the ``zettcode.plugins`` entry point, and everything it may touch is
4
+ re-exported here: the base classes and hooks of the agent side and of the terminal's rows, the command a handler returns,
5
+ the row model and the presenter it implements, the pet format, the link to the shell, and the few widgets a panel is
6
+ drawn with.
7
+
8
+ This package is the bottom of the graph a plugin lives in. The engine, the widget framework and the SDK are what it
9
+ needs; it imports neither the terminal application nor any implementation of the contracts it defines. The built-in rows
10
+ (`zettcode-presenters`), the shell and the loader that builds ``ctx.tui`` (`zettcode-app`) are written *against* it, which
11
+ is what lets a plugin and the program replace each other's parts without either importing the other.
12
+
13
+ The names are resolved on first use, like the program's other facades: importing one row constant must not pull the
14
+ settings, the runtime and a provider SDK in with it, because the boot frame is drawn before any of them exist.
15
+
16
+ The names are the ones the guide shows in `docs/guide/plugins.md`. They are re-exports, not a second definition, so a
17
+ plugin and the program cannot disagree about a signature.
18
+ """
19
+
20
+ from __future__ import annotations
21
+
22
+ import importlib
23
+ from typing import TYPE_CHECKING, Any
24
+
25
+ #: Where each public name lives; read by :func:`__getattr__` on first use.
26
+ _EXPORTS = {
27
+ "Activity": ".state",
28
+ "ActivityState": ".state",
29
+ "AgentBuild": "zettcode.engine.plugins",
30
+ "BusyPolicy": ".commands",
31
+ "CONTENT_INDENT": ".presenters",
32
+ "Canvas": "zettcode.tui",
33
+ "ChangesEntry": ".entries",
34
+ "Command": ".commands",
35
+ "CommandAgent": ".commands",
36
+ "CommandContext": ".commands",
37
+ "CommandHandler": ".commands",
38
+ "CommandHost": ".commands",
39
+ "CommandList": ".commands",
40
+ "CommandProvider": ".commands",
41
+ "CommandResult": ".commands",
42
+ "CommandTranscript": ".commands",
43
+ "CommandUi": ".commands",
44
+ "Contribution": "zettcode.engine.plugins",
45
+ "DeleteEntry": ".entries",
46
+ "DisplayState": ".state",
47
+ "EditEntry": ".entries",
48
+ "Entry": ".entries",
49
+ "EntryKind": ".entries",
50
+ "EntryStatus": ".entries",
51
+ "ExtensionFactory": "zettcode.engine.plugins",
52
+ "FileChangeEntry": ".entries",
53
+ "FileSummary": ".entries",
54
+ "HOST_LINK": ".host",
55
+ "Host": "zettcode.tui",
56
+ "HostLink": ".host",
57
+ "MarkdownEntry": ".entries",
58
+ "Mention": "zettcode.mention",
59
+ "MentionProvider": "zettcode.mention",
60
+ "MessageEntry": ".entries",
61
+ "ModelConfig": "zettcode.config",
62
+ "ModelState": ".state",
63
+ "MouseAction": "zettcode.tui",
64
+ "MouseEvent": "zettcode.tui",
65
+ "NoticeLevel": ".entries",
66
+ "Pet": ".pets",
67
+ "PetSource": ".pets",
68
+ "PlainCommandContext": "zettcode.engine.plugins.commands",
69
+ "Plugin": "zettcode.engine.plugins",
70
+ "PluginAgentMixin": "zettcode.engine.plugins",
71
+ "PluginContext": "zettcode.engine.plugins",
72
+ "PluginEventMixin": "zettcode.engine.plugins",
73
+ "PluginExtension": "zettcode.engine.plugins",
74
+ "PluginMaintenanceMixin": "zettcode.engine.plugins",
75
+ "PluginMiddlewareMixin": "zettcode.engine.plugins",
76
+ "PluginModelMixin": "zettcode.engine.plugins",
77
+ "PluginRunMixin": "zettcode.engine.plugins",
78
+ "PluginSetting": "zettcode.engine.plugins",
79
+ "PluginSetupMixin": "zettcode.engine.plugins",
80
+ "PluginToolMixin": "zettcode.engine.plugins",
81
+ "PluginTurnMixin": "zettcode.engine.plugins",
82
+ "PluginUiMixin": ".mixins",
83
+ "Plugins": "zettcode.engine.plugins",
84
+ "Presenter": ".presenters",
85
+ "Presenters": ".presenters",
86
+ "Provider": "zettcode.providers",
87
+ "Rail": ".switch",
88
+ "ReadEntry": ".entries",
89
+ "Registry": "zettcode.registry",
90
+ "RelayEntry": ".entries",
91
+ "Row": ".rows",
92
+ "SWITCH_WIDTH": ".switch",
93
+ "SessionState": ".state",
94
+ "ShellContext": ".state",
95
+ "Span": "zettcode.tui",
96
+ "Style": "zettcode.tui",
97
+ "Subcommand": ".commands",
98
+ "TextCommandResult": "zettcode.engine.plugins.commands",
99
+ "TextEntry": ".entries",
100
+ "TextLine": "zettcode.tui",
101
+ "ThinkingEntry": ".entries",
102
+ "ToolEntry": ".entries",
103
+ "TuiGroup": "zettcode.plugin_tui",
104
+ "TuiPlugin": ".plugin",
105
+ "TuiPlugins": ".plugin",
106
+ "TurnCommandResult": "zettcode.engine.plugins.commands",
107
+ "TurnSegment": ".state",
108
+ "UiBuilder": ".state",
109
+ "UiRegion": ".state",
110
+ "UiRow": ".state",
111
+ "UiSegment": ".state",
112
+ "UiSide": ".state",
113
+ "WaitEntry": ".entries",
114
+ "Widget": "zettcode.tui",
115
+ "WriteEntry": ".entries",
116
+ "ZettCodeConfig": "zettcode.config",
117
+ "blend": "zettcode.tui.render",
118
+ "bottom_panel": ".panels",
119
+ "display_width": "zettcode.tui.render",
120
+ "draw_switch": ".switch",
121
+ "pressed": ".panels",
122
+ "truncate": "zettcode.tui.render",
123
+ }
124
+
125
+
126
+ if TYPE_CHECKING: # pragma: no cover - for type checkers, not the runtime
127
+ from zettcode.config import ModelConfig, ZettCodeConfig
128
+ from zettcode.engine.plugins import (
129
+ AgentBuild,
130
+ Contribution,
131
+ ExtensionFactory,
132
+ Plugin,
133
+ PluginAgentMixin,
134
+ PluginContext,
135
+ PluginEventMixin,
136
+ PluginExtension,
137
+ PluginMaintenanceMixin,
138
+ PluginMiddlewareMixin,
139
+ PluginModelMixin,
140
+ PluginRunMixin,
141
+ Plugins,
142
+ PluginSetting,
143
+ PluginSetupMixin,
144
+ PluginToolMixin,
145
+ PluginTurnMixin,
146
+ )
147
+ from zettcode.engine.plugins.commands import PlainCommandContext, TextCommandResult, TurnCommandResult
148
+ from zettcode.mention import Mention, MentionProvider
149
+ from zettcode.plugin_tui import TuiGroup
150
+ from zettcode.providers import Provider
151
+ from zettcode.registry import Registry
152
+ from zettcode.tui import Canvas, Host, MouseAction, MouseEvent, Span, Style, TextLine, Widget
153
+ from zettcode.tui.render import blend, display_width, truncate
154
+
155
+ from .commands import (
156
+ BusyPolicy,
157
+ Command,
158
+ CommandAgent,
159
+ CommandContext,
160
+ CommandHandler,
161
+ CommandHost,
162
+ CommandList,
163
+ CommandProvider,
164
+ CommandResult,
165
+ CommandTranscript,
166
+ CommandUi,
167
+ Subcommand,
168
+ )
169
+ from .entries import (
170
+ ChangesEntry,
171
+ DeleteEntry,
172
+ EditEntry,
173
+ Entry,
174
+ EntryKind,
175
+ EntryStatus,
176
+ FileChangeEntry,
177
+ FileSummary,
178
+ MarkdownEntry,
179
+ MessageEntry,
180
+ NoticeLevel,
181
+ ReadEntry,
182
+ RelayEntry,
183
+ TextEntry,
184
+ ThinkingEntry,
185
+ ToolEntry,
186
+ WaitEntry,
187
+ WriteEntry,
188
+ )
189
+ from .host import HOST_LINK, HostLink
190
+ from .mixins import PluginUiMixin
191
+ from .panels import bottom_panel, pressed
192
+ from .pets import Pet, PetSource
193
+ from .plugin import TuiPlugin, TuiPlugins
194
+ from .presenters import CONTENT_INDENT, Presenter, Presenters
195
+ from .rows import Row
196
+ from .state import (
197
+ Activity,
198
+ ActivityState,
199
+ DisplayState,
200
+ ModelState,
201
+ SessionState,
202
+ ShellContext,
203
+ TurnSegment,
204
+ UiBuilder,
205
+ UiRegion,
206
+ UiRow,
207
+ UiSegment,
208
+ UiSide,
209
+ )
210
+ from .switch import SWITCH_WIDTH, Rail, draw_switch
211
+
212
+
213
+ def __getattr__(name: str) -> Any:
214
+ """Import the module a public name lives in, the first time it is asked for.
215
+
216
+ Args:
217
+ name: The public name the plugin asked for.
218
+
219
+ Returns:
220
+ What that module defines under the name.
221
+
222
+ Raises:
223
+ AttributeError: The package has no such name.
224
+ """
225
+ module = _EXPORTS.get(name)
226
+ if module is None:
227
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
228
+ value = getattr(importlib.import_module(module, __name__), name)
229
+ globals()[name] = value
230
+ return value
231
+
232
+
233
+ __all__ = [
234
+ "Activity",
235
+ "ActivityState",
236
+ "AgentBuild",
237
+ "BusyPolicy",
238
+ "CONTENT_INDENT",
239
+ "Canvas",
240
+ "ChangesEntry",
241
+ "Command",
242
+ "CommandAgent",
243
+ "CommandContext",
244
+ "CommandHandler",
245
+ "CommandHost",
246
+ "CommandList",
247
+ "CommandProvider",
248
+ "CommandResult",
249
+ "CommandTranscript",
250
+ "CommandUi",
251
+ "Contribution",
252
+ "DeleteEntry",
253
+ "DisplayState",
254
+ "EditEntry",
255
+ "Entry",
256
+ "EntryKind",
257
+ "EntryStatus",
258
+ "ExtensionFactory",
259
+ "FileChangeEntry",
260
+ "FileSummary",
261
+ "HOST_LINK",
262
+ "Host",
263
+ "HostLink",
264
+ "MarkdownEntry",
265
+ "Mention",
266
+ "MentionProvider",
267
+ "MessageEntry",
268
+ "ModelConfig",
269
+ "ModelState",
270
+ "MouseAction",
271
+ "MouseEvent",
272
+ "NoticeLevel",
273
+ "Pet",
274
+ "PetSource",
275
+ "PlainCommandContext",
276
+ "Plugin",
277
+ "PluginAgentMixin",
278
+ "PluginContext",
279
+ "PluginEventMixin",
280
+ "PluginExtension",
281
+ "PluginMaintenanceMixin",
282
+ "PluginMiddlewareMixin",
283
+ "PluginModelMixin",
284
+ "PluginRunMixin",
285
+ "PluginSetting",
286
+ "PluginSetupMixin",
287
+ "PluginToolMixin",
288
+ "PluginTurnMixin",
289
+ "PluginUiMixin",
290
+ "Plugins",
291
+ "Presenter",
292
+ "Presenters",
293
+ "Provider",
294
+ "Rail",
295
+ "ReadEntry",
296
+ "Registry",
297
+ "RelayEntry",
298
+ "Row",
299
+ "SWITCH_WIDTH",
300
+ "SessionState",
301
+ "ShellContext",
302
+ "Span",
303
+ "Style",
304
+ "Subcommand",
305
+ "TextCommandResult",
306
+ "TextEntry",
307
+ "TextLine",
308
+ "ThinkingEntry",
309
+ "ToolEntry",
310
+ "TuiGroup",
311
+ "TuiPlugin",
312
+ "TuiPlugins",
313
+ "TurnCommandResult",
314
+ "TurnSegment",
315
+ "UiBuilder",
316
+ "UiRegion",
317
+ "UiRow",
318
+ "UiSegment",
319
+ "UiSide",
320
+ "WaitEntry",
321
+ "Widget",
322
+ "WriteEntry",
323
+ "ZettCodeConfig",
324
+ "blend",
325
+ "bottom_panel",
326
+ "display_width",
327
+ "draw_switch",
328
+ "pressed",
329
+ "truncate",
330
+ ]