Skip to main content

Plugin interface contracts for Spec-Kit - Pure interfaces with zero dependencies

Project description

spec-kit-contracts

Pure interface contracts for the Spec-Kit plugin system.

Overview

This package contains only interfaces and contracts that define the communication between the Spec-Kit core and plugins. It has zero dependencies to ensure maximum portability.

Plugin developers should depend only on this package to create plugins that are compatible with the Spec-Kit ecosystem.

Installation

pip install spec-kit-contracts

Usage

Creating a Plugin

from spec_kit_contracts import (
    IPlugin,
    IPluginMetadata,
    PluginBase,
    PluginStatus,
    PluginCapability,
)

class MyPlugin(PluginBase):
    """Example plugin implementation."""

    def _create_metadata(self) -> IPluginMetadata:
        return IPluginMetadata(
            name="my-plugin",
            version="1.0.0",
            author="Your Name",
            description="My awesome plugin",
            capabilities=[PluginCapability.COMMAND, PluginCapability.HOOK],
        )

    def handle_message(self, message):
        """Handle incoming messages."""
        if hasattr(message, 'command_name'):
            if message.command_name == "my-plugin:hello":
                return {"message": "Hello from my plugin!"}
        return None

    def get_config_schema(self):
        """Return configuration schema."""
        return {
            "type": "object",
            "properties": {
                "enabled": {"type": "boolean", "default": True},
            },
        }

Using Service Interfaces

from spec_kit_contracts import (
    IServiceRegistry,
    IFileSystemService,
    IConfigService,
)

class MyPlugin(PluginBase):
    def register_services(self, registry: IServiceRegistry) -> None:
        """Register plugin services with the runtime."""
        registry.register_command("my-plugin:hello", self._handle_hello)
        registry.register_hook("post_save", self._on_file_saved, priority=50)

    def set_services(self, services: dict) -> None:
        """Receive injected services."""
        self.fs: IFileSystemService = services.get("filesystem")
        self.config: IConfigService = services.get("config")

Working with Messages

from spec_kit_contracts import (
    Message,
    Request,
    Response,
    Event,
    Command,
    MessageBuilder,
)

# Create a command message
command = MessageBuilder.command(
    name="design:generate",
    arguments=["my-feature"],
    options={"force": True},
)

# Create an event
event = MessageBuilder.event(
    name="file:saved",
    data={"path": "/path/to/file.py"},
)

# Create a request
request = MessageBuilder.request(
    method="get_config",
    params={"key": "max_lines"},
)

Available Contracts

Plugin Interfaces

Interface Description
IPlugin Core plugin protocol (duck typing)
IPluginMetadata Plugin identity and capabilities
PluginBase Convenience base class with defaults
PluginStatus Lifecycle states (INACTIVE, ACTIVE, etc.)
PluginCapability Declared capabilities (COMMAND, HOOK, etc.)

Service Interfaces

Interface Description
IServiceRegistry Register commands, hooks, services
IConfigService Read/write configuration
IFileSystemService File operations with safety
ITemplateService Template rendering
ILoggingService Structured logging
IEventService Pub/sub events
IStateService Persistent state

Message Types

Type Description
Message Base message class
Request Method call expecting response
Response Response to a request
Event Notification/broadcast
Command Direct execution
Query Information request

Exceptions

Exception Description
ContractError Base contract error
PluginContractError Plugin contract violation
MessageContractError Message contract violation
ServiceContractError Service contract violation

Design Principles

  1. Zero Dependencies: This package has no external dependencies
  2. Protocol-Based: Uses Python Protocols for duck typing
  3. Type Safe: Full type annotations for IDE support
  4. Minimal: Only interfaces, no implementations
  5. Stable API: Semantic versioning for breaking changes

Version Compatibility

spec-kit-contracts spec-kit-runtime spec-kit-core
1.x 1.x 1.x

License

MIT License - see LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spec_kit_contracts-1.0.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spec_kit_contracts-1.0.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file spec_kit_contracts-1.0.0.tar.gz.

File metadata

  • Download URL: spec_kit_contracts-1.0.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for spec_kit_contracts-1.0.0.tar.gz
Algorithm Hash digest
SHA256 bdf07b80675b78427e50ccfafdcbe6f025fae903c1f6375851d09ce2331ef720
MD5 eea9d73c9ac6b53a82e09df97e518283
BLAKE2b-256 e35e88ed675cbc44af82e250a604bdcccd3d0a73f4b6928438000a87c9cdba4c

See more details on using hashes here.

File details

Details for the file spec_kit_contracts-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for spec_kit_contracts-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5a34e532cfd2d66d4884d40e6b66dce87ab95f5c0cf05682d9af3dff35e96cd6
MD5 88029def35c9997066b30d7cedcd1d86
BLAKE2b-256 9acb583128f48784f79c8010a39953e2523d6e756017904f168af6e3d43a5893

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page