zettcode-engine 0.5.0__tar.gz → 0.5.2__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.2}/.gitignore +1 -1
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/PKG-INFO +3 -3
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/pyproject.toml +2 -2
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/config.py +14 -6
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/config_edit.py +5 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/agent/context.py +1 -1
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/core.py +63 -19
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/extensions/subagents.py +18 -3
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/extensions/usage.py +20 -3
- zettcode_engine-0.5.2/src/zettcode/engine/harness_library.py +910 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/permission/approval.py +11 -7
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/permission/sandbox.py +12 -1
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/plugins/__init__.py +8 -4
- zettcode_engine-0.5.2/src/zettcode/engine/plugins/children.py +94 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/plugins/cli.py +7 -5
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/plugins/commands.py +31 -5
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/plugins/context.py +9 -4
- zettcode_engine-0.5.2/src/zettcode/engine/plugins/environment.py +5 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/plugins/loader.py +152 -199
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/plugins/plugin.py +61 -18
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/plugins/state.py +5 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/plugins/switches.py +240 -169
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/storage/ledger.py +63 -18
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/version.py +1 -1
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/_compat.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/budget.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/__init__.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/agent/__init__.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/agent/base.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/agent/exports.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/agent/interaction.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/agent/sessions.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/agent/settings.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/agent/turns.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/delivery.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/delivery_runtime.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/dialogue/__init__.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/dialogue/ask.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/dialogue/side.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/dialogue/title.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/export/__init__.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/export/trace/script.js +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/export/trace/style.css +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/export/trace/template.html +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/extensions/__init__.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/extensions/capabilities.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/extensions/compaction.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/extensions/context.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/extensions/files.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/extensions/guidance.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/extensions/harness_switch.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/extensions/mcp_notice.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/extensions/relay.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/harness_paths.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/inbox.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/permission/__init__.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/permission/readonly.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/pipeline.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/plugins/extension.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/plugins/graph.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/plugins/groups.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/plugins/llm.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/plugins/mixins.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/plugins/services.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/plugins/settings.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/plugins/triggers.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/provided.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/py.typed +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/server_tools.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/service_contracts.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/storage/__init__.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/storage/layout.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/storage/locks.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/storage/metadata.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/storage/records.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/engine/storage/store.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/error_text.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/filelock.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/logging_setup.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/mention.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/modes.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/paths.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/plugin_tui.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/processes.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/prompt.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/providers.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/py.typed +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/registry.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/relay.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/statusline_parts.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/src/zettcode/wire.py +0 -0
- {zettcode_engine-0.5.0 → zettcode_engine-0.5.2}/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.2
|
|
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
|
|
@@ -18,7 +18,7 @@ Requires-Python: >=3.10
|
|
|
18
18
|
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
|
-
Requires-Dist: zett-agent<0.
|
|
22
|
-
Requires-Dist: zettcode-tools<0.6,>=0.5.
|
|
21
|
+
Requires-Dist: zett-agent<0.4,>=0.3.1
|
|
22
|
+
Requires-Dist: zettcode-tools<0.6,>=0.5.2
|
|
23
23
|
Provides-Extra: tiktoken
|
|
24
24
|
Requires-Dist: tiktoken<1,>=0.12; extra == 'tiktoken'
|
|
@@ -18,9 +18,9 @@ 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.2,<0.6",
|
|
22
22
|
# The runtime this is a core over. Imported directly: the agent, the message types, the approval mode.
|
|
23
|
-
"zett-agent>=0.
|
|
23
|
+
"zett-agent>=0.3.1,<0.4",
|
|
24
24
|
# The session store's records are pydantic models.
|
|
25
25
|
"pydantic>=2,<3",
|
|
26
26
|
# The stdlib gained both of these in 3.11; older runtimes take the backports.
|
|
@@ -134,7 +134,7 @@ STATUSLINE_KEYS = frozenset(STATUSLINE_NAMES)
|
|
|
134
134
|
SHELL_KEYS = frozenset({"network"})
|
|
135
135
|
|
|
136
136
|
#: Keys the ``[harness]`` table may set.
|
|
137
|
-
HARNESS_KEYS = frozenset({"subagent", "subagent_max_iterations", "subagent_messaging", "todowrite", "jit"})
|
|
137
|
+
HARNESS_KEYS = frozenset({"subagent", "subagent_max_iterations", "subagent_messaging", "todowrite", "jit", "use"})
|
|
138
138
|
|
|
139
139
|
#: Model calls one subagent may make for the task it was given. A child that is exploring or editing
|
|
140
140
|
#: a real codebase makes dozens (a search, a read, an edit, a re-read, for each file), and the framework's
|
|
@@ -190,10 +190,11 @@ KEEP_SHARE = 4
|
|
|
190
190
|
|
|
191
191
|
#: Tokens one reply may spend before the endpoint cuts it off, when the config does not say otherwise. The providers'
|
|
192
192
|
#: own defaults are much smaller — 4,096 on most chat endpoints, 16,384 on Anthropic — and a long answer hit that
|
|
193
|
-
#: limit, ended early, and cost the reader a `/continue` for what was one reply.
|
|
194
|
-
#: current frontier model emits and over what a long answer needs,
|
|
195
|
-
#: so on its first request, where the fix is one
|
|
196
|
-
|
|
193
|
+
#: limit, ended early, and cost the reader a `/continue` for what was one reply. Sixty-four thousand is under what
|
|
194
|
+
#: every current frontier model emits and over what a long answer needs, while still leaving a 128,000-token window
|
|
195
|
+
#: room for the request; an entry whose endpoint refuses a budget says so on its first request, where the fix is one
|
|
196
|
+
#: number in the file.
|
|
197
|
+
DEFAULT_MAX_TOKENS = 64_000
|
|
197
198
|
|
|
198
199
|
#: The sampling temperature a model may be given: 0 is the most deterministic. OpenAI-compatible endpoints take up to
|
|
199
200
|
#: 2; Anthropic's Messages API stops at 1, which is checked for an ``anthropic`` entry.
|
|
@@ -490,7 +491,9 @@ class ZettCodeConfig:
|
|
|
490
491
|
``[plugins] disable`` list; the names the older switch file adds are merged in by
|
|
491
492
|
:attr:`off_names`, so a switch can tell the two apart.
|
|
492
493
|
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.
|
|
494
|
+
(``Plugin.default_enabled``); this is the configuration file's ``[plugins] enable`` list. A switch that
|
|
495
|
+
turns a plugin on writes it here as well as taking it out of ``disable``, so one press means the same
|
|
496
|
+
for a plugin that is off until named and one that is on until dropped.
|
|
494
497
|
plugin_settings: The ``[plugins.<name>]`` tables, by plugin name, exactly as written. A plugin declares
|
|
495
498
|
what its own keys mean and what they default to (``ctx.settings``); the configuration only carries the
|
|
496
499
|
reader's values, so a key no plugin knows is harmless and a plugin that ships later needs no change
|
|
@@ -517,6 +520,8 @@ class ZettCodeConfig:
|
|
|
517
520
|
update_file: Where that check leaves what it found; one small JSON file.
|
|
518
521
|
harness_dir: Where the just-in-time harness keeps each session's tools, one folder per session id. Directly
|
|
519
522
|
under ``~/.zettcode`` by default, not inside the session store, so clearing sessions does not take them.
|
|
523
|
+
harness_use: The name of a library harness (``zettcode harness``) that every session works in, in place of its
|
|
524
|
+
own folder; empty by default. ``[harness] use`` sets it, and ``/harness use`` writes it.
|
|
520
525
|
plugins_file: The older switch file. It is still read and merged with ``[plugins] disable``; a switch written
|
|
521
526
|
now removes the name from it, so it cannot go on overriding the configuration.
|
|
522
527
|
plugins_dir: Where single-file plugins live, one ``.py`` each; a file there is loaded at the next start
|
|
@@ -565,6 +570,8 @@ class ZettCodeConfig:
|
|
|
565
570
|
update_enabled: bool = True
|
|
566
571
|
update_file: Path = DEFAULT_UPDATE_FILE
|
|
567
572
|
harness_dir: Path = DEFAULT_HARNESS_DIR
|
|
573
|
+
#: The library harness every session works in (``[harness] use``); empty means each session's own.
|
|
574
|
+
harness_use: str = ""
|
|
568
575
|
#: Plugins the reader switched off from the shell; a JSON file, read at the next start.
|
|
569
576
|
plugins_file: Path = DEFAULT_PLUGINS_FILE
|
|
570
577
|
#: Single-file plugins: one ``.py`` each, loaded at the next start instead of being installed into site-packages.
|
|
@@ -1134,6 +1141,7 @@ def load_config(
|
|
|
1134
1141
|
subagent_messaging=bool(_setting(harness, "subagent_messaging", bool, False)),
|
|
1135
1142
|
todowrite_enabled=bool(_setting(harness, "todowrite", bool, False)),
|
|
1136
1143
|
jit_harness=bool(_setting(harness, "jit", bool, True)),
|
|
1144
|
+
harness_use=str(_setting(harness, "use", str, "")).strip(),
|
|
1137
1145
|
shell_network=bool(_setting(shell, "network", bool, False)),
|
|
1138
1146
|
sessions_enabled=bool(_setting(sessions, "enabled", bool, True)),
|
|
1139
1147
|
update_enabled=bool(_setting(update, "enabled", bool, True)),
|
|
@@ -412,6 +412,11 @@ def set_string_list(text: str, table: str, key: str, values: Sequence[str], *, w
|
|
|
412
412
|
return _set_key(text, table, key, literal, list(values), where=where, command=command)
|
|
413
413
|
|
|
414
414
|
|
|
415
|
+
def set_string(text: str, table: str, key: str, value: str, *, where: Path, command: str) -> str:
|
|
416
|
+
"""Return ``text`` with ``[table] key`` set to a string, touching nothing else, checked like every key edit."""
|
|
417
|
+
return _set_key(text, table, key, toml_string(value), value, where=where, command=command)
|
|
418
|
+
|
|
419
|
+
|
|
415
420
|
def set_boolean(text: str, table: str, key: str, enabled: bool, *, where: Path, command: str) -> str:
|
|
416
421
|
"""Return ``text`` with ``[table] key`` set to a boolean, touching nothing else.
|
|
417
422
|
|
|
@@ -141,7 +141,7 @@ class ContextMixin(AgentBase):
|
|
|
141
141
|
reader may have moved to another session by the time it is wanted.
|
|
142
142
|
"""
|
|
143
143
|
instructions = self.runtime.context.instructions or (
|
|
144
|
-
SystemMessage(content=build_system_prompt(self.runtime.config)),
|
|
144
|
+
SystemMessage(content=build_system_prompt(self.runtime.config, role=self.runtime.system_prompt)),
|
|
145
145
|
)
|
|
146
146
|
checkpoint, tail = session.active()
|
|
147
147
|
stored: list[AnyMessage] = [checkpoint.message[0]] if checkpoint is not None else []
|
|
@@ -120,16 +120,16 @@ WARM_MODULES_WHEN = (
|
|
|
120
120
|
|
|
121
121
|
|
|
122
122
|
def _load_engine_plugins(config: ZettCodeConfig, shared: Mapping[str, object]) -> Plugins:
|
|
123
|
-
"""Load
|
|
123
|
+
"""Load every installed plugin, and honour the switches that turn them off.
|
|
124
124
|
|
|
125
|
-
The engine ships no
|
|
126
|
-
|
|
127
|
-
|
|
125
|
+
The engine ships no plugin of its own: composing the agent (the tools, the store, the permission, the compaction,
|
|
126
|
+
the MCP client) is done by plugins that distributions publish, found through their entry points like any other.
|
|
127
|
+
A front end that has a screen, or that requires some of them by name, passes its own loader here.
|
|
128
128
|
"""
|
|
129
|
-
return load_plugins(config,
|
|
129
|
+
return load_plugins(config, shared=shared)
|
|
130
130
|
|
|
131
131
|
|
|
132
|
-
def build_system_prompt(config: ZettCodeConfig, *, now: datetime | None = None) -> str:
|
|
132
|
+
def build_system_prompt(config: ZettCodeConfig, *, now: datetime | None = None, role: str | None = None) -> str:
|
|
133
133
|
"""Build request instructions with an explicit workspace boundary.
|
|
134
134
|
|
|
135
135
|
The prompt is the head of every request, so whatever it contains is part of
|
|
@@ -141,9 +141,13 @@ def build_system_prompt(config: ZettCodeConfig, *, now: datetime | None = None)
|
|
|
141
141
|
config: Settings the runtime was built from.
|
|
142
142
|
now: Moment to describe, injectable for tests; defaults to the local
|
|
143
143
|
current time.
|
|
144
|
+
role: The part this run plays, appended after the rules above — a client's
|
|
145
|
+
``system_prompt``, which is what ``daemon spawn --system`` sets. It is
|
|
146
|
+
the process's, not the session's, and blank or ``None`` adds nothing,
|
|
147
|
+
so a program that sets no role sends the head every other one sends.
|
|
144
148
|
"""
|
|
145
149
|
moment = now or datetime.now().astimezone()
|
|
146
|
-
|
|
150
|
+
prompt = f"""You are ZettCode, a focused coding agent working with the user in one local workspace.
|
|
147
151
|
|
|
148
152
|
Inspect relevant files before editing. Make focused changes, preserve unrelated work,
|
|
149
153
|
and run checks proportional to risk. Explain blockers concretely. Do not perform
|
|
@@ -151,8 +155,9 @@ destructive actions unless the user explicitly requests them.
|
|
|
151
155
|
|
|
152
156
|
Changing files: use the file tools, and only them. To edit a file that exists, call
|
|
153
157
|
edit directly: read the lines first, copy old_string exactly, and make one change a
|
|
154
|
-
call — call edit again for the next one.
|
|
155
|
-
|
|
158
|
+
call — call edit again for the next one. A read prefixes each line with its number and a
|
|
159
|
+
tab; the prefix is not in the file, so leave it out of old_string and write_file content.
|
|
160
|
+
Use write_file for a new file or a deliberate whole-file rewrite.
|
|
156
161
|
Never change a file's contents through the shell: no sed, awk, perl -i,
|
|
157
162
|
python -c, a script you write to do the editing, cat or echo with a redirection, a heredoc,
|
|
158
163
|
or tee. There is no delete tool: remove a file with rm in the shell, like any command.
|
|
@@ -162,9 +167,10 @@ edit fails, read the file again and retry it with corrected old_string; do not f
|
|
|
162
167
|
back to a shell command.
|
|
163
168
|
|
|
164
169
|
Reading files: call read tool, and do not shell out to cat, sed, head, tail, nl, awk or
|
|
165
|
-
python -c to look at a file. read takes file_path, offset and limit (
|
|
166
|
-
lines a call
|
|
167
|
-
|
|
170
|
+
python -c to look at a file. read takes file_path, offset and limit (2,000
|
|
171
|
+
lines a call and never more, or 50 KB, whichever comes first; pass a smaller
|
|
172
|
+
limit to read less), so a long file is read in the parts you need rather than
|
|
173
|
+
whole; the reply says where to continue when more remains. Those shell tools are for what read
|
|
168
174
|
cannot do — a binary, a file past its limits, a transformation no line range
|
|
169
175
|
expresses — and only then; say what read could not do. grep and glob are for finding
|
|
170
176
|
what to read — the matching lines — not for printing a file. A bash call starts in
|
|
@@ -181,6 +187,14 @@ Runtime environment:
|
|
|
181
187
|
|
|
182
188
|
Treat the workspace as the current working directory. Prefer relative paths in tool
|
|
183
189
|
calls. Verify mutable facts with tools instead of assuming this startup snapshot is current."""
|
|
190
|
+
role = (role or "").strip()
|
|
191
|
+
if not role:
|
|
192
|
+
return prompt
|
|
193
|
+
return (
|
|
194
|
+
f"{prompt}\n\n# Your role\n"
|
|
195
|
+
"This session was started with a role for it. Follow it along with the instructions above:\n\n"
|
|
196
|
+
f"{role}"
|
|
197
|
+
)
|
|
184
198
|
|
|
185
199
|
|
|
186
200
|
def _build_provider(selected: ModelConfig) -> Adapter:
|
|
@@ -204,7 +218,7 @@ def _build_provider(selected: ModelConfig) -> Adapter:
|
|
|
204
218
|
``max_tokens``.
|
|
205
219
|
|
|
206
220
|
A budget larger than the window is sent as the window: a reply longer than the context that has to hold it is not
|
|
207
|
-
a request any endpoint can serve, and the default of
|
|
221
|
+
a request any endpoint can serve, and the default of 64,000 would otherwise make every small-context entry
|
|
208
222
|
impossible the moment it was read. The entry keeps the number it was given; only the request is bounded.
|
|
209
223
|
"""
|
|
210
224
|
token = selected.token or KEYLESS_TOKEN
|
|
@@ -346,6 +360,10 @@ class ZettCodeEngine:
|
|
|
346
360
|
#: The lock on the session this process has open: only the process that holds it writes to the session.
|
|
347
361
|
#: A runtime that was not given one (a test's) shares nothing, so every claim is granted.
|
|
348
362
|
session_locks: SessionGuard = field(default_factory=NoLocks)
|
|
363
|
+
#: A role this process was started with, appended to the system prompt of every request it makes: what a client's
|
|
364
|
+
#: ``system_prompt`` sets, and what ``daemon spawn --system`` hands a daemon. ``None`` adds nothing. It belongs to
|
|
365
|
+
#: the process and not to the session — a stored conversation resumed elsewhere runs without it.
|
|
366
|
+
system_prompt: str | None = None
|
|
349
367
|
event_dispatcher: AgentEventDispatcher | None = None
|
|
350
368
|
client: AgentClient | None = None
|
|
351
369
|
model: Adapter | None = None
|
|
@@ -385,7 +403,12 @@ class ZettCodeEngine:
|
|
|
385
403
|
|
|
386
404
|
@classmethod
|
|
387
405
|
def preview(
|
|
388
|
-
cls,
|
|
406
|
+
cls,
|
|
407
|
+
config: ZettCodeConfig,
|
|
408
|
+
load: PluginLoader | None = None,
|
|
409
|
+
*,
|
|
410
|
+
shared: Mapping[str, object] | None = None,
|
|
411
|
+
system_prompt: str | None = None,
|
|
389
412
|
) -> ZettCodeEngine:
|
|
390
413
|
"""Build the session side of the runtime, without a provider.
|
|
391
414
|
|
|
@@ -402,6 +425,7 @@ class ZettCodeEngine:
|
|
|
402
425
|
hands over itself is refused. A name another plugin provides fails that plugin unless the plugin
|
|
403
426
|
is written to keep what it is given — the messaging plugin keeps a supplied ``INBOX`` or
|
|
404
427
|
``SESSION_LINK``, which is how a front end hands over its line or replaces the queue.
|
|
428
|
+
system_prompt: A role for this run, appended to the system prompt of every request; ``None`` adds none.
|
|
405
429
|
|
|
406
430
|
Raises:
|
|
407
431
|
ValueError: ``shared`` names a service the runtime hands over itself (``DELIVERY``, ``PERSISTENCE``, ...).
|
|
@@ -428,8 +452,9 @@ class ZettCodeEngine:
|
|
|
428
452
|
os.chdir(config.workspace)
|
|
429
453
|
file_models = config.models
|
|
430
454
|
# 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
|
-
#
|
|
455
|
+
# the invariant S23), and `use_model` sizes this runtime the moment `/config` writes the first entry. The
|
|
456
|
+
# first entry is also the one a run starts on: the file's, or — when it has none — the first model a plugin
|
|
457
|
+
# offers, chosen below once the plugins have been loaded.
|
|
433
458
|
selected = file_models[0] if file_models else None
|
|
434
459
|
effort = config.reasoning_effort if selected is None else selected.accepted_effort(config.reasoning_effort)
|
|
435
460
|
# One policy, read by everything that decides whether a command is asked
|
|
@@ -471,6 +496,15 @@ class ZettCodeEngine:
|
|
|
471
496
|
if shared:
|
|
472
497
|
provided.update(shared)
|
|
473
498
|
plugins = (load or _load_engine_plugins)(config, provided)
|
|
499
|
+
offered = entries(plugins.providers)
|
|
500
|
+
# The file is the reader's own order, so its first entry is the one a run starts on. With no entry there, the
|
|
501
|
+
# first model a plugin offers takes that place: a key in the environment is then enough to type at once,
|
|
502
|
+
# instead of the shell asking for a `/model` choice before it will do anything.
|
|
503
|
+
first_offered: ModelConfig | None = None
|
|
504
|
+
if selected is None and offered:
|
|
505
|
+
first_offered = offered[0]
|
|
506
|
+
selected = first_offered
|
|
507
|
+
effort = selected.accepted_effort(config.reasoning_effort)
|
|
474
508
|
runtime = cls(
|
|
475
509
|
config=config,
|
|
476
510
|
persistence=persistence,
|
|
@@ -484,10 +518,17 @@ class ZettCodeEngine:
|
|
|
484
518
|
active_model=selected,
|
|
485
519
|
compaction_counter=counter,
|
|
486
520
|
plugins=plugins,
|
|
521
|
+
system_prompt=system_prompt,
|
|
487
522
|
_models=models,
|
|
488
523
|
file_models=file_models,
|
|
489
|
-
provided_models=
|
|
524
|
+
provided_models=offered,
|
|
490
525
|
)
|
|
526
|
+
if first_offered is not None:
|
|
527
|
+
# The compaction policy asked for the selected model while it activated and was given none: this is the
|
|
528
|
+
# same sizing a switch does. A runtime whose plugins provide no policy (an engine preview with no agent
|
|
529
|
+
# parts) has nothing to size, and `use_model` would look it up in vain.
|
|
530
|
+
if runtime.plugins.find(COMPACTION, OnDemandCompaction) is not None:
|
|
531
|
+
runtime.use_model(first_offered)
|
|
491
532
|
context_reports.bind(runtime)
|
|
492
533
|
context_page.bind(runtime)
|
|
493
534
|
# The plugins are loaded, so the models they offered are known: a plugin that lists the models sees its own.
|
|
@@ -639,11 +680,14 @@ class ZettCodeEngine:
|
|
|
639
680
|
# store, the shell approval, the compaction ... see `zettcode.sdk.builtins`) in the order
|
|
640
681
|
# they are listed there, then any a third-party plugin brings, and last the one host that drives
|
|
641
682
|
# the plugins' hooks, which places itself at the earliest priority any plugin asked for.
|
|
642
|
-
extensions = [
|
|
683
|
+
extensions = [
|
|
684
|
+
*self.plugins.agent_extensions(AgentBuild(model=model, plugins=self.plugins)),
|
|
685
|
+
*self.plugins.extensions,
|
|
686
|
+
]
|
|
643
687
|
client = await create_agent(
|
|
644
688
|
model,
|
|
645
689
|
config=AgentRunConfig(session_id=self.session_id),
|
|
646
|
-
system_prompt=build_system_prompt(self.config),
|
|
690
|
+
system_prompt=build_system_prompt(self.config, role=self.system_prompt),
|
|
647
691
|
extensions=extensions,
|
|
648
692
|
reasoning_effort=self.config.reasoning_effort,
|
|
649
693
|
parallel_tool_call=self.config.parallel_tool_call,
|
|
@@ -39,6 +39,7 @@ from typing import TYPE_CHECKING, Any
|
|
|
39
39
|
|
|
40
40
|
from zettcode.config import DEFAULT_SUBAGENT_MAX_ITERATIONS
|
|
41
41
|
|
|
42
|
+
from ..plugins.children import ChildSession
|
|
42
43
|
from ..storage import SessionStore
|
|
43
44
|
from .capabilities import ModelCapabilities
|
|
44
45
|
|
|
@@ -96,7 +97,8 @@ CODING_PROMPT = (
|
|
|
96
97
|
"reads your report."
|
|
97
98
|
"\n\nHow to work:\n"
|
|
98
99
|
"- Read before you edit: the file, and enough of its neighbours to match their conventions (naming, "
|
|
99
|
-
"imports, error handling, tests).
|
|
100
|
+
"imports, error handling, tests). A read prefixes each line with its number and a tab; the prefix is not in "
|
|
101
|
+
"the file, so leave it out of old_string and write_file content. Follow the project instructions you were given.\n"
|
|
100
102
|
"- Make the smallest change that does what was asked. Do not refactor, rename, reformat or fix what you "
|
|
101
103
|
"were not asked to touch; mention it instead.\n"
|
|
102
104
|
"- Prefer edit with a short, unique old_string to rewriting a whole file, and read the result "
|
|
@@ -120,7 +122,8 @@ CODING_SHELL_PROMPT = (
|
|
|
120
122
|
"There is no file-deletion tool: remove a file with rm, which follows the same rule."
|
|
121
123
|
"\n\nHow to work:\n"
|
|
122
124
|
"- Read before you edit: the file, and enough of its neighbours to match their conventions (naming, "
|
|
123
|
-
"imports, error handling, tests).
|
|
125
|
+
"imports, error handling, tests). A read prefixes each line with its number and a tab; the prefix is not in "
|
|
126
|
+
"the file, so leave it out of old_string and write_file content. Follow the project instructions you were given.\n"
|
|
124
127
|
"- Make the smallest change that does what was asked. Do not refactor, rename, reformat or fix what you "
|
|
125
128
|
"were not asked to touch; mention it instead.\n"
|
|
126
129
|
"- Prefer edit with a short, unique old_string to rewriting a whole file, and read the result "
|
|
@@ -262,10 +265,12 @@ def _extension_class() -> Callable[..., SubAgentExtension]:
|
|
|
262
265
|
*,
|
|
263
266
|
capabilities: ModelCapabilities,
|
|
264
267
|
shares: Callable[[AgentExtension], bool] | None = None,
|
|
268
|
+
child_extensions: Callable[[ChildSession], tuple[AgentExtension, ...]] | None = None,
|
|
265
269
|
) -> None:
|
|
266
270
|
super().__init__(subagents)
|
|
267
271
|
self._capabilities = capabilities
|
|
268
272
|
self._shares = shares
|
|
273
|
+
self._child_extensions = child_extensions
|
|
269
274
|
|
|
270
275
|
def _levels(self, context: AgentRunContext) -> tuple[ReasoningEffort, ...]:
|
|
271
276
|
"""Return the levels the parent's model takes: every one for a model the runtime has no entry for."""
|
|
@@ -293,12 +298,20 @@ def _extension_class() -> Callable[..., SubAgentExtension]:
|
|
|
293
298
|
config = self._capabilities.config_of(parent)
|
|
294
299
|
if config is not None:
|
|
295
300
|
effort = config.accepted_effort(effort)
|
|
301
|
+
fresh = (
|
|
302
|
+
()
|
|
303
|
+
if self._child_extensions is None
|
|
304
|
+
else self._child_extensions(ChildSession("subagent", definition.name))
|
|
305
|
+
)
|
|
306
|
+
names = {extension.name for extension in fresh}
|
|
307
|
+
defaults = (*definition.extensions, *self._inherited(definition, context))
|
|
308
|
+
extensions = (*(extension for extension in defaults if extension.name not in names), *fresh)
|
|
296
309
|
child = await RelayingAgent.create(
|
|
297
310
|
parent,
|
|
298
311
|
config=AgentRunConfig(session_id=child_session_id, parent_session_id=context.session_id),
|
|
299
312
|
system_prompt=definition.system_prompt,
|
|
300
313
|
tools=definition.tools,
|
|
301
|
-
extensions=
|
|
314
|
+
extensions=extensions,
|
|
302
315
|
reasoning_effort=effort,
|
|
303
316
|
max_iterations=definition.max_iterations,
|
|
304
317
|
)
|
|
@@ -356,6 +369,7 @@ def subagent_extension(
|
|
|
356
369
|
workspace: Path | None = None,
|
|
357
370
|
max_iterations: int = DEFAULT_SUBAGENT_MAX_ITERATIONS,
|
|
358
371
|
shares: Callable[[AgentExtension], bool] | None = None,
|
|
372
|
+
child_extensions: Callable[[ChildSession], tuple[AgentExtension, ...]] | None = None,
|
|
359
373
|
) -> AgentExtension:
|
|
360
374
|
"""Return the ``task`` tool with ZettCode's profiles and their tool boundaries.
|
|
361
375
|
|
|
@@ -388,4 +402,5 @@ def subagent_extension(
|
|
|
388
402
|
),
|
|
389
403
|
capabilities=capabilities,
|
|
390
404
|
shares=shares,
|
|
405
|
+
child_extensions=child_extensions,
|
|
391
406
|
)
|
|
@@ -47,6 +47,8 @@ class UsageSnapshot:
|
|
|
47
47
|
output_tokens: Generated tokens, including reasoning when reported.
|
|
48
48
|
cache_read_tokens: Input tokens the provider served from its cache.
|
|
49
49
|
cache_write_tokens: Input tokens written into the provider cache.
|
|
50
|
+
cache_reported: Whether every counted call reported how much input it read from the cache; a
|
|
51
|
+
call that reported nothing leaves the share unknown, not zero.
|
|
50
52
|
reasoning_tokens: Reasoning subset of ``output_tokens``.
|
|
51
53
|
seconds: Time from the first token of each call to that call's terminal
|
|
52
54
|
response, summed: the window output was generated in, the rate's
|
|
@@ -60,6 +62,7 @@ class UsageSnapshot:
|
|
|
60
62
|
output_tokens: int = 0
|
|
61
63
|
cache_read_tokens: int = 0
|
|
62
64
|
cache_write_tokens: int = 0
|
|
65
|
+
cache_reported: bool = True
|
|
63
66
|
reasoning_tokens: int = 0
|
|
64
67
|
seconds: float = 0.0
|
|
65
68
|
requests: int = 0
|
|
@@ -72,8 +75,15 @@ class UsageSnapshot:
|
|
|
72
75
|
|
|
73
76
|
@property
|
|
74
77
|
def cache_hit_rate(self) -> float | None:
|
|
75
|
-
"""Return the cached share of all input, or None
|
|
76
|
-
|
|
78
|
+
"""Return the cached share of all input, or None when it was not measured.
|
|
79
|
+
|
|
80
|
+
None means there is no ratio to report: no input yet, or a counted call said nothing about what
|
|
81
|
+
it read from the cache. A provider that reports a zero read has still measured a miss, and that
|
|
82
|
+
is 0.0 rather than None.
|
|
83
|
+
"""
|
|
84
|
+
if not self.cache_reported or not self.input_tokens:
|
|
85
|
+
return None
|
|
86
|
+
return self.cache_read_tokens / self.input_tokens
|
|
77
87
|
|
|
78
88
|
@property
|
|
79
89
|
def output_rate(self) -> float | None:
|
|
@@ -107,6 +117,9 @@ class UsageSnapshot:
|
|
|
107
117
|
output_tokens=self.output_tokens + usage.output_tokens,
|
|
108
118
|
cache_read_tokens=self.cache_read_tokens + usage.cache_read_tokens,
|
|
109
119
|
cache_write_tokens=self.cache_write_tokens + usage.cache_write_tokens,
|
|
120
|
+
# One call that said nothing about its cache leaves the running share unknown: the
|
|
121
|
+
# percentage would be over the calls that happened to report.
|
|
122
|
+
cache_reported=self.cache_reported and usage.cache_reported,
|
|
110
123
|
reasoning_tokens=self.reasoning_tokens + usage.reasoning_tokens,
|
|
111
124
|
seconds=self.seconds + max(0.0, seconds),
|
|
112
125
|
requests=self.requests + 1,
|
|
@@ -115,13 +128,14 @@ class UsageSnapshot:
|
|
|
115
128
|
context_tokens=(usage.input_tokens or self.context_tokens) if context_tokens is None else context_tokens,
|
|
116
129
|
)
|
|
117
130
|
|
|
118
|
-
def to_payload(self) -> dict[str, int | float]:
|
|
131
|
+
def to_payload(self) -> dict[str, int | float | bool]:
|
|
119
132
|
"""Return the JSON-serializable form carried by the custom event."""
|
|
120
133
|
return {
|
|
121
134
|
"input_tokens": self.input_tokens,
|
|
122
135
|
"output_tokens": self.output_tokens,
|
|
123
136
|
"cache_read_tokens": self.cache_read_tokens,
|
|
124
137
|
"cache_write_tokens": self.cache_write_tokens,
|
|
138
|
+
"cache_reported": self.cache_reported,
|
|
125
139
|
"reasoning_tokens": self.reasoning_tokens,
|
|
126
140
|
"seconds": self.seconds,
|
|
127
141
|
"requests": self.requests,
|
|
@@ -145,6 +159,9 @@ class UsageSnapshot:
|
|
|
145
159
|
output_tokens=count("output_tokens"),
|
|
146
160
|
cache_read_tokens=count("cache_read_tokens"),
|
|
147
161
|
cache_write_tokens=count("cache_write_tokens"),
|
|
162
|
+
# A payload written before this flag existed said what the provider said, so it keeps
|
|
163
|
+
# the old meaning rather than turning every replayed session's share into unknown.
|
|
164
|
+
cache_reported=payload.get("cache_reported") is not False,
|
|
148
165
|
reasoning_tokens=count("reasoning_tokens"),
|
|
149
166
|
seconds=seconds("seconds"),
|
|
150
167
|
requests=count("requests"),
|