zettcode-engine 0.4.6__tar.gz → 0.5.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.
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/.gitignore +1 -3
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/PKG-INFO +2 -2
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/pyproject.toml +1 -1
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/config.py +5 -4
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/plugins/plugin.py +3 -1
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/plugins/switches.py +49 -6
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/service_contracts.py +10 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/storage/store.py +131 -21
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/version.py +1 -1
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/_compat.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/budget.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/config_edit.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/__init__.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/agent/__init__.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/agent/base.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/agent/context.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/agent/exports.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/agent/interaction.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/agent/sessions.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/agent/settings.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/agent/turns.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/core.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/delivery.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/delivery_runtime.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/dialogue/__init__.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/dialogue/ask.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/dialogue/side.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/dialogue/title.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/export/__init__.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/export/trace/script.js +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/export/trace/style.css +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/export/trace/template.html +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/extensions/__init__.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/extensions/capabilities.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/extensions/compaction.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/extensions/context.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/extensions/files.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/extensions/guidance.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/extensions/harness_switch.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/extensions/mcp_notice.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/extensions/relay.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/extensions/subagents.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/extensions/usage.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/harness_paths.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/inbox.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/permission/__init__.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/permission/approval.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/permission/readonly.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/permission/sandbox.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/pipeline.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/plugins/__init__.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/plugins/cli.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/plugins/commands.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/plugins/context.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/plugins/extension.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/plugins/graph.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/plugins/groups.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/plugins/llm.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/plugins/loader.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/plugins/mixins.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/plugins/services.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/plugins/settings.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/plugins/state.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/plugins/triggers.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/provided.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/py.typed +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/server_tools.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/storage/__init__.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/storage/layout.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/storage/ledger.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/storage/locks.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/storage/metadata.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/storage/records.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/error_text.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/filelock.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/logging_setup.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/mention.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/modes.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/paths.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/plugin_tui.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/processes.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/prompt.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/providers.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/py.typed +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/registry.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/relay.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/statusline_parts.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/wire.py +0 -0
- {zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/wording.py +0 -0
|
@@ -36,7 +36,5 @@ docs/internal/palettes.html
|
|
|
36
36
|
# The release order is generated from the pyproject.toml files (`make order`); it is not kept in git.
|
|
37
37
|
packages/order.txt
|
|
38
38
|
|
|
39
|
-
#
|
|
40
|
-
# installers under release/.
|
|
41
|
-
clients/desktop/renderer/
|
|
39
|
+
# electron-builder writes the desktop installers under release/.
|
|
42
40
|
clients/desktop/release/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: zettcode-engine
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
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.
|
|
22
|
+
Requires-Dist: zettcode-tools<0.6,>=0.5.0
|
|
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.
|
|
21
|
+
"zettcode-tools>=0.5.0,<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.
|
|
@@ -504,8 +504,9 @@ class ZettCodeConfig:
|
|
|
504
504
|
shows in its plan panel. Off by default: a plan is a turn spent
|
|
505
505
|
updating it, and not every session wants one.
|
|
506
506
|
jit_harness: Start with the just-in-time harness on: the model may write small Python tools of its own
|
|
507
|
-
and run them.
|
|
508
|
-
|
|
507
|
+
and run them. On by default; what it writes runs in a child process of its own, and inside the shell's
|
|
508
|
+
sandbox at every level below ``full``. ``[harness] jit = false`` (or the terminal's ``/plugins`` switch)
|
|
509
|
+
turns it off for the next start.
|
|
509
510
|
shell_network: Let a command that runs in the ``safe`` sandbox use the network. Off by default; ``[shell]
|
|
510
511
|
network = true`` turns it on. ``full`` always has the network, and so does a machine with no sandbox.
|
|
511
512
|
sessions_enabled: Register with the background session broker, so this session can be
|
|
@@ -558,7 +559,7 @@ class ZettCodeConfig:
|
|
|
558
559
|
subagent_max_iterations: int = DEFAULT_SUBAGENT_MAX_ITERATIONS
|
|
559
560
|
subagent_messaging: bool = False
|
|
560
561
|
todowrite_enabled: bool = False
|
|
561
|
-
jit_harness: bool =
|
|
562
|
+
jit_harness: bool = True
|
|
562
563
|
shell_network: bool = False
|
|
563
564
|
sessions_enabled: bool = True
|
|
564
565
|
update_enabled: bool = True
|
|
@@ -1132,7 +1133,7 @@ def load_config(
|
|
|
1132
1133
|
),
|
|
1133
1134
|
subagent_messaging=bool(_setting(harness, "subagent_messaging", bool, False)),
|
|
1134
1135
|
todowrite_enabled=bool(_setting(harness, "todowrite", bool, False)),
|
|
1135
|
-
jit_harness=bool(_setting(harness, "jit", bool,
|
|
1136
|
+
jit_harness=bool(_setting(harness, "jit", bool, True)),
|
|
1136
1137
|
shell_network=bool(_setting(shell, "network", bool, False)),
|
|
1137
1138
|
sessions_enabled=bool(_setting(sessions, "enabled", bool, True)),
|
|
1138
1139
|
update_enabled=bool(_setting(update, "enabled", bool, True)),
|
|
@@ -84,7 +84,9 @@ class Plugin(PluginAgentMixin, Generic[_C], ABC):
|
|
|
84
84
|
when the entry-point name is not the label you want in
|
|
85
85
|
diagnostics. When it is empty the entry-point name is used, and a
|
|
86
86
|
plugin that declares neither falls back to the class name.
|
|
87
|
-
description: One-line summary of what the plugin adds,
|
|
87
|
+
description: One-line summary of what the plugin adds, shown beside its switch on ``/plugins`` and used in
|
|
88
|
+
diagnostics. A plugin a reader can switch should say something here: a listed row with nothing to say
|
|
89
|
+
costs the reader the one line that tells the two plugins called alike apart.
|
|
88
90
|
priority: Hook order against every other extension: lower runs first,
|
|
89
91
|
and equal priorities keep registration order.
|
|
90
92
|
setting: The configuration key that turns its work off, for a plugin compiled into the program; ``None`` when
|
|
@@ -57,6 +57,10 @@ class PluginEntry:
|
|
|
57
57
|
why: Why it cannot be switched, when it cannot; empty otherwise.
|
|
58
58
|
note: What else a list should say about the row — a plugin that lost its name to one loaded before it has no
|
|
59
59
|
switch and is not a failure, and this says so.
|
|
60
|
+
description: What the plugin adds, in one line. It is derived, not stored: the plugin's own
|
|
61
|
+
:attr:`~zettcode.engine.plugins.plugin.Plugin.description` once it has loaded, and otherwise the summary
|
|
62
|
+
its distribution declares — which is a sentence about the distribution the row's second column names,
|
|
63
|
+
not about one plugin inside it. Empty when neither says anything.
|
|
60
64
|
"""
|
|
61
65
|
|
|
62
66
|
name: str
|
|
@@ -68,6 +72,7 @@ class PluginEntry:
|
|
|
68
72
|
switchable: bool = True
|
|
69
73
|
why: str = ""
|
|
70
74
|
note: str = ""
|
|
75
|
+
description: str = ""
|
|
71
76
|
|
|
72
77
|
|
|
73
78
|
@dataclass(frozen=True, slots=True)
|
|
@@ -120,10 +125,11 @@ def catalog(
|
|
|
120
125
|
builtin=True,
|
|
121
126
|
enabled=bool(getattr(config, setting.field)),
|
|
122
127
|
setting=setting.path,
|
|
128
|
+
description=plugin.description,
|
|
123
129
|
)
|
|
124
130
|
)
|
|
125
131
|
continue
|
|
126
|
-
installed.append(_installed(plugin.name, origin, config, off=off))
|
|
132
|
+
installed.append(_installed(plugin.name, origin, config, off=off, description=plugin.description))
|
|
127
133
|
points = tuple(entry_points) if entry_points is not None else loader.installed_entry_points()
|
|
128
134
|
seen = {entry.origin for entry in installed} | {origin for origin, _why in bundle.failed}
|
|
129
135
|
for point in points:
|
|
@@ -136,7 +142,9 @@ def catalog(
|
|
|
136
142
|
if loader.part_group(point) is not None:
|
|
137
143
|
if point.name not in off:
|
|
138
144
|
continue
|
|
139
|
-
|
|
145
|
+
# This one never loaded, so there is no object to ask: its distribution's summary is what it has to say. The
|
|
146
|
+
# metadata is read here and not for every entry point, because a row that loaded speaks for itself.
|
|
147
|
+
installed.append(_installed(point.name, point.name, config, off=off, description=_summary(point)))
|
|
140
148
|
# A single-file plugin that is switched off is not in the bundle (the loader never imported it), so the folder is
|
|
141
149
|
# what says it exists: it stays on the page, off, where it can be switched back on.
|
|
142
150
|
for path in loader.installed_files(config.plugins_dir):
|
|
@@ -159,8 +167,17 @@ def catalog(
|
|
|
159
167
|
for origin, why in bundle.failed:
|
|
160
168
|
if origin in builtins or origin not in loaded_origins:
|
|
161
169
|
failures.setdefault(origin, []).append(why)
|
|
170
|
+
by_name = {point.name: point for point in points}
|
|
162
171
|
failed = [
|
|
163
|
-
_failed(
|
|
172
|
+
_failed(
|
|
173
|
+
origin,
|
|
174
|
+
"; ".join(whys),
|
|
175
|
+
config,
|
|
176
|
+
builtin=origin in builtins,
|
|
177
|
+
off=off,
|
|
178
|
+
# A row that failed has no object either: the summary of the point it came from is all there is.
|
|
179
|
+
description=_summary(by_name[origin]) if origin in by_name else "",
|
|
180
|
+
)
|
|
164
181
|
for origin, whys in failures.items()
|
|
165
182
|
]
|
|
166
183
|
lost = [PluginEntry(name, name, enabled=False, switchable=False, note=note) for name, note in bundle.taken]
|
|
@@ -176,7 +193,7 @@ def catalog(
|
|
|
176
193
|
)
|
|
177
194
|
|
|
178
195
|
|
|
179
|
-
def _installed(name: str, origin: str, config: ZettCodeConfig, *, off: set[str]) -> PluginEntry:
|
|
196
|
+
def _installed(name: str, origin: str, config: ZettCodeConfig, *, off: set[str], description: str = "") -> PluginEntry:
|
|
180
197
|
"""Return one installed plugin's row: whether the next start loads it, and whether its switch can move."""
|
|
181
198
|
why = (
|
|
182
199
|
"installed plugins are off entirely: [plugins] enabled = false in the configuration file"
|
|
@@ -189,10 +206,13 @@ def _installed(name: str, origin: str, config: ZettCodeConfig, *, off: set[str])
|
|
|
189
206
|
enabled=config.plugins_enabled and origin not in off,
|
|
190
207
|
switchable=why == "",
|
|
191
208
|
why=why,
|
|
209
|
+
description=description,
|
|
192
210
|
)
|
|
193
211
|
|
|
194
212
|
|
|
195
|
-
def _failed(
|
|
213
|
+
def _failed(
|
|
214
|
+
origin: str, why: str, config: ZettCodeConfig, *, builtin: bool, off: set[str], description: str = ""
|
|
215
|
+
) -> PluginEntry:
|
|
196
216
|
"""Return the row of a plugin that could not load.
|
|
197
217
|
|
|
198
218
|
A compiled-in one has no switch here: the object that declares its setting never loaded. An installed one keeps
|
|
@@ -207,8 +227,9 @@ def _failed(origin: str, why: str, config: ZettCodeConfig, *, builtin: bool, off
|
|
|
207
227
|
failure=why,
|
|
208
228
|
switchable=False,
|
|
209
229
|
why="it could not load, so there is no switch to move",
|
|
230
|
+
description=description,
|
|
210
231
|
)
|
|
211
|
-
row = _installed(origin, origin, config, off=off)
|
|
232
|
+
row = _installed(origin, origin, config, off=off, description=description)
|
|
212
233
|
return PluginEntry(
|
|
213
234
|
row.name,
|
|
214
235
|
row.origin,
|
|
@@ -216,9 +237,31 @@ def _failed(origin: str, why: str, config: ZettCodeConfig, *, builtin: bool, off
|
|
|
216
237
|
failure=why,
|
|
217
238
|
switchable=row.switchable,
|
|
218
239
|
why=row.why,
|
|
240
|
+
description=row.description,
|
|
219
241
|
)
|
|
220
242
|
|
|
221
243
|
|
|
244
|
+
def _summary(point: EntryPoint) -> str:
|
|
245
|
+
"""Return the one-line summary the distribution behind an entry point declares, or ``""`` when it declares none.
|
|
246
|
+
|
|
247
|
+
The plugin says what it does itself once it loads (:attr:`~zettcode.engine.plugins.plugin.Plugin.description`);
|
|
248
|
+
this is for the rows where it never got that far — the distribution switched off, or a part this process does not
|
|
249
|
+
load — and for those the package metadata is all there is. The summary describes the *distribution*, which is what
|
|
250
|
+
the row's second column names; for a distribution carrying several plugins it is one sentence about all of them.
|
|
251
|
+
A stand-in entry point that has no distribution beside it (a test's own) says nothing rather than failing the page,
|
|
252
|
+
and so does a metadata file that cannot be opened or parsed: a nicety costs its cell, never the page.
|
|
253
|
+
"""
|
|
254
|
+
try:
|
|
255
|
+
# `getattr` for the same reason the loader asks a point for its distribution that way: a stand-in that has
|
|
256
|
+
# none is a point with nothing to say, not a page that cannot open.
|
|
257
|
+
dist = getattr(point, "dist", None)
|
|
258
|
+
metadata = getattr(dist, "metadata", None)
|
|
259
|
+
summary = metadata["Summary"] if metadata is not None else ""
|
|
260
|
+
except (OSError, TypeError, ValueError):
|
|
261
|
+
return ""
|
|
262
|
+
return " ".join(str(summary or "").split())
|
|
263
|
+
|
|
264
|
+
|
|
222
265
|
def _config_disabled(path: Path) -> list[str]:
|
|
223
266
|
"""Return the names ``[plugins] disable`` holds in the configuration file, validating the shape."""
|
|
224
267
|
from zettcode._compat import tomllib
|
|
@@ -12,6 +12,8 @@ from dataclasses import dataclass
|
|
|
12
12
|
from typing import TYPE_CHECKING, ClassVar
|
|
13
13
|
|
|
14
14
|
if TYPE_CHECKING: # pragma: no cover - annotations only
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
15
17
|
from zettcode.engine.extensions.context import ContextReport
|
|
16
18
|
from zettcode.engine.storage.ledger import Ledger
|
|
17
19
|
from zettcode.engine.storage.metadata import SessionInfo
|
|
@@ -31,6 +33,14 @@ class SessionStoreService(ABC):
|
|
|
31
33
|
async def list_sessions(self, *, limit: int = 100, offset: int = 0) -> list[SessionInfo]:
|
|
32
34
|
"""Return the workspace's sessions, newest first."""
|
|
33
35
|
|
|
36
|
+
@abstractmethod
|
|
37
|
+
def session_path(self, session_id: str) -> Path:
|
|
38
|
+
"""Return the file one session's conversation is stored in; it may not exist yet.
|
|
39
|
+
|
|
40
|
+
Raises:
|
|
41
|
+
ValueError: For an id that would leave the store.
|
|
42
|
+
"""
|
|
43
|
+
|
|
34
44
|
|
|
35
45
|
class UsageLedgerService(ABC):
|
|
36
46
|
"""The workspace's usage ledger, read from the stored conversations."""
|
|
@@ -29,13 +29,14 @@ from __future__ import annotations
|
|
|
29
29
|
|
|
30
30
|
import asyncio
|
|
31
31
|
import json
|
|
32
|
+
import os
|
|
32
33
|
import threading
|
|
33
34
|
from collections import Counter
|
|
34
35
|
from collections.abc import Iterator, Mapping, Sequence
|
|
35
36
|
from dataclasses import dataclass, field, replace
|
|
36
37
|
from datetime import datetime
|
|
37
38
|
from pathlib import Path
|
|
38
|
-
from typing import cast
|
|
39
|
+
from typing import BinaryIO, cast
|
|
39
40
|
from weakref import WeakKeyDictionary
|
|
40
41
|
|
|
41
42
|
from pydantic import ValidationError
|
|
@@ -92,6 +93,26 @@ from .records import (
|
|
|
92
93
|
#: reach it through :meth:`SessionPersistenceMixin.session_dir`, so the name is stated here, once.
|
|
93
94
|
KEPT_OUTPUT = "tool-output"
|
|
94
95
|
|
|
96
|
+
#: How many bytes before the end of a read are remembered, to tell an appended file from a replaced one.
|
|
97
|
+
_ANCHOR = 64
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@dataclass(frozen=True, slots=True)
|
|
101
|
+
class _Reading:
|
|
102
|
+
"""Where the last read of a session file stopped, so the next one can start there.
|
|
103
|
+
|
|
104
|
+
Attributes:
|
|
105
|
+
session: What that read produced.
|
|
106
|
+
offset: The byte after the last line it took in.
|
|
107
|
+
anchor: The bytes just before ``offset``. A file that no longer has them there was replaced, not appended to.
|
|
108
|
+
lines: How many lines the read took in, so an error further on can name its line number.
|
|
109
|
+
"""
|
|
110
|
+
|
|
111
|
+
session: Session
|
|
112
|
+
offset: int
|
|
113
|
+
anchor: bytes
|
|
114
|
+
lines: int = 0
|
|
115
|
+
|
|
95
116
|
|
|
96
117
|
def message_context(
|
|
97
118
|
value: Mapping[str, object] | None, *, field: str, nonempty_keys: bool = False
|
|
@@ -174,6 +195,8 @@ class SessionPersistenceMixin:
|
|
|
174
195
|
# is the hot path — one call per message — so it must not re-parse the
|
|
175
196
|
# whole log; the cache makes a read O(1) and a write a tuple copy.
|
|
176
197
|
self._sessions: dict[str, tuple[tuple[int, int] | None, Session]] = {}
|
|
198
|
+
#: Where the last full or partial read of each session stopped, so a log that only grew is read from there.
|
|
199
|
+
self._readings: dict[str, _Reading] = {}
|
|
177
200
|
#: A read now runs on a worker thread for the framework's restore hook,
|
|
178
201
|
#: while appends still fold into the same cache on the loop. The lock
|
|
179
202
|
#: orders only the cache lookups and the publish; the parse itself runs
|
|
@@ -253,36 +276,91 @@ class SessionPersistenceMixin:
|
|
|
253
276
|
return cached[1]
|
|
254
277
|
if stamp is None:
|
|
255
278
|
session = Session(header=None, messages=(), compactions=(), head_id=None)
|
|
279
|
+
reading: _Reading | None = None
|
|
256
280
|
else:
|
|
257
|
-
|
|
281
|
+
with self._cache_lock:
|
|
282
|
+
known = self._readings.get(session_id)
|
|
283
|
+
session, reading = self._read_from(path, known)
|
|
258
284
|
with self._cache_lock:
|
|
259
285
|
cached = self._sessions.get(session_id)
|
|
260
286
|
if stamp is not None and cached is not None and cached[0] is not None and cached[0] >= stamp:
|
|
261
287
|
return cached[1]
|
|
262
288
|
self._sessions[session_id] = (stamp, session)
|
|
289
|
+
if reading is None:
|
|
290
|
+
self._forget(session_id, keep_session=True)
|
|
291
|
+
else:
|
|
292
|
+
self._readings[session_id] = reading
|
|
263
293
|
return session
|
|
264
294
|
|
|
265
|
-
def
|
|
266
|
-
"""
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
295
|
+
def _forget(self, session_id: str, *, keep_session: bool = False) -> None:
|
|
296
|
+
"""Drop what is remembered of a session's file: the parse, and where the last read of it stopped.
|
|
297
|
+
|
|
298
|
+
They go together, because a reading kept without its entry would be continued from by the next read, and
|
|
299
|
+
"dropped" has always meant "read again from the first byte".
|
|
300
|
+
"""
|
|
301
|
+
with self._cache_lock:
|
|
302
|
+
if not keep_session:
|
|
303
|
+
self._sessions.pop(session_id, None)
|
|
304
|
+
self._readings.pop(session_id, None)
|
|
305
|
+
|
|
306
|
+
def _read_from(self, path: Path, known: _Reading | None) -> tuple[Session, _Reading]:
|
|
307
|
+
"""Parse a session file, taking only what was appended since ``known`` when that is safe.
|
|
308
|
+
|
|
309
|
+
The log is append-only, so a file that is longer than it was, with the same bytes where the earlier read
|
|
310
|
+
stopped, is the earlier file plus new lines: only those are parsed. Anything else (shorter, a different
|
|
311
|
+
file, other bytes before the offset) is parsed whole, so a replaced file can never be read as an extension.
|
|
312
|
+
"""
|
|
313
|
+
with path.open("rb") as handle:
|
|
314
|
+
size = os.fstat(handle.fileno()).st_size
|
|
315
|
+
if known is not None and self._extends(handle, known, size):
|
|
316
|
+
handle.seek(known.offset)
|
|
317
|
+
tail = handle.read(size - known.offset)
|
|
318
|
+
return self._parse_tail(path, known, tail)
|
|
319
|
+
handle.seek(0)
|
|
320
|
+
return self._parse_tail(path, None, handle.read(size))
|
|
321
|
+
|
|
322
|
+
@staticmethod
|
|
323
|
+
def _extends(handle: BinaryIO, known: _Reading, size: int) -> bool:
|
|
324
|
+
"""Return whether the file still has the bytes the earlier read ended on, in the same place.
|
|
325
|
+
|
|
326
|
+
An equal-size file with those bytes is an extension of nothing: the parse of its empty tail is the cached one.
|
|
327
|
+
"""
|
|
328
|
+
if size < known.offset or known.offset == 0:
|
|
329
|
+
return False
|
|
330
|
+
anchor = min(known.offset, _ANCHOR)
|
|
331
|
+
handle.seek(known.offset - anchor)
|
|
332
|
+
return handle.read(anchor) == known.anchor
|
|
333
|
+
|
|
334
|
+
def _parse_tail(self, path: Path, known: _Reading | None, data: bytes) -> tuple[Session, _Reading]:
|
|
335
|
+
"""Parse ``data`` (the whole file, or what follows ``known``) and return the session and where it ended.
|
|
336
|
+
|
|
337
|
+
Only whole lines are consumed: a final line with no newline is parsed when it is complete JSON (the writer
|
|
338
|
+
is between its two writes) and left for the next read when it is not, so a torn line is never skipped.
|
|
339
|
+
"""
|
|
340
|
+
base = known.offset if known is not None else 0
|
|
341
|
+
first_line = known.lines + 1 if known is not None else 1
|
|
342
|
+
# Bytes, split on b"\n" only: ``str.splitlines`` also breaks at U+2028, U+2029 and U+0085, which JSON writes
|
|
343
|
+
# into a string as they are, and a message that held one was once cut in half and the file called corrupt.
|
|
344
|
+
lines = data.split(b"\n")
|
|
345
|
+
trailing = lines.pop() # what follows the last newline: usually empty
|
|
346
|
+
header = known.session.header if known is not None else None
|
|
347
|
+
messages = list(known.session.messages) if known is not None else []
|
|
348
|
+
compactions = list(known.session.compactions) if known is not None else []
|
|
349
|
+
head_id = known.session.head_id if known is not None else None
|
|
350
|
+
consumed = 0
|
|
277
351
|
for index, line in enumerate(lines):
|
|
352
|
+
consumed += len(line) + 1
|
|
278
353
|
if not line.strip():
|
|
279
354
|
continue
|
|
280
355
|
try:
|
|
281
356
|
parsed = LINES.validate_json(line)
|
|
282
357
|
except ValidationError as error:
|
|
283
|
-
if index == len(lines) - 1:
|
|
284
|
-
|
|
285
|
-
|
|
358
|
+
if index == len(lines) - 1 and not trailing.strip():
|
|
359
|
+
consumed -= len(line) + 1 # a torn last line: leave it for the next read
|
|
360
|
+
break
|
|
361
|
+
raise ValueError(
|
|
362
|
+
f"Corrupt session file {path.name} at line {first_line + index} (byte {base + consumed - len(line) - 1})"
|
|
363
|
+
) from error
|
|
286
364
|
match parsed:
|
|
287
365
|
case SessionLine():
|
|
288
366
|
header = parsed
|
|
@@ -293,8 +371,33 @@ class SessionPersistenceMixin:
|
|
|
293
371
|
compactions.append(parsed)
|
|
294
372
|
case other:
|
|
295
373
|
raise ValueError(f"Unknown session record: {type(other).__name__}")
|
|
374
|
+
if trailing.strip():
|
|
375
|
+
try:
|
|
376
|
+
parsed = LINES.validate_json(trailing)
|
|
377
|
+
except ValidationError:
|
|
378
|
+
pass # half a record: the next read starts at its first byte
|
|
379
|
+
else:
|
|
380
|
+
consumed += len(trailing)
|
|
381
|
+
match parsed:
|
|
382
|
+
case SessionLine():
|
|
383
|
+
header = parsed
|
|
384
|
+
case MessageLine():
|
|
385
|
+
messages.append(parsed)
|
|
386
|
+
head_id = parsed.id
|
|
387
|
+
case CompactionLine():
|
|
388
|
+
compactions.append(parsed)
|
|
389
|
+
case other:
|
|
390
|
+
raise ValueError(f"Unknown session record: {type(other).__name__}")
|
|
391
|
+
elif trailing:
|
|
392
|
+
consumed += len(trailing) # blanks only
|
|
296
393
|
self._check_links(path, messages, compactions)
|
|
297
|
-
|
|
394
|
+
session = Session(header=header, messages=tuple(messages), compactions=tuple(compactions), head_id=head_id)
|
|
395
|
+
end = base + consumed
|
|
396
|
+
# The anchor comes from the bytes just parsed, never from a second look at the file: a writer could have
|
|
397
|
+
# appended in between, and the anchor would then describe bytes this read never took in.
|
|
398
|
+
before = (known.anchor if known is not None else b"") + data[:consumed]
|
|
399
|
+
taken = data[:consumed].count(b"\n") + (1 if consumed and not data[:consumed].endswith(b"\n") else 0)
|
|
400
|
+
return session, _Reading(session, end, before[-_ANCHOR:], (known.lines if known is not None else 0) + taken)
|
|
298
401
|
|
|
299
402
|
@staticmethod
|
|
300
403
|
def _stamp(path: Path) -> tuple[int, int]:
|
|
@@ -348,7 +451,14 @@ class SessionPersistenceMixin:
|
|
|
348
451
|
A cache entry that does not know the line's parent is dropped rather
|
|
349
452
|
than extended: a worker may have published an empty session between the
|
|
350
453
|
append's leading read and this call, and a one-line cache would then
|
|
351
|
-
claim to be the whole history.
|
|
454
|
+
claim to be the whole history. Its reading is dropped with it, so a
|
|
455
|
+
dropped entry means the next read parses the file whole, as it always did.
|
|
456
|
+
|
|
457
|
+
The reading of a kept entry is deliberately *not* advanced to the spliced
|
|
458
|
+
session. It stays where the last read of the file stopped, so the first
|
|
459
|
+
read after another writer appends parses this process's recent lines once
|
|
460
|
+
more, and that is what keeps them from being counted twice: moving the
|
|
461
|
+
reading forward here would add each of them to the session a second time.
|
|
352
462
|
"""
|
|
353
463
|
with self._cache_lock:
|
|
354
464
|
cached = self._sessions.get(session_id)
|
|
@@ -364,7 +474,7 @@ class SessionPersistenceMixin:
|
|
|
364
474
|
and line.parent != session.head_id
|
|
365
475
|
and session.message(line.parent) is None
|
|
366
476
|
):
|
|
367
|
-
self.
|
|
477
|
+
self._forget(session_id)
|
|
368
478
|
return
|
|
369
479
|
# A read on a worker may have parsed the file after this
|
|
370
480
|
# append wrote it but before it reached this cache update.
|
|
@@ -375,7 +485,7 @@ class SessionPersistenceMixin:
|
|
|
375
485
|
session = replace(session, messages=(*session.messages, line), head_id=line.id)
|
|
376
486
|
case CompactionLine():
|
|
377
487
|
if session.message(line.parent) is None:
|
|
378
|
-
self.
|
|
488
|
+
self._forget(session_id)
|
|
379
489
|
return
|
|
380
490
|
if not any(item.id == line.id for item in session.compactions):
|
|
381
491
|
session = replace(session, compactions=(*session.compactions, line))
|
|
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.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/export/trace/template.html
RENAMED
|
File without changes
|
|
File without changes
|
{zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/extensions/capabilities.py
RENAMED
|
File without changes
|
{zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/extensions/compaction.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/src/zettcode/engine/extensions/harness_switch.py
RENAMED
|
File without changes
|
{zettcode_engine-0.4.6 → zettcode_engine-0.5.0}/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
|