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.0.tar.gz (8.5 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.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hook_bridge_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 8.5 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.0.tar.gz
Algorithm Hash digest
SHA256 a0b0888c456b2f0559af79cbfea43387f73fde75cf4804c0bf5965926fbf226d
MD5 a74e7dacb81a317cf9db150a25877384
BLAKE2b-256 5c5db76dbf3b448a822ea80e3af4b437b92f2fb3f16afbc7d4197ebdf6cd4d98

See more details on using hashes here.

Provenance

The following attestation bundles were made for hook_bridge_sdk-0.1.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for hook_bridge_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 894aaf5daba1833c3bc29d334ea3d51a7be0731bfc55358638b3b7deb8590e38
MD5 f9aaeaf72cea359ed9355054d7dd2366
BLAKE2b-256 4a2abceeb09e0d51b68276d237f0405a22a0d38364a456e3d57a40d06e6445e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for hook_bridge_sdk-0.1.0-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