zettcode-recap 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.
@@ -16,7 +16,7 @@ dist/
16
16
  /result.json
17
17
 
18
18
  # The docs site: dependencies, build output, and VitePress' cache.
19
- node_modules/
19
+ node_modules
20
20
  docs/.vitepress/dist/
21
21
  docs/.vitepress/cache/
22
22
  docs/.vitepress/.temp/
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: zettcode-recap
3
- Version: 0.5.0
3
+ Version: 0.5.2
4
4
  Summary: A ZettCode plugin: /recap sums up where the session is, and does so on its own when you step away
5
5
  Project-URL: Repository, https://github.com/Chang-LeHung/zettcode/tree/main/packages/zettcode-recap
6
6
  Project-URL: Issues, https://github.com/Chang-LeHung/zettcode/issues
@@ -19,7 +19,7 @@ Classifier: Programming Language :: Python :: 3.15
19
19
  Classifier: Topic :: Software Development :: User Interfaces
20
20
  Classifier: Typing :: Typed
21
21
  Requires-Python: >=3.10
22
- Requires-Dist: zettcode-plugin-api<0.6,>=0.5.0
22
+ Requires-Dist: zettcode-plugin-api<0.6,>=0.5.2
23
23
  Description-Content-Type: text/markdown
24
24
 
25
25
  # zettcode-recap
@@ -24,7 +24,7 @@ dependencies = [
24
24
  # The plugin API: `PluginContext`, `TuiPlugin`, and the terminal group's focus and turn-end hooks, which the 0.3
25
25
  # line added. The recap also asks with `ask(origin=)`, which 0.3.0-0.3.3 do not take: raise this floor to the release
26
26
  # that ships it, in the same commit that sets that version.
27
- "zettcode-plugin-api>=0.5.0,<0.6",
27
+ "zettcode-plugin-api>=0.5.2,<0.6",
28
28
  ]
29
29
 
30
30
  [project.urls]
@@ -33,11 +33,15 @@ from typing import TYPE_CHECKING
33
33
 
34
34
  from zettcode.plugin_api import (
35
35
  HOST_LINK,
36
+ LLM,
36
37
  CommandContext,
37
38
  CommandHost,
38
39
  CommandResult,
39
40
  HostLink,
41
+ ModelAccess,
42
+ PlainCommandContext,
40
43
  PluginContext,
44
+ TextCommandResult,
41
45
  TuiPlugin,
42
46
  )
43
47
 
@@ -47,7 +51,7 @@ if TYPE_CHECKING: # pragma: no cover - annotations only
47
51
 
48
52
 
49
53
  #: The one place the version is written; ``pyproject.toml`` reads it from here.
50
- __version__ = "0.5.0"
54
+ __version__ = "0.5.2"
51
55
 
52
56
  __all__ = ["RecapPlugin", "__version__"]
53
57
 
@@ -100,6 +104,8 @@ class RecapPlugin(TuiPlugin):
100
104
  def __init__(self) -> None:
101
105
  """Start with nothing counted and no recap on its way."""
102
106
  self._link: HostLink | None = None
107
+ #: The front-end-neutral model service: a process with no screen still has one, bound by its SDK client.
108
+ self._llm: ModelAccess | None = None
103
109
  #: Bumped by every turn start: a wait armed for an older one is for a conversation that has moved on.
104
110
  self._generation = 0
105
111
  self._turns = 0
@@ -121,7 +127,11 @@ class RecapPlugin(TuiPlugin):
121
127
  self.min_messages = int(_number(given, "min_messages", least=1))
122
128
  self.min_since_recap = int(_number(given, "min_since_recap", least=1))
123
129
  self._link = ctx.find(HOST_LINK, HostLink)
130
+ self._llm = ctx.find(LLM, ModelAccess)
124
131
  if ctx.tui is None:
132
+ # A process with no screen still has the model service; `/recap` is one plain command, and the idle wait
133
+ # stays a terminal feature until the engine gives every front end turn hooks.
134
+ ctx.commands.register("/recap", "summarise where this session is", self.plain_recap, when_busy="refuse")
125
135
  return
126
136
  # `/recap` asks the shell's own side question, which takes seconds, so it returns the work to do and the shell
127
137
  # shows what it is doing until it is answered; Ctrl-C and Escape stop it.
@@ -218,16 +228,18 @@ class RecapPlugin(TuiPlugin):
218
228
  self._schedule()
219
229
 
220
230
  async def _ask(self) -> str:
221
- """Ask the model for the summary, as the shell's own side question.
231
+ """Ask the model for the summary through the front end's model service.
222
232
 
223
233
  ``origin="recap"``: the question is the plugin's, not the reader's, so nothing of the exchange is drawn — the
