Hooks — API
The facade of the domain package goga.hooks — the extension surface of the goga domains for installed tool packages. The facade declares no type of its own: it re-exports the declared action catalog, the run registry with its per-tool inspection view, the emission of an action at a domain checkpoint, the delivery primitives for domains that drive per-tool delivery themselves, and the installed goga_tool_* package enumeration. Importing the package imports no tool package and enumerates nothing.
The signatures below are the CODEMANIFEST contract of the platform cells.
The facade
from goga.hooks import (
HookRegistry, ToolHooks, build_hook_arguments, declared_actions,
emit_hook_event, enumerate_tool_packages, wrap_context,
)
| Name | Origin | Purpose |
|---|---|---|
declared_actions() |
goga.hooks.catalog |
The declared action catalog |
HookRegistry(), ToolHooks |
goga.hooks.registry |
The run registry and its per-tool view |
emit_hook_event(...) |
goga.hooks.dispatch |
The emission of an action at a domain checkpoint |
wrap_context(...), build_hook_arguments(...) |
goga.hooks.dispatch |
The delivery primitives for domains that drive per-tool delivery themselves (staged contributions) |
enumerate_tool_packages() |
goga.hooks.tools |
The installed goga_tool_* package enumeration |
The delivery primitives serve the staged per-tool delivery pattern — a domain commits a tool's contribution only after all its hooks succeed (the onboarding session, the topics amendments, the pipeline workflow amendment, the config amendment, the schema cell amendment, the contract amendment (contract / amend_contract), the codegraph node amendment, and the drift report/entry amendments are the in-tree consumers — the pipeline, config, schema, contract, codegraph, and drift ones being the hard variant: a failing hook raises instead of being discarded; the schema and codegraph validation gates consume the same primitives for their verdict-collecting walks, with no contribution commit).
Per-domain hook facades built on the platform: goga.pipeline.hooks (the pipeline events, the WorkflowAmendment view, and the bridged mid-run emissions with their RunEvent/StageEvent contexts — see Pipelines — Hooks), goga.build.hooks (the build validation gate and the run moments — see Build — Hooks), goga.topics.hooks (the topic lifecycle checkpoints and the two amendments — see Topics — Hooks), goga.config.hooks (the config amendment zone — ConfigHooks, ConfigAmendment, ConfigOverlay, merge_config_amendments, ToolAmendment, AppliedAmendment, PathAmendment; see Configuration — Hooks), goga.schema.hooks (the schema cell-amendment and validation-gate zone — SchemaHooks, CellAmendment, CellFacts, DependencyFacts, SchemaNode, SchemaValidation, Violation, GateVerdict, ToolContribution, merge_cell_contributions; see Schema — Hooks), goga.contract.hooks (the contract amendment zone — ContractHooks, ContractAmendment, CellFacts, TypeFacts, FormFacts, MemberFacts, ToolContribution, merge_type_contributions; see Contract — Hooks), goga.usages.hooks (the usages run-level moments zone — UsagesHooks plus the four moment contexts and the eight fact records; see Usages — Hooks), goga.codegraph.hooks (the codegraph node-amendment and validation-gate zone — CodegraphHooks, NodeFacts, NodeAmendment, GraphValidation, Violation, GateVerdict, ToolContribution, merge_node_contributions; see Codegraph — Hooks), and goga.drift.hooks (the drift run-moments and amendments zone — DriftHooks, DriftFilters, RunOutcome, RunCompletion, ReportEntry, EntryFacts, ReportAmendment, EntryAmendment, ToolContribution, merge_entry_contributions; see Drift — Hooks).
The action catalog
Every action declared by the domains — its address (domain, name) and its error class (soft or hard). A domain checkpoint consults the catalog to validate the address before emitting.
The registry
HookRegistry()
ToolHooks(tool: str, subscriptions: list[Subscription], rejections: list[RejectedRegistration])
ToolContext(tool: str)
HookRegistry is the one-registry-per-run state: one ToolHooks entry per tool with registrations, carrying its subscriptions and its refused registrations (with reasons). ToolContext is the isolated per-tool context delivered as self to the tool's hooks.
The registration envelope lives in the tools leaf cell:
HookRegistrar(tool: str)
Subscription(tool: str, domain: str, action: str, name: str, hook: Callable)
RejectedRegistration(tool: str, domain: str, action: str, name: str, reason: str)
enumerate_tool_packages() -> list[ToolPackage]
ToolPackage(module_name: str)
call_register_hooks(package: ToolPackage, registrar: HookRegistrar) -> bool
HookRegistrar is the hooks object delivered to a package's register_hooks callback — subscribe(domain, action, name, hook) registers one hook; a wrong address, an empty name, or a repeated name on the same address is refused with a recorded reason. enumerate_tool_packages discovers the installed goga_tool_* packages deterministically (alphabetical order of top-level module name); call_register_hooks invokes a package's callback (True — the package declares one).
The emission
emit_hook_event(registry: HookRegistry, domain: str, action: str, context_for: Callable)
wrap_context(target: object) -> object
build_hook_arguments(hook: Callable, context: object, self_context: ToolContext) -> dict[str, object]
emit_hook_event delivers an action to every subscribed hook — assembling the registry on first use. The context mediation: wrap_context makes the delivered object read-only (attribute assignment blocked); build_hook_arguments passes a hook only the values it declares by the offered names (context, self).
Example
from goga.hooks import HookRegistry, declared_actions, emit_hook_event
registry = HookRegistry()
for action in declared_actions():
print(action.domain, action.name, action.error_class)
# a domain checkpoint — the scale assembly of the history domain
emit_hook_event(registry, "statuses", "register_statuses", context_for=make_registry_surface)