zettcode-engine 0.4.2__tar.gz → 0.4.3__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.
Files changed (88) hide show
  1. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/PKG-INFO +1 -1
  2. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/core.py +2 -0
  3. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/plugins/__init__.py +5 -0
  4. zettcode_engine-0.4.3/src/zettcode/engine/plugins/cli.py +133 -0
  5. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/plugins/commands.py +0 -7
  6. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/plugins/plugin.py +11 -0
  7. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/plugins/services.py +2 -0
  8. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/version.py +1 -1
  9. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/.gitignore +0 -0
  10. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/pyproject.toml +0 -0
  11. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/_compat.py +0 -0
  12. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/budget.py +0 -0
  13. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/config.py +0 -0
  14. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/config_edit.py +0 -0
  15. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/__init__.py +0 -0
  16. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/agent/__init__.py +0 -0
  17. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/agent/base.py +0 -0
  18. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/agent/context.py +0 -0
  19. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/agent/exports.py +0 -0
  20. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/agent/interaction.py +0 -0
  21. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/agent/sessions.py +0 -0
  22. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/agent/settings.py +0 -0
  23. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/agent/turns.py +0 -0
  24. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/delivery.py +0 -0
  25. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/delivery_runtime.py +0 -0
  26. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/dialogue/__init__.py +0 -0
  27. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/dialogue/ask.py +0 -0
  28. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/dialogue/side.py +0 -0
  29. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/dialogue/title.py +0 -0
  30. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/export/__init__.py +0 -0
  31. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/export/trace/script.js +0 -0
  32. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/export/trace/style.css +0 -0
  33. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/export/trace/template.html +0 -0
  34. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/extensions/__init__.py +0 -0
  35. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/extensions/capabilities.py +0 -0
  36. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/extensions/compaction.py +0 -0
  37. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/extensions/context.py +0 -0
  38. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/extensions/files.py +0 -0
  39. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/extensions/guidance.py +0 -0
  40. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/extensions/harness_switch.py +0 -0
  41. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/extensions/mcp_notice.py +0 -0
  42. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/extensions/relay.py +0 -0
  43. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/extensions/subagents.py +0 -0
  44. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/extensions/usage.py +0 -0
  45. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/harness_paths.py +0 -0
  46. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/inbox.py +0 -0
  47. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/permission/__init__.py +0 -0
  48. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/permission/approval.py +0 -0
  49. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/permission/readonly.py +0 -0
  50. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/permission/sandbox.py +0 -0
  51. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/pipeline.py +0 -0
  52. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/plugins/context.py +0 -0
  53. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/plugins/extension.py +0 -0
  54. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/plugins/graph.py +0 -0
  55. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/plugins/groups.py +0 -0
  56. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/plugins/llm.py +0 -0
  57. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/plugins/loader.py +0 -0
  58. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/plugins/mixins.py +0 -0
  59. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/plugins/settings.py +0 -0
  60. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/plugins/state.py +0 -0
  61. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/plugins/switches.py +0 -0
  62. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/plugins/triggers.py +0 -0
  63. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/py.typed +0 -0
  64. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/server_tools.py +0 -0
  65. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/service_contracts.py +0 -0
  66. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/storage/__init__.py +0 -0
  67. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/storage/layout.py +0 -0
  68. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/storage/ledger.py +0 -0
  69. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/storage/locks.py +0 -0
  70. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/storage/metadata.py +0 -0
  71. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/storage/records.py +0 -0
  72. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/engine/storage/store.py +0 -0
  73. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/error_text.py +0 -0
  74. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/filelock.py +0 -0
  75. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/logging_setup.py +0 -0
  76. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/mention.py +0 -0
  77. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/modes.py +0 -0
  78. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/paths.py +0 -0
  79. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/plugin_tui.py +0 -0
  80. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/processes.py +0 -0
  81. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/prompt.py +0 -0
  82. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/providers.py +0 -0
  83. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/py.typed +0 -0
  84. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/registry.py +0 -0
  85. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/relay.py +0 -0
  86. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/statusline_parts.py +0 -0
  87. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/wire.py +0 -0
  88. {zettcode_engine-0.4.2 → zettcode_engine-0.4.3}/src/zettcode/wording.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: zettcode-engine