224
234
  projector drops it live — and nothing of it comes back when the session is resumed. The one line the reader
225
235
  sees is the quote :meth:`_show` draws.
226
236
 
227
237
  Raises:
228
- RuntimeError: The shell is not built yet.
238
+ RuntimeError: The model service is not ready yet.
229
239
  Exception: Whatever the ask raised — a run already going, the session locked, the provider failing.
230
240
  """
241
+ if self._llm is not None:
242
+ return await self._llm.ask(PROMPT, cache="read", timeout=TIMEOUT_SECONDS, origin="recap")
231
243
  host = self._host()
232
244
  if host is None:
233
245
  raise RuntimeError("The shell is not ready yet")
@@ -245,7 +257,7 @@ class RecapPlugin(TuiPlugin):
245
257
  Exception: What the session's ``ask`` raised — refused because a run is going, the session locked by
246
258
  another process, the provider failing — for a caller with a reader to tell.
247
259
  """
248
- if self._host() is None:
260
+ if self._llm is None and self._host() is None:
249
261
  return ""
250
262
  asking = asyncio.current_task() if cancellable else None
251
263
  if cancellable:
@@ -282,6 +294,18 @@ class RecapPlugin(TuiPlugin):
282
294
  return CommandResult(notification="Nothing to recap yet")
283
295
  return CommandResult(message=quote(text), notification=f"{PREFIX} ready")
284
296
 
297
+ async def plain_recap(self, context: PlainCommandContext) -> TextCommandResult:
298
+ """``/recap`` for a front end with no screen: one side question, answered as a Markdown document."""
299
+ try:
300
+ text = await self._recap(cancellable=False)
301
+ except asyncio.CancelledError:
302
+ raise
303
+ except Exception as error:
304
+ raise ValueError(f"Could not write a recap: {error}") from error
305
+ if not text:
306
+ return TextCommandResult(notification="Nothing to recap yet")
307
+ return TextCommandResult(markdown=quote(text), notification=f"{PREFIX} ready")
308
+
285
309
  # -- helpers -----------------------------------------------------------------------------------
286
310
  def _show(self, text: str) -> None:
287
311
  """Say it in the conversation as a message — the row a command's answer uses — and ask for the frame."""
@@ -352,14 +352,43 @@ def test_a_setting_that_could_never_be_meant_is_refused_when_the_plugin_activate
352
352
 
353
353
 
354
354
  def test_the_plugin_also_activates_without_a_screen(tmp_path):
355
- """Every process loads every plugin; one that only draws into a terminal must leave the others alone."""
355
+ """Every process loads every plugin; a screenless one gets the plain command, not the panel or the hooks."""
356
356
  config = ZettCodeConfig(workspace=tmp_path, models=(ModelConfig(model="m", token="t"),))
357
357
  from zettcode.engine.plugins.context import PluginContext
358
358
 
359
359
  plugin = RecapPlugin()
360
- plugin.activate(PluginContext(config, {}))
360
+ ctx = PluginContext(config, {})
361
+ plugin.activate(ctx)
361
362
 
362
363
  assert plugin._link is None
364
+ (command,) = ctx.commands.commands
365
+ assert command.name == "/recap" and command.when_busy == "refuse"
366
+
367
+
368
+ async def test_a_screenless_recap_asks_through_the_model_service(tmp_path):
369
+ """No shell is needed: the service the SDK binds is the side question, and the answer comes back as a document."""
370
+ from zettcode.engine.plugins.commands import PlainCommandContext, TextCommandResult
371
+ from zettcode.engine.plugins.context import PluginContext
372
+ from zettcode.engine.plugins.llm import ModelAccess
373
+ from zettcode.engine.plugins.services import LLM
374
+
375
+ async def ask(question: str, **options: object) -> str:
376
+ assert question == PROMPT and options["origin"] == "recap"
377
+ return "Fixing the parser; next, run the tests."
378
+
379
+ access = ModelAccess(())
380
+ access.bind(ask)
381
+ config = ZettCodeConfig(workspace=tmp_path, models=(ModelConfig(model="m", token="t"),))
382
+ ctx = PluginContext(config, {LLM: access}, name="recap")
383
+ plugin = RecapPlugin()
384
+ plugin.activate(ctx)
385
+ (command,) = ctx.commands.commands
386
+ result = await command.handler(PlainCommandContext())
387
+
388
+ assert isinstance(result, TextCommandResult)
389
+ assert result.markdown.startswith("> **Recap**")
390
+ assert "Fixing the parser" in result.markdown
391
+ assert result.notification == "Recap ready"
363
392
 
364
393
 
365
394
  def test_the_zettcode_range_admits_the_release_the_plugin_runs_on():
File without changes
File without changes