Skip to main content

Thin typed authoring SDK for hook-bridge Hooks: write a Hook once against the generic Contract, test it with no harness present.

Project description

hook-bridge-sdk

The thin typed authoring SDK for hook-bridge Hooks.

Write a Hook once against the generic Contract — the harness-agnostic Context it receives and the Verdict it returns — and test it in-process with no harness present. hook-bridge (the runner, a separate package) adapts each harness's native protocol to and from this Contract.

# /// script
# dependencies = ["hook-bridge-sdk"]
# ///
from hook_bridge import hook, allow, deny, ask, defer, ToolBeforeContext, ToolBeforeVerdict


@hook
def guard(ctx: ToolBeforeContext) -> ToolBeforeVerdict:  # pure logic, no IO
    if ctx.tool.kind != "shell":
        return defer()
    if "rm -rf /" in ctx.tool.command:
        return deny("that would delete everything")
    return allow()


if __name__ == "__main__":  # runnable as a subprocess AND importable in tests
    guard.run()

Harness-free test:

from hook_bridge import tool_before, shell
from guard import guard

def test_denies_rm_rf() -> None:
    assert guard.dispatch(tool_before(shell("rm -rf /"))).is_deny

Runnable examples live in ../../examples/.

v1 surface

  • @hook decorator → Hook[C, V] with .dispatch(ctx) (pure test seam) and .run() (stdin JSON → dispatch → stdout JSON; exit code = health only).
  • run(*hooks) to compose several events in one file (dispatch by ctx.event).
  • Verdict helpers: allow(), deny(reason), ask(reason), defer().
  • Contract types: ToolBeforeContext (.tool discriminated on .kind; shell.command) and ToolBeforeVerdict (is_allow / is_deny / is_ask / is_defer / reason).
  • Boundary schema validation on the Context read and Verdict written (BoundaryError).
  • Testing factories: tool_before, shell.

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

hook_bridge_sdk-0.1.1.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

hook_bridge_sdk-0.1.1-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file hook_bridge_sdk-0.1.1.tar.gz.

File metadata

  • Download URL: hook_bridge_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for hook_bridge_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 062a2783d77b2f03186f6bb02c4172c6a9558e5e0af1f98a158fb8d7921a9d19
MD5 bc24a5da47e35f92548399c6a3b95c10
BLAKE2b-256 c7e3001611f9529f8398333b0c5dcd4f760494bc617bfe08b336780fbbb6e0ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for hook_bridge_sdk-0.1.1.tar.gz:

Publisher: publish-sdk.yml on jamessawle/hook-bridge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hook_bridge_sdk-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for hook_bridge_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ae5d1dfc4efdb2c15a84d2c808b250ca7ff8bfda4361a156235f1ddecf2acfad
MD5 fafa99c704cd6c5f0ab5d8ddbc6706ca
BLAKE2b-256 31e49db55f59c422c607697056c79a3c69e81eaebc5ee291e4b67bf689dac6df

See more details on using hashes here.

Provenance

The following attestation bundles were made for hook_bridge_sdk-0.1.1-py3-none-any.whl:

Publisher: publish-sdk.yml on jamessawle/hook-bridge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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