3
- Version: 0.4.2
3
+ Version: 0.4.3
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
@@ -49,6 +49,7 @@ from zettcode.engine.plugins.services import (
49
49
  LLM,
50
50
  MODELS,
51
51
  PERSISTENCE,
52
+ PLUGIN_CLI,
52
53
  POLICY,
53
54
  SELECTED_MODEL,
54
55
  SESSION_STORE,
@@ -400,6 +401,7 @@ class ZettCodeEngine:
400
401
  CONTEXT_REPORT: context_reports,
401
402
  CONTEXT_PAGE: context_page,
402
403
  LLM: ModelAccess(config.models),
404
+ PLUGIN_CLI: {},
403
405
  }
404
406
  if selected is not None:
405
407
  # A plugin that sizes something for the model asks for this one; a machine with no model provides
@@ -23,6 +23,7 @@ The pieces live in focused modules — :mod:`~zettcode.engine.plugins.mixins` fo
23
23
 
24
24
  from __future__ import annotations
25
25
 
26
+ from .cli import CliOption, installed_options
26
27
  from .context import PluginContext
27
28
  from .extension import PluginExtension
28
29
  from .llm import ModelAccess
@@ -42,6 +43,7 @@ from .plugin import Plugin, Plugins, PluginSetting
42
43
  from .services import (
43
44
  LLM,
44
45
  PLUGIN_AGENT,
46
+ PLUGIN_CLI,
45
47
  PLUGIN_COMMANDS,
46
48
  PLUGIN_CONFIG,
47
49
  PLUGIN_SETTINGS,
@@ -56,6 +58,9 @@ __all__ = [
56
58
  "PLUGIN_ENTRY_POINT_GROUP",
57
59
  "LLM",
58
60
  "ModelAccess",
61
+ "CliOption",
62
+ "PLUGIN_CLI",
63
+ "installed_options",
59
64
  "PLUGIN_AGENT",
60
65
  "PLUGIN_COMMANDS",
61
66
  "PLUGIN_CONFIG",
@@ -0,0 +1,133 @@
1
+ """Command-line options a plugin contributes, and the values it receives back.
2
+
3
+ A plugin class may override :meth:`~zettcode.engine.plugins.plugin.Plugin.cli_arguments` with a tuple of
4
+ :class:`CliOption`. The ``zettcode`` and ``zettcode daemon spawn`` parsers read those declarations without activating
5
+ the plugin or reading a configuration, so a plugin can add a flag before the runtime exists. The parsed values are
6
+ handed back as the ``PLUGIN_CLI`` service, a mapping from the plugin's entry-point name to its own option values.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import argparse
12
+ import json
13
+ import sys
14
+ from dataclasses import dataclass
15
+ from typing import TYPE_CHECKING
16
+
17
+ if TYPE_CHECKING: # pragma: no cover - annotations only
18
+ from collections.abc import Iterable
19
+ from importlib.metadata import EntryPoint
20
+
21
+
22
+ @dataclass(frozen=True, slots=True)
23
+ class CliOption:
24
+ """One option a plugin adds to a program's command line.
25
+
26
+ Attributes:
27
+ flags: The spellings, such as ``("--recap-depth",)``.
28
+ dest: The key the value is stored under for the plugin.
29
+ help: The line ``--help`` shows.
30
+ default: What the option takes when it is not typed.
31
+ action: The argparse action, ``"store"``, ``"store_true"`` or ``"store_false"``.
32
+ choices: The values argparse accepts, when the option is an enum.
33
+ metavar: The placeholder ``--help`` shows for a value.
34
+ """
35
+
36
+ flags: tuple[str, ...]
37
+ dest: str
38
+ help: str = ""
39
+ default: object = None
40
+ action: str = "store"
41
+ choices: tuple[str, ...] | None = None
42
+ metavar: str | None = None
43
+
44
+ def add(self, parser: argparse.ArgumentParser, *, prefix: str) -> str:
45
+ """Add the option to ``parser`` under ``prefix`` and return the namespace key it uses."""
46
+ key = f"{prefix}{self.dest}"
47
+ parser.add_argument(
48
+ *self.flags,
49
+ dest=key,
50
+ default=self.default,
51
+ help=self.help,
52
+ action=self.action,
53
+ choices=self.choices,
54
+ metavar=self.metavar,
55
+ )
56
+ return key
57
+
58
+
59
+ def installed_options(entry_points: Iterable[EntryPoint] | None = None) -> tuple[tuple[str, CliOption], ...]:
60
+ """Return every option the installed plugin classes declare, in entry-point order.
61
+
62
+ Loading an entry point here loads the plugin's class, not an instance: :meth:`Plugin.cli_arguments` is a class
63
+ method precisely so this can happen before a configuration exists. An entry point that cannot be imported or
64
+ whose declaration is malformed contributes nothing; the plugin loader reports the import failure when it loads
65
+ the plugin for real.
66
+ """
67
+ from .loader import installed_entry_points
68
+ from .plugin import Plugin
69
+
70
+ points = tuple(entry_points) if entry_points is not None else installed_entry_points()
71
+ found: list[tuple[str, CliOption]] = []
72
+ for point in points:
73
+ try:
74
+ target = point.load()
75
+ if not isinstance(target, type) or not issubclass(target, Plugin):
76
+ continue
77
+ declared = target.cli_arguments()
78
+ except (KeyboardInterrupt, SystemExit):
79
+ raise
80
+ except Exception:
81
+ continue
82
+ try:
83
+ options = tuple(declared)
84
+ except (TypeError, ValueError):
85
+ continue
86
+ for option in options:
87
+ if not isinstance(option, CliOption):
88
+ continue
89
+ found.append((point.name, option))
90
+ return tuple(found)
91
+
92
+
93
+ def add_options(
94
+ parser: argparse.ArgumentParser, options: Iterable[tuple[str, CliOption]], *, prefix: str = "plugin__"
95
+ ) -> tuple[tuple[str, CliOption, str], ...]:
96
+ """Add every option with a namespace key that names its plugin, and return the keys.
97
+
98
+ A colliding flag or a default that cannot cross a daemon's JSON handoff drops only that option and names it on
99
+ stderr; one bad plugin declaration must not make every start a traceback.
100
+ """
101
+ added: list[tuple[str, CliOption, str]] = []
102
+ for origin, option in options:
103
+ if (
104
+ not isinstance(option.flags, tuple)
105
+ or not option.flags
106
+ or not all(isinstance(flag, str) and flag.startswith("-") for flag in option.flags)
107
+ ):
108
+ print(f"zettcode: ignored {origin} {option.dest!r}: flags must be option strings", file=sys.stderr)
109
+ continue
110
+ if not isinstance(option.dest, str) or not option.dest.strip():
111
+ print(f"zettcode: ignored {origin} {option.flags[0]}: a destination is required", file=sys.stderr)
112
+ continue
113
+ label = option.flags[0]
114
+ try:
115
+ json.dumps(option.default)
116
+ except (TypeError, ValueError):
117
+ print(f"zettcode: ignored {origin} {label}: its default is not JSON-safe", file=sys.stderr)
118
+ continue
119
+ try:
120
+ key = option.add(parser, prefix=f"{prefix}{origin}__")
121
+ except (argparse.ArgumentError, TypeError, ValueError) as error:
122
+ print(f"zettcode: ignored {origin} {label}: {error}", file=sys.stderr)
123
+ continue
124
+ added.append((origin, option, key))
125
+ return tuple(added)
126
+
127
+
128
+ def values(namespace: argparse.Namespace, added: Iterable[tuple[str, CliOption, str]]) -> dict[str, dict[str, object]]:
129
+ """Return the plugin values parsed into ``namespace``, grouped by plugin."""
130
+ result: dict[str, dict[str, object]] = {}
131
+ for origin, option, key in added:
132
+ result.setdefault(origin, {})[option.dest] = getattr(namespace, key)
133
+ return result
@@ -55,7 +55,6 @@ class PlainCommandContext:
55
55
 
56
56
  Attributes:
57
57
  argument: The words typed after the command's name.
58
- arguments: The same words split on whitespace, for a command that takes several values.
59
58
  level: The shell level the session is running at (``deny``, ``ask``, ``safe`` or ``full``), filled by the
60
59
  front end that runs the command. A command that decides what to ask the model says it in these terms
61
60
  rather than reaching for a shell it may not have.
@@ -66,12 +65,6 @@ class PlainCommandContext:
66
65
  #: The session, for a command that acts on it; ``None`` when the front end running it has no such reach, and the
67
66
  #: command then says so rather than failing.
68
67
  host: PlainCommandHost | None = None
69
- arguments: tuple[str, ...] = ()
70
-
71
- def __post_init__(self) -> None:
72
- """Derive the list form when the caller did not give one."""
73
- if not self.arguments:
74
- object.__setattr__(self, "arguments", tuple(self.argument.split()))
75
68
 
76
69
 
77
70
  @dataclass(frozen=True, slots=True)
@@ -32,6 +32,7 @@ if TYPE_CHECKING: # pragma: no cover - annotations only, so the imports stay la
32
32
  from zettcode.mention import MentionProvider
33
33
  from zettcode.providers import Provider
34
34
 
35
+ from .cli import CliOption
35
36
  from .extension import PluginExtension
36
37
  from .triggers import TriggerRegistration
37
38
 
@@ -121,6 +122,16 @@ class Plugin(PluginAgentMixin, Generic[_C], ABC):
121
122
  """
122
123
  return True
123
124
 
125
+ @classmethod
126
+ def cli_arguments(cls) -> tuple[CliOption, ...]:
127
+ """Return the command-line options this plugin adds to a start or a daemon spawn.
128
+
129
+ The declarations are read from the class before the plugin is activated or a configuration exists, which is
130
+ why this is a class method. The parsed values are handed back as the ``PLUGIN_CLI`` service under this
131
+ plugin's entry-point name. The default adds nothing.
132
+ """
133
+ return ()
134
+
124
135
  def activate(self, container: _C) -> None:
125
136
  """Run once at startup, before any agent client is built.
126
137
 
@@ -32,6 +32,7 @@ MODELS = "models"
32
32
  COMPACTION_COUNTER = "compaction-counter"
33
33
  SELECTED_MODEL = "selected-model"
34
34
  LLM = "llm"
35
+ PLUGIN_CLI = "plugin-cli"
35
36
 
36
37
  #: What the plugin context gives a plugin: the same values its attributes expose, found by name.
37
38
  PLUGIN_AGENT = "plugin-agent"
@@ -85,6 +86,7 @@ __all__ = [
85
86
  "CONTEXT_REPORT",
86
87
  "LLM",
87
88
  "PLUGIN_AGENT",
89
+ "PLUGIN_CLI",
88
90
  "PLUGIN_COMMANDS",
89
91
  "PLUGIN_CONFIG",
90
92
  "PLUGIN_SETTINGS",
@@ -8,4 +8,4 @@ of the dependency graph: everything else may import `zettcode.version`, nothing
8
8
  from __future__ import annotations
9
9
 
10
10
  #: The version of the program and of every distribution built beside it.
11
- __version__ = "0.4.2"
11
+ __version__ = "0.4.3"