Skip to content

Hooks are methods of Plugin subclasses - #25

Merged
nigelgilbert merged 18 commits into
mainfrom
feature/plugins
Nov 24, 2026
Merged

nigelgilbert merged 18 commits into
mainfrom
feature/plugins

Conversation

@nigelgilbert

@nigelgilbert nigelgilbert commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

A hook file now defines one or more Plugin subclasses, and the five hooks are its methods. Each hook has a default that passes its input on, so a plugin overrides only the ones it needs.

from typing import override

from kiku import Plugin


class Shout(Plugin):
    """Paste every dictation in capitals."""

    @override
    def on_cleaned(self, t: str) -> str:
        return t.upper()

Breaking change

Module-level on_* functions are no longer hooks. There is no adapter and no warning: a file that only has them loads and does nothing. Existing hook files need porting to a Plugin subclass.

What changed

  • kiku package: a hook file imports Plugin and write_log from kiku, a small package shipped in the same distribution as kiku_sidecar. kiku_sidecar stays the server's internals.
  • Loading: load_plugins replaces load_hooks. It makes one instance of every Plugin subclass a file defines, in definition order, with files in filename order. Imported classes are skipped, and a class bound to two names is made once.
  • Firing: fire, fire_done, hook_message and report take the flat list of plugins. The Hooks dict type and POINTS are gone, and fire accepts only the three text hook names.
  • Docs and examples: the recipes in docs/hooks.md and the hook files in examples/ are ported, with @override on each hook. Each recipe's plugin class has a one-line docstring, and the hooks in examples/ keep theirs. State moves from global to self.
  • Type checking: pyright now covers examples/.
  • translate_ja_es.py: a model reply that is not the expected JSON leaves the text as it was instead of failing the dictation.

What did not change

  • The five hooks, what each receives, and what its return means.
  • Filename order, and the labels in errors.txt such as on_cleaned in voice.py:3.
  • The hooks/ folder name and location, so the Swift app and install scripts are untouched.

Review notes

  • A class that another plugin in the same file subclasses is also instantiated, as documented. A shared base belongs in an imported module.
  • In translate_ja_es.py, the re.split after the parse still raises when the language the model names is not in the text word for word. That predates this PR.
  • CI still runs only pytest; pyright and ruff run locally.

Testing

From sidecar/: ruff check, ruff format --check and pyright are clean, and pytest passes 111 tests. A built wheel contains both kiku/ and kiku_sidecar/.

@nigelgilbert
nigelgilbert merged commit be19d8f into main Nov 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant