zettcode-engine 0.5.0__tar.gz → 0.5.1__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.
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/PKG-INFO +2 -2
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/pyproject.toml +1 -1
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/config.py +3 -1
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/core.py +19 -3
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/plugins/loader.py +35 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/plugins/plugin.py +4 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/plugins/switches.py +136 -31
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/version.py +1 -1
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/.gitignore +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/_compat.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/budget.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/config_edit.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/__init__.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/agent/__init__.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/agent/base.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/agent/context.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/agent/exports.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/agent/interaction.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/agent/sessions.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/agent/settings.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/agent/turns.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/delivery.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/delivery_runtime.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/dialogue/__init__.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/dialogue/ask.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/dialogue/side.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/dialogue/title.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/export/__init__.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/export/trace/script.js +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/export/trace/style.css +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/export/trace/template.html +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/extensions/__init__.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/extensions/capabilities.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/extensions/compaction.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/extensions/context.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/extensions/files.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/extensions/guidance.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/extensions/harness_switch.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/extensions/mcp_notice.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/extensions/relay.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/extensions/subagents.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/extensions/usage.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/harness_paths.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/inbox.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/permission/__init__.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/permission/approval.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/permission/readonly.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/permission/sandbox.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/pipeline.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/plugins/__init__.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/plugins/cli.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/plugins/commands.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/plugins/context.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/plugins/extension.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/plugins/graph.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/plugins/groups.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/plugins/llm.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/plugins/mixins.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/plugins/services.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/plugins/settings.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/plugins/state.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/plugins/triggers.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/provided.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/py.typed +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/server_tools.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/service_contracts.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/storage/__init__.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/storage/layout.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/storage/ledger.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/storage/locks.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/storage/metadata.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/storage/records.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/storage/store.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/error_text.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/filelock.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/logging_setup.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/mention.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/modes.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/paths.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/plugin_tui.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/processes.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/prompt.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/providers.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/py.typed +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/registry.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/relay.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/statusline_parts.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/wire.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/wording.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: zettcode-engine
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.1
|
|
4
4
|
Summary: The agent core of ZettCode: the runtime over zett-agent, and the leaf types it is written on
|
|
5
5
|
Project-URL: Repository, https://github.com/Chang-LeHung/zettcode
|
|
6
6
|
Author: Chang-LeHung
|
|
@@ -19,6 +19,6 @@ Requires-Dist: exceptiongroup<2,>=1.2; python_version < '3.11'
|
|
|
19
19
|
Requires-Dist: pydantic<3,>=2
|
|
20
20
|
Requires-Dist: tomli<3,>=2; python_version < '3.11'
|
|
21
21
|
Requires-Dist: zett-agent<0.3,>=0.2.10
|
|
22
|
-
Requires-Dist: zettcode-tools<0.6,>=0.5.
|
|
22
|
+
Requires-Dist: zettcode-tools<0.6,>=0.5.1
|
|
23
23
|
Provides-Extra: tiktoken
|
|
24
24
|
Requires-Dist: tiktoken<1,>=0.12; extra == 'tiktoken'
|
|
@@ -18,7 +18,7 @@ classifiers = [
|
|
|
18
18
|
]
|
|
19
19
|
dependencies = [
|
|
20
20
|
# The coding tools the runtime hands the model, a leaf of its own beneath the engine.
|
|
21
|
-
"zettcode-tools>=0.5.
|
|
21
|
+
"zettcode-tools>=0.5.1,<0.6",
|
|
22
22
|
# The runtime this is a core over. Imported directly: the agent, the message types, the approval mode.
|
|
23
23
|
"zett-agent>=0.2.10,<0.3",
|
|
24
24
|
# The session store's records are pydantic models.
|
|
@@ -490,7 +490,9 @@ class ZettCodeConfig:
|
|
|
490
490
|
``[plugins] disable`` list; the names the older switch file adds are merged in by
|
|
491
491
|
:attr:`off_names`, so a switch can tell the two apart.
|
|
492
492
|
enabled_plugins: Entry-point names to load although the plugin itself says it is off by default
|
|
493
|
-
(``Plugin.default_enabled``); this is the configuration file's ``[plugins] enable`` list.
|
|
493
|
+
(``Plugin.default_enabled``); this is the configuration file's ``[plugins] enable`` list. A switch that
|
|
494
|
+
turns a plugin on writes it here as well as taking it out of ``disable``, so one press means the same
|
|
495
|
+
for a plugin that is off until named and one that is on until dropped.
|
|
494
496
|
plugin_settings: The ``[plugins.<name>]`` tables, by plugin name, exactly as written. A plugin declares
|
|
495
497
|
what its own keys mean and what they default to (``ctx.settings``); the configuration only carries the
|
|
496
498
|
reader's values, so a key no plugin knows is harmless and a plugin that ships later needs no change
|
|
@@ -428,8 +428,9 @@ class ZettCodeEngine:
|
|
|
428
428
|
os.chdir(config.workspace)
|
|
429
429
|
file_models = config.models
|
|
430
430
|
# A machine that has never been set up has no model to start on; the shell opens anyway and says so (see
|
|
431
|
-
# the invariant S23), and `use_model` sizes this runtime the moment `/config` writes the first entry.
|
|
432
|
-
#
|
|
431
|
+
# the invariant S23), and `use_model` sizes this runtime the moment `/config` writes the first entry. The
|
|
432
|
+
# first entry is also the one a run starts on: the file's, or — when it has none — the first model a plugin
|
|
433
|
+
# offers, chosen below once the plugins have been loaded.
|
|
433
434
|
selected = file_models[0] if file_models else None
|
|
434
435
|
effort = config.reasoning_effort if selected is None else selected.accepted_effort(config.reasoning_effort)
|
|
435
436
|
# One policy, read by everything that decides whether a command is asked
|
|
@@ -471,6 +472,15 @@ class ZettCodeEngine:
|
|
|
471
472
|
if shared:
|
|
472
473
|
provided.update(shared)
|
|
473
474
|
plugins = (load or _load_engine_plugins)(config, provided)
|
|
475
|
+
offered = entries(plugins.providers)
|
|
476
|
+
# The file is the reader's own order, so its first entry is the one a run starts on. With no entry there, the
|
|
477
|
+
# first model a plugin offers takes that place: a key in the environment is then enough to type at once,
|
|
478
|
+
# instead of the shell asking for a `/model` choice before it will do anything.
|
|
479
|
+
first_offered: ModelConfig | None = None
|
|
480
|
+
if selected is None and offered:
|
|
481
|
+
first_offered = offered[0]
|
|
482
|
+
selected = first_offered
|
|
483
|
+
effort = selected.accepted_effort(config.reasoning_effort)
|
|
474
484
|
runtime = cls(
|
|
475
485
|
config=config,
|
|
476
486
|
persistence=persistence,
|
|
@@ -486,8 +496,14 @@ class ZettCodeEngine:
|
|
|
486
496
|
plugins=plugins,
|
|
487
497
|
_models=models,
|
|
488
498
|
file_models=file_models,
|
|
489
|
-
provided_models=
|
|
499
|
+
provided_models=offered,
|
|
490
500
|
)
|
|
501
|
+
if first_offered is not None:
|
|
502
|
+
# The compaction policy asked for the selected model while it activated and was given none: this is the
|
|
503
|
+
# same sizing a switch does. A runtime whose plugins provide no policy (an engine preview with no agent
|
|
504
|
+
# parts) has nothing to size, and `use_model` would look it up in vain.
|
|
505
|
+
if runtime.plugins.find(COMPACTION, OnDemandCompaction) is not None:
|
|
506
|
+
runtime.use_model(first_offered)
|
|
491
507
|
context_reports.bind(runtime)
|
|
492
508
|
context_page.bind(runtime)
|
|
493
509
|
# The plugins are loaded, so the models they offered are known: a plugin that lists the models sees its own.
|
|
@@ -95,6 +95,7 @@ PROGRAM_DISTRIBUTIONS: dict[str, frozenset[str]] = {
|
|
|
95
95
|
"zettcode-tool-output",
|
|
96
96
|
"zettcode-truncation",
|
|
97
97
|
"zettcode-guidance",
|
|
98
|
+
"zettcode-one-system",
|
|
98
99
|
}
|
|
99
100
|
),
|
|
100
101
|
TERMINAL_ROLE: frozenset({"zettcode-app", "zettcode-commands", "zettcode-pets", "zettcode-presenters"}),
|
|
@@ -204,6 +205,23 @@ def _file_plugins(path: Path) -> tuple[list[Plugin[Any]], list[tuple[str, BaseEx
|
|
|
204
205
|
return plugins, failures
|
|
205
206
|
|
|
206
207
|
|
|
208
|
+
def file_off_by_default(path: Path) -> bool | None:
|
|
209
|
+
"""Return whether a single-file plugin loads nothing unless ``[plugins] enable`` names it.
|
|
210
|
+
|
|
211
|
+
The answer is on the class, so the file is imported here the way a start imports it: its module is executed and
|
|
212
|
+
its plugin classes are built, but nothing is activated and no command of the plugin runs. ``None`` when the file
|
|
213
|
+
cannot be read as a plugin at all — a failure the next start reports, and one a list must not turn into a
|
|
214
|
+
traceback. A file that defines several classes is off by default when every one of them asks to be.
|
|
215
|
+
"""
|
|
216
|
+
try:
|
|
217
|
+
plugins, _failures = _file_plugins(path)
|
|
218
|
+
except KeyboardInterrupt:
|
|
219
|
+
raise
|
|
220
|
+
except BaseException: # noqa: BLE001 - an unreadable plugin file is the loader's to report, not a caller's
|
|
221
|
+
return None
|
|
222
|
+
return bool(plugins) and not any(plugin.default_enabled() for plugin in plugins)
|
|
223
|
+
|
|
224
|
+
|
|
207
225
|
def load_plugins(
|
|
208
226
|
config: ZettCodeConfig,
|
|
209
227
|
*,
|
|
@@ -444,6 +462,19 @@ def run(
|
|
|
444
462
|
kept.extend(extra)
|
|
445
463
|
kept_ids.update(id(candidate) for candidate in extra)
|
|
446
464
|
needed.update(dep for candidate in extra for dep in candidate.deps)
|
|
465
|
+
# The plugins dropped for exactly one reason — they say they are off by default — are remembered, so a list can
|
|
466
|
+
# draw the row as off and a switch knows which line of the configuration file turns one on. An origin that kept
|
|
467
|
+
# another candidate is not one of them: a single file may define a class that loads and one that does not, and the
|
|
468
|
+
# file it names did its work, so neither list may call the file off by default.
|
|
469
|
+
kept_origins = {candidate.origin for candidate in candidates if id(candidate) in kept_ids}
|
|
470
|
+
loader.off_by_default.extend(
|
|
471
|
+
candidate.origin
|
|
472
|
+
for candidate in candidates
|
|
473
|
+
if id(candidate) not in kept_ids
|
|
474
|
+
and candidate.origin not in kept_origins
|
|
475
|
+
and candidate.plugin is not None
|
|
476
|
+
and not candidate.plugin.default_enabled()
|
|
477
|
+
)
|
|
447
478
|
candidates = kept
|
|
448
479
|
# Within the program's own groups the stated rank decides, then the name; the stable sort keeps everything else.
|
|
449
480
|
at = [i for i, c in enumerate(candidates) if c.agent]
|
|
@@ -552,6 +583,9 @@ class Loader:
|
|
|
552
583
|
#: One ``(name, why)`` per plugin that lost a name to one loaded before it; the winner did nothing wrong,
|
|
553
584
|
#: so these are notes rather than failures, and a list shows them without a switch.
|
|
554
585
|
self.taken: list[tuple[str, str]] = []
|
|
586
|
+
#: The origins of the plugins left out only because they say they are off by default, in discovery order; a
|
|
587
|
+
#: list shows one as off and a switch writes it into ``[plugins] enable``.
|
|
588
|
+
self.off_by_default: list[str] = []
|
|
555
589
|
#: The origins of the compiled-in plugins, in load order, so a bundle can say which rows are the program's.
|
|
556
590
|
self.builtins: list[str] = []
|
|
557
591
|
#: Whether the plugin being accepted is the program's own (built in, or one of its parts); read by ``merge``.
|
|
@@ -652,6 +686,7 @@ class Loader:
|
|
|
652
686
|
builtins=tuple(self.builtins),
|
|
653
687
|
triggers=tuple(self.triggers),
|
|
654
688
|
taken=tuple(self.taken),
|
|
689
|
+
default_off=tuple(dict.fromkeys(self.off_by_default)),
|
|
655
690
|
)
|
|
656
691
|
|
|
657
692
|
# -- the same for every front end --
|
|
@@ -185,6 +185,9 @@ class Plugins:
|
|
|
185
185
|
itself (see :class:`~zettcode.engine.plugins.triggers.TriggerHost`).
|
|
186
186
|
taken: The plugins that lost a name to one loaded before them, each as ``(name, why)``; they are not failures
|
|
187
187
|
of the plugin that kept it, and a list shows them without a switch.
|
|
188
|
+
default_off: The origins of the plugins this process left out only because they say they are off by default
|
|
189
|
+
(:meth:`Plugin.default_enabled`). A list draws each as off and says which line turns it on; it is not a
|
|
190
|
+
failure, since the reader never asked for it.
|
|
188
191
|
"""
|
|
189
192
|
|
|
190
193
|
host: PluginExtension | None = None
|
|
@@ -197,6 +200,7 @@ class Plugins:
|
|
|
197
200
|
builtins: tuple[str, ...] = ()
|
|
198
201
|
triggers: tuple[TriggerRegistration, ...] = ()
|
|
199
202
|
taken: tuple[tuple[str, str], ...] = ()
|
|
203
|
+
default_off: tuple[str, ...] = ()
|
|
200
204
|
|
|
201
205
|
@property
|
|
202
206
|
def failures(self) -> tuple[str, ...]:
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
Two things decide it, and both are written now for the process that starts next:
|
|
4
4
|
|
|
5
5
|
* A plugin installed as a distribution is switched by `[plugins] disable` in the configuration file; an older
|
|
6
|
-
file of names beside the session store is still read and merged.
|
|
6
|
+
file of names beside the session store is still read and merged. A plugin that says it is off by default
|
|
7
|
+
(:meth:`~zettcode.engine.plugins.plugin.Plugin.default_enabled`) is the other way round: it stays off until
|
|
8
|
+
`[plugins] enable` names it, and that is the line a switch turning one on writes.
|
|
7
9
|
* A plugin compiled into the program has no file of its own. What turns its work off is a setting the reader already
|
|
8
10
|
has — ``[skills] enabled``, ``[mcp] enabled`` — which the plugin declares (see
|
|
9
11
|
:attr:`~zettcode.engine.plugins.plugin.Plugin.setting`). A compiled-in plugin that declares none cannot be switched
|
|
@@ -82,6 +84,7 @@ class SwitchState:
|
|
|
82
84
|
plugins_file: Path
|
|
83
85
|
plugins_enabled: bool = True
|
|
84
86
|
disabled_plugins: tuple[str, ...] = ()
|
|
87
|
+
enabled_plugins: tuple[str, ...] = ()
|
|
85
88
|
|
|
86
89
|
|
|
87
90
|
def off_names(config: ZettCodeConfig) -> tuple[str, ...]:
|
|
@@ -111,6 +114,10 @@ def catalog(
|
|
|
111
114
|
"""
|
|
112
115
|
builtins = set(bundle.builtins)
|
|
113
116
|
off = set(off_names(config))
|
|
117
|
+
# The two lists a reader wrote, and the plugins the loader left out only because they ask to be: a row is on when
|
|
118
|
+
# it was named, or when nothing holds it back and it wants to be on.
|
|
119
|
+
turned_on = set(config.enabled_plugins)
|
|
120
|
+
by_default = set(bundle.default_off)
|
|
114
121
|
compiled: list[PluginEntry] = []
|
|
115
122
|
installed: list[PluginEntry] = []
|
|
116
123
|
for plugin in bundle.plugins:
|
|
@@ -129,7 +136,17 @@ def catalog(
|
|
|
129
136
|
)
|
|
130
137
|
)
|
|
131
138
|
continue
|
|
132
|
-
installed.append(
|
|
139
|
+
installed.append(
|
|
140
|
+
_installed(
|
|
141
|
+
plugin.name,
|
|
142
|
+
origin,
|
|
143
|
+
config,
|
|
144
|
+
off=off,
|
|
145
|
+
turned_on=turned_on,
|
|
146
|
+
by_default=by_default,
|
|
147
|
+
description=plugin.description,
|
|
148
|
+
)
|
|
149
|
+
)
|
|
133
150
|
points = tuple(entry_points) if entry_points is not None else loader.installed_entry_points()
|
|
134
151
|
seen = {entry.origin for entry in installed} | {origin for origin, _why in bundle.failed}
|
|
135
152
|
for point in points:
|
|
@@ -144,12 +161,24 @@ def catalog(
|
|
|
144
161
|
continue
|
|
145
162
|
# This one never loaded, so there is no object to ask: its distribution's summary is what it has to say. The
|
|
146
163
|
# metadata is read here and not for every entry point, because a row that loaded speaks for itself.
|
|
147
|
-
installed.append(
|
|
164
|
+
installed.append(
|
|
165
|
+
_installed(
|
|
166
|
+
point.name,
|
|
167
|
+
point.name,
|
|
168
|
+
config,
|
|
169
|
+
off=off,
|
|
170
|
+
turned_on=turned_on,
|
|
171
|
+
by_default=by_default,
|
|
172
|
+
description=_summary(point),
|
|
173
|
+
)
|
|
174
|
+
)
|
|
148
175
|
# A single-file plugin that is switched off is not in the bundle (the loader never imported it), so the folder is
|
|
149
176
|
# what says it exists: it stays on the page, off, where it can be switched back on.
|
|
150
177
|
for path in loader.installed_files(config.plugins_dir):
|
|
151
178
|
if path.stem not in seen:
|
|
152
|
-
installed.append(
|
|
179
|
+
installed.append(
|
|
180
|
+
_installed(path.stem, path.stem, config, off=off, turned_on=turned_on, by_default=by_default)
|
|
181
|
+
)
|
|
153
182
|
# A file can load some of its classes and fail others: every reason belongs on the file's one row, not on a
|
|
154
183
|
# second row named after the class, which no switch could ever write. A file that fails all of its classes still
|
|
155
184
|
# gets one row, with every reason joined.
|
|
@@ -193,19 +222,35 @@ def catalog(
|
|
|
193
222
|
)
|
|
194
223
|
|
|
195
224
|
|
|
196
|
-
def _installed(
|
|
197
|
-
|
|
225
|
+
def _installed(
|
|
226
|
+
name: str,
|
|
227
|
+
origin: str,
|
|
228
|
+
config: ZettCodeConfig,
|
|
229
|
+
*,
|
|
230
|
+
off: set[str],
|
|
231
|
+
turned_on: set[str] | frozenset[str] = frozenset(),
|
|
232
|
+
by_default: set[str] | frozenset[str] = frozenset(),
|
|
233
|
+
description: str = "",
|
|
234
|
+
) -> PluginEntry:
|
|
235
|
+
"""Return one installed plugin's row: whether the next start loads it, and whether its switch can move.
|
|
236
|
+
|
|
237
|
+
A plugin that asks to be off until it is named is off here too, and its row says so: the loader leaves it out
|
|
238
|
+
for that reason, and a switch turning it on writes ``[plugins] enable``. A name in ``[plugins] disable`` is a
|
|
239
|
+
reader's decision about it, so the row is off and the note is not shown for one.
|
|
240
|
+
"""
|
|
198
241
|
why = (
|
|
199
242
|
"installed plugins are off entirely: [plugins] enabled = false in the configuration file"
|
|
200
243
|
if not config.plugins_enabled
|
|
201
244
|
else ""
|
|
202
245
|
)
|
|
246
|
+
off_by_default = origin in by_default and origin not in turned_on and origin not in off
|
|
203
247
|
return PluginEntry(
|
|
204
248
|
name,
|
|
205
249
|
origin,
|
|
206
|
-
enabled=config.plugins_enabled and origin not in off,
|
|
250
|
+
enabled=config.plugins_enabled and origin not in off and not off_by_default,
|
|
207
251
|
switchable=why == "",
|
|
208
252
|
why=why,
|
|
253
|
+
note="off by default; [plugins] enable turns it on" if off_by_default and config.plugins_enabled else "",
|
|
209
254
|
description=description,
|
|
210
255
|
)
|
|
211
256
|
|
|
@@ -297,33 +342,73 @@ def _drop_legacy_names(path: Path, names: set[str]) -> bool:
|
|
|
297
342
|
return True
|
|
298
343
|
|
|
299
344
|
|
|
300
|
-
def
|
|
301
|
-
"""
|
|
345
|
+
def _config_enabled(path: Path) -> list[str]:
|
|
346
|
+
"""Return the names ``[plugins] enable`` holds in the configuration file, validating the shape."""
|
|
347
|
+
from zettcode._compat import tomllib
|
|
348
|
+
|
|
349
|
+
if not path.is_file():
|
|
350
|
+
return []
|
|
351
|
+
try:
|
|
352
|
+
text = path.read_text(encoding="utf-8")
|
|
353
|
+
except OSError:
|
|
354
|
+
return []
|
|
355
|
+
data = tomllib.loads(text) if text.strip() else {}
|
|
356
|
+
plugins = data.get("plugins", {})
|
|
357
|
+
if not isinstance(plugins, dict):
|
|
358
|
+
raise ValueError(f"{path} writes [plugins] in a way /plugins cannot edit; edit the file by hand")
|
|
359
|
+
values = plugins.get("enable", [])
|
|
360
|
+
if not isinstance(values, list) or any(not isinstance(name, str) or not name.strip() for name in values):
|
|
361
|
+
raise ValueError(f"{path} has a [plugins] enable that is not an array of names; edit the file by hand")
|
|
362
|
+
return [name.strip() for name in values]
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
def _write_switches(
|
|
366
|
+
config: ZettCodeConfig | SwitchState,
|
|
367
|
+
*,
|
|
368
|
+
turn_on: set[str] | frozenset[str] = frozenset(),
|
|
369
|
+
turn_off: set[str] | frozenset[str] = frozenset(),
|
|
370
|
+
by_default: set[str] | frozenset[str] = frozenset(),
|
|
371
|
+
forget: set[str] | frozenset[str] = frozenset(),
|
|
372
|
+
) -> None:
|
|
373
|
+
"""Write a switch into ``[plugins] disable`` and, for a plugin that asks to be off, ``[plugins] enable``.
|
|
374
|
+
|
|
375
|
+
``by_default`` names the plugins that are off until they are named
|
|
376
|
+
(:meth:`~zettcode.engine.plugins.plugin.Plugin.default_enabled`); turning one on is what writes `[plugins]
|
|
377
|
+
enable`, and turning it off takes the name out again. A plugin that is on unless it is dropped needs no line
|
|
378
|
+
when it is turned on, so a switch that changes nothing still writes nothing. ``forget`` takes a name out of both
|
|
379
|
+
lists — an uninstall retires it rather than switching it.
|
|
302
380
|
|
|
303
381
|
The configuration file is the one the reader edits and the one ``load_config`` reads, so the switch is written
|
|
304
382
|
there; a file that does not exist yet gets one with the table, and the models are added when the reader sets one.
|
|
305
|
-
|
|
306
|
-
|
|
383
|
+
The read and the replace are held under a lock, so two plugin switches (or two plugin-settings edits) cannot
|
|
384
|
+
lose one another.
|
|
307
385
|
"""
|
|
308
386
|
target = config_path()
|
|
309
387
|
if target.exists() and not target.is_file():
|
|
310
388
|
raise ValueError(f"{target} is not a file; edit the plugin switches by hand")
|
|
389
|
+
on, off, named_for, gone = set(turn_on), set(turn_off), set(by_default), set(forget)
|
|
311
390
|
changed = False
|
|
312
391
|
try:
|
|
313
392
|
with _lock(target):
|
|
314
393
|
text = target.read_text(encoding="utf-8") if target.is_file() else ""
|
|
315
394
|
current = set(_config_disabled(target))
|
|
316
|
-
names = (current |
|
|
395
|
+
names = (current | (off - named_for)) - on - gone
|
|
317
396
|
if names != current:
|
|
318
397
|
text = set_string_list(text, "plugins", "disable", sorted(names), where=target, command="/plugins")
|
|
319
|
-
write_text_atomically(target, text)
|
|
320
398
|
changed = True
|
|
399
|
+
asked = set(_config_enabled(target))
|
|
400
|
+
wanted = (asked | (on & named_for)) - off - gone
|
|
401
|
+
if wanted != asked:
|
|
402
|
+
text = set_string_list(text, "plugins", "enable", sorted(wanted), where=target, command="/plugins")
|
|
403
|
+
changed = True
|
|
404
|
+
if changed:
|
|
405
|
+
write_text_atomically(target, text)
|
|
321
406
|
except (OSError, ValueError) as error:
|
|
322
407
|
raise ValueError(f"the plugin switch could not be written: {error}") from error
|
|
323
|
-
if not _drop_legacy_names(config.plugins_file,
|
|
408
|
+
if not _drop_legacy_names(config.plugins_file, on | off | gone) and on:
|
|
324
409
|
if changed:
|
|
325
|
-
raise ValueError(f"the configuration was changed, but {_still_in_legacy(
|
|
326
|
-
raise ValueError(_still_in_legacy(
|
|
410
|
+
raise ValueError(f"the configuration was changed, but {_still_in_legacy(on)}")
|
|
411
|
+
raise ValueError(_still_in_legacy(on))
|
|
327
412
|
|
|
328
413
|
|
|
329
414
|
def _still_in_legacy(enable: set[str]) -> str:
|
|
@@ -411,10 +496,11 @@ def set_many(
|
|
|
411
496
|
written[name] = enabled
|
|
412
497
|
if off_changes:
|
|
413
498
|
try:
|
|
414
|
-
|
|
499
|
+
_write_switches(
|
|
415
500
|
config,
|
|
416
|
-
|
|
417
|
-
|
|
501
|
+
turn_on={name for name, enabled in off_changes.items() if enabled},
|
|
502
|
+
turn_off={name for name, enabled in off_changes.items() if not enabled},
|
|
503
|
+
by_default=set(bundle.default_off),
|
|
418
504
|
)
|
|
419
505
|
except ValueError as error:
|
|
420
506
|
# Nothing of this batch was written, so the refusals above are still worth reporting with it.
|
|
@@ -494,23 +580,37 @@ def applied(config: ZettCodeConfig, setting: PluginSetting, enabled: bool) -> Ze
|
|
|
494
580
|
return replace(config, **{setting.field: enabled}) # type: ignore[arg-type]
|
|
495
581
|
|
|
496
582
|
|
|
497
|
-
def applied_installed(
|
|
498
|
-
|
|
583
|
+
def applied_installed(
|
|
584
|
+
config: ZettCodeConfig, changes: Mapping[str, bool], *, by_default: set[str] | frozenset[str] = frozenset()
|
|
585
|
+
) -> ZettCodeConfig:
|
|
586
|
+
"""Return ``config`` with the installed names a switch wrote reflected in the two lists a row reads.
|
|
499
587
|
|
|
500
|
-
|
|
501
|
-
|
|
588
|
+
A name turned off is taken out of ``[plugins] enable`` and put in ``disable``, except that a plugin which is off
|
|
589
|
+
by default rests there unnamed. A name turned on is taken out of ``disable`` and named in ``enable`` only when it
|
|
590
|
+
asks to be off — a plugin that is on unless dropped gains no line, so this must not invent one in memory either.
|
|
591
|
+
``by_default`` says which names those are.
|
|
502
592
|
"""
|
|
503
|
-
|
|
593
|
+
off = set(config.disabled_plugins)
|
|
594
|
+
on = set(config.enabled_plugins)
|
|
595
|
+
named_for = set(by_default)
|
|
504
596
|
for name, enabled in changes.items():
|
|
505
|
-
|
|
506
|
-
|
|
597
|
+
if enabled:
|
|
598
|
+
off.discard(name)
|
|
599
|
+
if name in named_for:
|
|
600
|
+
on.add(name)
|
|
601
|
+
else:
|
|
602
|
+
on.discard(name)
|
|
603
|
+
if name not in named_for:
|
|
604
|
+
off.add(name)
|
|
605
|
+
return replace(config, disabled_plugins=tuple(sorted(off)), enabled_plugins=tuple(sorted(on)))
|
|
507
606
|
|
|
508
607
|
|
|
509
|
-
def set_installed(config: ZettCodeConfig | SwitchState, name: str, *, enabled: bool) -> None:
|
|
510
|
-
"""Write one installed plugin's switch
|
|
608
|
+
def set_installed(config: ZettCodeConfig | SwitchState, name: str, *, enabled: bool, by_default: bool = False) -> None:
|
|
609
|
+
"""Write one installed plugin's switch, without loading any plugin.
|
|
511
610
|
|
|
512
611
|
A management command asks this for a name it has already checked exists (an entry point, a single file in
|
|
513
|
-
:attr:`ZettCodeConfig.plugins_dir`, or a name the file already holds).
|
|
612
|
+
:attr:`ZettCodeConfig.plugins_dir`, or a name the file already holds). ``by_default`` says the plugin is off
|
|
613
|
+
until ``[plugins] enable`` names it, which is the line turning it on writes. Nothing is written while
|
|
514
614
|
``[plugins] enabled`` is off; a name in ``[plugins] disable`` is an ordinary switch and can be turned on.
|
|
515
615
|
|
|
516
616
|
Raises:
|
|
@@ -524,7 +624,12 @@ def set_installed(config: ZettCodeConfig | SwitchState, name: str, *, enabled: b
|
|
|
524
624
|
"[plugins] enabled = false in the configuration file turns every installed plugin off; edit that line "
|
|
525
625
|
"to load them again"
|
|
526
626
|
)
|
|
527
|
-
|
|
627
|
+
_write_switches(
|
|
628
|
+
config,
|
|
629
|
+
turn_on={name} if enabled else set(),
|
|
630
|
+
turn_off=set() if enabled else {name},
|
|
631
|
+
by_default={name} if by_default else set(),
|
|
632
|
+
)
|
|
528
633
|
|
|
529
634
|
|
|
530
635
|
def forget_installed(config: ZettCodeConfig | SwitchState, name: str) -> bool:
|
|
@@ -545,7 +650,7 @@ def forget_installed(config: ZettCodeConfig | SwitchState, name: str) -> bool:
|
|
|
545
650
|
if not found:
|
|
546
651
|
return False
|
|
547
652
|
try:
|
|
548
|
-
|
|
653
|
+
_write_switches(config, forget={name})
|
|
549
654
|
except ValueError:
|
|
550
655
|
return False
|
|
551
656
|
return True
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/export/trace/template.html
RENAMED
|
File without changes
|
|
File without changes
|
{zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/extensions/capabilities.py
RENAMED
|
File without changes
|
{zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/extensions/compaction.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/extensions/harness_switch.py
RENAMED
|
File without changes
|
{zettcode_engine-0.5.0 → zettcode_engine-0.5.1}/src/zettcode/engine/extensions/mcp_notice.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|